Skip to content
This repository has been archived by the owner on Sep 17, 2023. It is now read-only.

Commit

Permalink
Add support for disabling realtime warning highlight and add support …
Browse files Browse the repository at this point in the history
…for custom editor fonts (#92)

Signed-off-by: PranavPurwar <[email protected]>
  • Loading branch information
PranavPurwar committed Aug 23, 2023
1 parent 0a1b94c commit 7310e01
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .idea/copyright/cosmicide.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.cosmicide.project.Project
import org.cosmicide.rewrite.common.Prefs
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import java.io.File

Expand All @@ -50,23 +51,25 @@ class KotlinLanguage(

init {
CoroutineScope(Dispatchers.IO).launch {
kotlinEnvironment.addIssueListener {
val severity = when (it.severity) {
CompilerMessageSeverity.ERROR -> DiagnosticRegion.SEVERITY_ERROR
CompilerMessageSeverity.WARNING, CompilerMessageSeverity.STRONG_WARNING -> DiagnosticRegion.SEVERITY_WARNING
else -> return@addIssueListener
}
editor.post {
Log.d(TAG, "Diagnostic: $it")
container.addDiagnostic(
DiagnosticRegion(
it.startOffset,
it.endOffset,
severity,
0,
DiagnosticDetail(it.message)
if (Prefs.kotlinRealtimeErrors) {
kotlinEnvironment.addIssueListener {
val severity = when (it.severity) {
CompilerMessageSeverity.ERROR -> DiagnosticRegion.SEVERITY_ERROR
CompilerMessageSeverity.WARNING, CompilerMessageSeverity.STRONG_WARNING -> DiagnosticRegion.SEVERITY_WARNING
else -> return@addIssueListener
}
editor.post {
Log.d(TAG, "Diagnostic: $it")
container.addDiagnostic(
DiagnosticRegion(
it.startOffset,
it.endOffset,
severity,
0,
DiagnosticDetail(it.message)
)
)
)
}
}
}
val ktFile =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@

package org.cosmicide.rewrite.extension

import android.graphics.Typeface
import androidx.core.content.res.ResourcesCompat
import io.github.rosemoe.sora.widget.CodeEditor
import io.github.rosemoe.sora.widget.component.EditorAutoCompletion
import org.cosmicide.rewrite.R
import org.cosmicide.rewrite.common.Prefs
import org.cosmicide.rewrite.editor.completion.CustomCompletionItemAdapter
import org.cosmicide.rewrite.editor.completion.CustomCompletionLayout

/**
* Sets the font and enables highlighting of the current line for the code editor.
*/
fun CodeEditor.setFont() {
typefaceText = ResourcesCompat.getFont(context, R.font.source_pro_regular)
typefaceText = if (Prefs.editorFont.isNotEmpty()) {
Typeface.createFromFile(Prefs.editorFont)
} else {
ResourcesCompat.getFont(context, R.font.source_pro_regular)
}
isHighlightCurrentLine = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package org.cosmicide.rewrite.fragment.settings
import androidx.core.content.res.ResourcesCompat
import androidx.fragment.app.FragmentActivity
import de.Maxr1998.modernpreferences.PreferenceScreen
import de.Maxr1998.modernpreferences.helpers.editText
import de.Maxr1998.modernpreferences.helpers.seekBar
import de.Maxr1998.modernpreferences.helpers.switch
import org.cosmicide.rewrite.R
Expand Down Expand Up @@ -37,6 +38,7 @@ class EditorSettings(private val activity: FragmentActivity) : SettingsProvider
summary = "Set the tab size for the editor"
max = 14
min = 2
default = 4
showTickMarks = true
}

Expand All @@ -46,6 +48,19 @@ class EditorSettings(private val activity: FragmentActivity) : SettingsProvider
defaultValue = false
}

switch(PreferenceKeys.KOTLIN_REALTIME_ERRORS) {
title = "Enable Kotlin real-time errors"
summary =
"Enables real-time error checking for Kotlin files. This is a slow process and may cause lag. Recommended to turn off on complex projects."
defaultValue = false
}

editText(PreferenceKeys.EDITOR_FONT) {
title = "Editor font"
summary = "Enter the font path for editor"
defaultValue = ""
}

switch(PreferenceKeys.STICKY_SCROLL) {
title = "Sticky scroll"
summary = "Enables sticky scroll in the editor"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ object PreferenceKeys {
const val EDITOR_LINE_NUMBERS_SHOW = "line_numbers_show"
const val EDITOR_DOUBLE_CLICK_CLOSE = "double_click_close"
const val EDITOR_EXP_JAVA_COMPLETION = "experimental_java_completion"
const val KOTLIN_REALTIME_ERRORS = "kotlin_realtime_errors"
const val EDITOR_FONT = "editor_font"
const val BRACKET_PAIR_AUTOCOMPLETE = "bracket_pair_autocomplete"
const val QUICK_DELETE = "quick_delete"
const val STICKY_SCROLL = "sticky_scroll"
Expand Down
7 changes: 7 additions & 0 deletions common/src/main/java/org/cosmicide/rewrite/common/Prefs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ object Prefs {
val gitApiKey: String
get() = prefs.getString("git_api_key", "") ?: ""

val kotlinRealtimeErrors: Boolean
get() = prefs.getBoolean("kotlin_realtime_errors", false)


val editorFont: String
get() = prefs.getString("editor_font", "") ?: ""

val pluginRepository: String
get() = prefs.getString(
"plugin_repository",
Expand Down
23 changes: 13 additions & 10 deletions datadir/src/main/kotlin/changedatadirectory/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@

package changedatadirectory

import android.os.Build
import android.os.Environment
import android.util.Log
import android.widget.Toast
import de.Maxr1998.modernpreferences.PreferenceScreen
import de.Maxr1998.modernpreferences.helpers.editText
import de.Maxr1998.modernpreferences.preferences.EditTextPreference
import org.cosmicide.rewrite.plugin.api.HookManager
import org.cosmicide.rewrite.util.FileUtil
import org.cosmicide.rewrite.util.PermissionUtils
import java.io.File

object Main {
Expand All @@ -27,11 +24,17 @@ object Main {
@JvmStatic
fun main(args: Array<String>) {
val context = HookManager.context.get()!!
val isGranted = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
Environment.isExternalStorageManager()
} else {
PermissionUtils.hasPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
val dataDir = pref.getString("data_directory", null)

if (dataDir == null) {
Log.d("Plugin", "Data directory not set")
return
}

val dir = File(dataDir)

val isGranted = dir.canWrite()

if (isGranted.not()) {
Toast.makeText(
context,
Expand All @@ -40,10 +43,10 @@ object Main {
).show()
return
}
val dataDir = pref.getString("data_directory", null)
if (dataDir != null && File(dataDir).exists()) {

if (dir.exists()) {
Log.d("Plugin", "Data directory already set to $dataDir")
updateDirectory(File(dataDir))
updateDirectory(dir)
}
Log.d("Plugin", "Loaded plugin ChangeDataDirectory")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class CompletionProvider {

@Suppress("DEPRECATION")
fun registerExtensions(extensionArea: ExtensionsAreaImpl) {
if (extensionArea.hasExtensionPoint("com.intellij.virtualFileManagerListener").not()) {
if (!extensionArea.hasExtensionPoint("com.intellij.virtualFileManagerListener")) {
extensionArea.registerExtensionPoint(
"com.intellij.virtualFileManagerListener",
VirtualFileManagerImpl::class.java.name,
Expand Down

0 comments on commit 7310e01

Please sign in to comment.