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

Commit 7310e01

Browse files
committed
Add support for disabling realtime warning highlight and add support for custom editor fonts (#92)
Signed-off-by: PranavPurwar <[email protected]>
1 parent 0a1b94c commit 7310e01

File tree

9 files changed

+68
-31
lines changed

9 files changed

+68
-31
lines changed

.idea/copyright/cosmicide.xml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/deploymentTargetDropDown.xml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/kotlin/org/cosmicide/rewrite/editor/language/KotlinLanguage.kt

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import kotlinx.coroutines.CoroutineScope
2525
import kotlinx.coroutines.Dispatchers
2626
import kotlinx.coroutines.launch
2727
import org.cosmicide.project.Project
28+
import org.cosmicide.rewrite.common.Prefs
2829
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
2930
import java.io.File
3031

@@ -50,23 +51,25 @@ class KotlinLanguage(
5051

5152
init {
5253
CoroutineScope(Dispatchers.IO).launch {
53-
kotlinEnvironment.addIssueListener {
54-
val severity = when (it.severity) {
55-
CompilerMessageSeverity.ERROR -> DiagnosticRegion.SEVERITY_ERROR
56-
CompilerMessageSeverity.WARNING, CompilerMessageSeverity.STRONG_WARNING -> DiagnosticRegion.SEVERITY_WARNING
57-
else -> return@addIssueListener
58-
}
59-
editor.post {
60-
Log.d(TAG, "Diagnostic: $it")
61-
container.addDiagnostic(
62-
DiagnosticRegion(
63-
it.startOffset,
64-
it.endOffset,
65-
severity,
66-
0,
67-
DiagnosticDetail(it.message)
54+
if (Prefs.kotlinRealtimeErrors) {
55+
kotlinEnvironment.addIssueListener {
56+
val severity = when (it.severity) {
57+
CompilerMessageSeverity.ERROR -> DiagnosticRegion.SEVERITY_ERROR
58+
CompilerMessageSeverity.WARNING, CompilerMessageSeverity.STRONG_WARNING -> DiagnosticRegion.SEVERITY_WARNING
59+
else -> return@addIssueListener
60+
}
61+
editor.post {
62+
Log.d(TAG, "Diagnostic: $it")
63+
container.addDiagnostic(
64+
DiagnosticRegion(
65+
it.startOffset,
66+
it.endOffset,
67+
severity,
68+
0,
69+
DiagnosticDetail(it.message)
70+
)
6871
)
69-
)
72+
}
7073
}
7174
}
7275
val ktFile =

app/src/main/kotlin/org/cosmicide/rewrite/extension/editor.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,24 @@
77

88
package org.cosmicide.rewrite.extension
99

10+
import android.graphics.Typeface
1011
import androidx.core.content.res.ResourcesCompat
1112
import io.github.rosemoe.sora.widget.CodeEditor
1213
import io.github.rosemoe.sora.widget.component.EditorAutoCompletion
1314
import org.cosmicide.rewrite.R
15+
import org.cosmicide.rewrite.common.Prefs
1416
import org.cosmicide.rewrite.editor.completion.CustomCompletionItemAdapter
1517
import org.cosmicide.rewrite.editor.completion.CustomCompletionLayout
1618

1719
/**
1820
* Sets the font and enables highlighting of the current line for the code editor.
1921
*/
2022
fun CodeEditor.setFont() {
21-
typefaceText = ResourcesCompat.getFont(context, R.font.source_pro_regular)
23+
typefaceText = if (Prefs.editorFont.isNotEmpty()) {
24+
Typeface.createFromFile(Prefs.editorFont)
25+
} else {
26+
ResourcesCompat.getFont(context, R.font.source_pro_regular)
27+
}
2228
isHighlightCurrentLine = true
2329
}
2430

app/src/main/kotlin/org/cosmicide/rewrite/fragment/settings/EditorSettings.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package org.cosmicide.rewrite.fragment.settings
1010
import androidx.core.content.res.ResourcesCompat
1111
import androidx.fragment.app.FragmentActivity
1212
import de.Maxr1998.modernpreferences.PreferenceScreen
13+
import de.Maxr1998.modernpreferences.helpers.editText
1314
import de.Maxr1998.modernpreferences.helpers.seekBar
1415
import de.Maxr1998.modernpreferences.helpers.switch
1516
import org.cosmicide.rewrite.R
@@ -37,6 +38,7 @@ class EditorSettings(private val activity: FragmentActivity) : SettingsProvider
3738
summary = "Set the tab size for the editor"
3839
max = 14
3940
min = 2
41+
default = 4
4042
showTickMarks = true
4143
}
4244

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

51+
switch(PreferenceKeys.KOTLIN_REALTIME_ERRORS) {
52+
title = "Enable Kotlin real-time errors"
53+
summary =
54+
"Enables real-time error checking for Kotlin files. This is a slow process and may cause lag. Recommended to turn off on complex projects."
55+
defaultValue = false
56+
}
57+
58+
editText(PreferenceKeys.EDITOR_FONT) {
59+
title = "Editor font"
60+
summary = "Enter the font path for editor"
61+
defaultValue = ""
62+
}
63+
4964
switch(PreferenceKeys.STICKY_SCROLL) {
5065
title = "Sticky scroll"
5166
summary = "Enables sticky scroll in the editor"

app/src/main/kotlin/org/cosmicide/rewrite/util/PreferenceKeys.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ object PreferenceKeys {
3333
const val EDITOR_LINE_NUMBERS_SHOW = "line_numbers_show"
3434
const val EDITOR_DOUBLE_CLICK_CLOSE = "double_click_close"
3535
const val EDITOR_EXP_JAVA_COMPLETION = "experimental_java_completion"
36+
const val KOTLIN_REALTIME_ERRORS = "kotlin_realtime_errors"
37+
const val EDITOR_FONT = "editor_font"
3638
const val BRACKET_PAIR_AUTOCOMPLETE = "bracket_pair_autocomplete"
3739
const val QUICK_DELETE = "quick_delete"
3840
const val STICKY_SCROLL = "sticky_scroll"

common/src/main/java/org/cosmicide/rewrite/common/Prefs.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ object Prefs {
106106
val gitApiKey: String
107107
get() = prefs.getString("git_api_key", "") ?: ""
108108

109+
val kotlinRealtimeErrors: Boolean
110+
get() = prefs.getBoolean("kotlin_realtime_errors", false)
111+
112+
113+
val editorFont: String
114+
get() = prefs.getString("editor_font", "") ?: ""
115+
109116
val pluginRepository: String
110117
get() = prefs.getString(
111118
"plugin_repository",

datadir/src/main/kotlin/changedatadirectory/Main.kt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@
88

99
package changedatadirectory
1010

11-
import android.os.Build
12-
import android.os.Environment
1311
import android.util.Log
1412
import android.widget.Toast
1513
import de.Maxr1998.modernpreferences.PreferenceScreen
1614
import de.Maxr1998.modernpreferences.helpers.editText
1715
import de.Maxr1998.modernpreferences.preferences.EditTextPreference
1816
import org.cosmicide.rewrite.plugin.api.HookManager
1917
import org.cosmicide.rewrite.util.FileUtil
20-
import org.cosmicide.rewrite.util.PermissionUtils
2118
import java.io.File
2219

2320
object Main {
@@ -27,11 +24,17 @@ object Main {
2724
@JvmStatic
2825
fun main(args: Array<String>) {
2926
val context = HookManager.context.get()!!
30-
val isGranted = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
31-
Environment.isExternalStorageManager()
32-
} else {
33-
PermissionUtils.hasPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
27+
val dataDir = pref.getString("data_directory", null)
28+
29+
if (dataDir == null) {
30+
Log.d("Plugin", "Data directory not set")
31+
return
3432
}
33+
34+
val dir = File(dataDir)
35+
36+
val isGranted = dir.canWrite()
37+
3538
if (isGranted.not()) {
3639
Toast.makeText(
3740
context,
@@ -40,10 +43,10 @@ object Main {
4043
).show()
4144
return
4245
}
43-
val dataDir = pref.getString("data_directory", null)
44-
if (dataDir != null && File(dataDir).exists()) {
46+
47+
if (dir.exists()) {
4548
Log.d("Plugin", "Data directory already set to $dataDir")
46-
updateDirectory(File(dataDir))
49+
updateDirectory(dir)
4750
}
4851
Log.d("Plugin", "Loaded plugin ChangeDataDirectory")
4952
}

feature/java-completion/src/main/java/org/cosmicide/completion/java/parser/CompletionProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class CompletionProvider {
141141

142142
@Suppress("DEPRECATION")
143143
fun registerExtensions(extensionArea: ExtensionsAreaImpl) {
144-
if (extensionArea.hasExtensionPoint("com.intellij.virtualFileManagerListener").not()) {
144+
if (!extensionArea.hasExtensionPoint("com.intellij.virtualFileManagerListener")) {
145145
extensionArea.registerExtensionPoint(
146146
"com.intellij.virtualFileManagerListener",
147147
VirtualFileManagerImpl::class.java.name,

0 commit comments

Comments
 (0)