From dfca3d7f4814dca9ef3d71c4e2f501474a97429c Mon Sep 17 00:00:00 2001 From: lauvsong Date: Mon, 1 Jan 2024 23:40:17 +0900 Subject: [PATCH 1/7] chore: modify plugin/platform build version --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 169cfee..5b80ae2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,11 +8,11 @@ pluginVersion = 0.0.1 # Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html pluginSinceBuild = 223 -pluginUntilBuild = 232.* +pluginUntilBuild = # IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension platformType = IC -platformVersion = 2022.3.3 +platformVersion = 2023.3.2 # Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html # Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22 From f7aad0ba46719ebe0b52d32b1b1c757321f4e043 Mon Sep 17 00:00:00 2001 From: lauvsong Date: Mon, 1 Jan 2024 23:41:33 +0900 Subject: [PATCH 2/7] fix: remove unused bundle --- .../lauvsong/languagecursor/MyBundle.kt | 20 ------------------- .../resources/messages/MyBundle.properties | 3 --- 2 files changed, 23 deletions(-) delete mode 100644 src/main/kotlin/com/github/lauvsong/languagecursor/MyBundle.kt delete mode 100644 src/main/resources/messages/MyBundle.properties diff --git a/src/main/kotlin/com/github/lauvsong/languagecursor/MyBundle.kt b/src/main/kotlin/com/github/lauvsong/languagecursor/MyBundle.kt deleted file mode 100644 index ccdeb8a..0000000 --- a/src/main/kotlin/com/github/lauvsong/languagecursor/MyBundle.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.github.lauvsong.languagecursor - -import com.intellij.DynamicBundle -import org.jetbrains.annotations.NonNls -import org.jetbrains.annotations.PropertyKey - -@NonNls -private const val BUNDLE = "messages.MyBundle" - -object MyBundle : DynamicBundle(BUNDLE) { - - @JvmStatic - fun message(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) = - getMessage(key, *params) - - @Suppress("unused") - @JvmStatic - fun messagePointer(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) = - getLazyMessage(key, *params) -} diff --git a/src/main/resources/messages/MyBundle.properties b/src/main/resources/messages/MyBundle.properties deleted file mode 100644 index 2e041d8..0000000 --- a/src/main/resources/messages/MyBundle.properties +++ /dev/null @@ -1,3 +0,0 @@ -projectService=Project service: {0} -randomLabel=The random number is: {0} -shuffle=Shuffle From 0d6afa8be3ada436804ba32d23771f9d93322e02 Mon Sep 17 00:00:00 2001 From: lauvsong Date: Mon, 1 Jan 2024 23:41:50 +0900 Subject: [PATCH 3/7] fix: remove bundle config --- src/main/resources/META-INF/plugin.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 121f163..044215e 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -6,8 +6,6 @@ com.intellij.modules.platform - messages.MyBundle - Date: Mon, 1 Jan 2024 23:42:16 +0900 Subject: [PATCH 4/7] feat: add notification util --- .../lauvsong/languagecursor/utils/NotifyUtil.kt | 15 +++++++++++++++ src/main/resources/META-INF/plugin.xml | 5 +++++ 2 files changed, 20 insertions(+) create mode 100644 src/main/kotlin/com/github/lauvsong/languagecursor/utils/NotifyUtil.kt diff --git a/src/main/kotlin/com/github/lauvsong/languagecursor/utils/NotifyUtil.kt b/src/main/kotlin/com/github/lauvsong/languagecursor/utils/NotifyUtil.kt new file mode 100644 index 0000000..b2273a1 --- /dev/null +++ b/src/main/kotlin/com/github/lauvsong/languagecursor/utils/NotifyUtil.kt @@ -0,0 +1,15 @@ +package com.github.lauvsong.languagecursor.utils + +import com.intellij.notification.NotificationGroupManager +import com.intellij.notification.NotificationType +import com.intellij.openapi.project.Project + +object NotifyUtil { + + fun byBalloonWarning(project: Project, content: String) { + NotificationGroupManager.getInstance() + .getNotificationGroup("balloon") + .createNotification(content, NotificationType.WARNING) + .notify(project) + } +} \ No newline at end of file diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 044215e..60d95d8 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -15,5 +15,10 @@ /> + From fc12ddc056100ed102d1291145724d383ca8b0ae Mon Sep 17 00:00:00 2001 From: lauvsong Date: Mon, 1 Jan 2024 23:58:10 +0900 Subject: [PATCH 5/7] feat: add notify if not supported os --- .../languagecursor/ProjectOpenStartUpActivity.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/kotlin/com/github/lauvsong/languagecursor/ProjectOpenStartUpActivity.kt b/src/main/kotlin/com/github/lauvsong/languagecursor/ProjectOpenStartUpActivity.kt index 9e99e16..c3fab90 100644 --- a/src/main/kotlin/com/github/lauvsong/languagecursor/ProjectOpenStartUpActivity.kt +++ b/src/main/kotlin/com/github/lauvsong/languagecursor/ProjectOpenStartUpActivity.kt @@ -11,6 +11,19 @@ class ProjectOpenStartUpActivity : StartupActivity.DumbAware { val editorFactory = EditorFactory.getInstance() val listener = NotEnglishKeyListener() editorFactory.eventMulticaster.addCaretListener(listener, project) + if (isNotSupportedOs()) { + notifyNotSupportedOs(project) + } + + private fun isNotSupportedOs(): Boolean { + return !(SystemUtils.IS_OS_WINDOWS || SystemUtils.IS_OS_MAC) + } + + private fun notifyNotSupportedOs(project: Project) { + NotifyUtil.byBalloonWarning(project, """ + Language Cursor may not supported on your OS. + Windows and macOS are supported. + """.trimIndent()) } } From 896fbe91b124f9bc19ef5e5181b0a3943500e8e3 Mon Sep 17 00:00:00 2001 From: lauvsong Date: Mon, 1 Jan 2024 23:59:49 +0900 Subject: [PATCH 6/7] feat: NotEnlglishKeyListener -> CursorColorManager (make singleton object) --- ...tEnglishKeyListener.kt => CursorColorManager.kt} | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) rename src/main/kotlin/com/github/lauvsong/languagecursor/{listeners/NotEnglishKeyListener.kt => CursorColorManager.kt} (84%) diff --git a/src/main/kotlin/com/github/lauvsong/languagecursor/listeners/NotEnglishKeyListener.kt b/src/main/kotlin/com/github/lauvsong/languagecursor/CursorColorManager.kt similarity index 84% rename from src/main/kotlin/com/github/lauvsong/languagecursor/listeners/NotEnglishKeyListener.kt rename to src/main/kotlin/com/github/lauvsong/languagecursor/CursorColorManager.kt index df6800c..468ad72 100644 --- a/src/main/kotlin/com/github/lauvsong/languagecursor/listeners/NotEnglishKeyListener.kt +++ b/src/main/kotlin/com/github/lauvsong/languagecursor/CursorColorManager.kt @@ -1,29 +1,22 @@ -package com.github.lauvsong.languagecursor.listeners +package com.github.lauvsong.languagecursor import com.github.lauvsong.languagecursor.settings.AppSettingsState import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.colors.EditorColors import com.intellij.openapi.editor.colors.EditorColorsManager -import com.intellij.openapi.editor.event.CaretEvent -import com.intellij.openapi.editor.event.CaretListener import com.intellij.ui.JBColor import java.awt.Color import java.awt.im.InputContext import java.util.Locale -class NotEnglishKeyListener : CaretListener { +object CursorColorManager { private val originalCursorColor: Color = EditorColorsManager.getInstance() .globalScheme .getColor(EditorColors.CARET_COLOR) ?: JBColor.BLACK - override fun caretPositionChanged(event: CaretEvent) { - val editor = event.editor - updateCursorColor(editor) - } - - private fun updateCursorColor(editor: Editor) { + fun updateCursorColor(editor: Editor) { val settings = AppSettingsState.instance val isEnglishInput = isEnglishInput() val cursorColor = if (!isEnglishInput) settings.cursorColor else editor.colorsScheme.defaultForeground From c9306f3f040595e23e4380d091af440fd933b424 Mon Sep 17 00:00:00 2001 From: lauvsong Date: Tue, 2 Jan 2024 00:00:24 +0900 Subject: [PATCH 7/7] feat: trigger update color logic by all IDE event --- .../ProjectOpenStartUpActivity.kt | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/github/lauvsong/languagecursor/ProjectOpenStartUpActivity.kt b/src/main/kotlin/com/github/lauvsong/languagecursor/ProjectOpenStartUpActivity.kt index c3fab90..affe148 100644 --- a/src/main/kotlin/com/github/lauvsong/languagecursor/ProjectOpenStartUpActivity.kt +++ b/src/main/kotlin/com/github/lauvsong/languagecursor/ProjectOpenStartUpActivity.kt @@ -1,20 +1,49 @@ package com.github.lauvsong.languagecursor -import com.github.lauvsong.languagecursor.listeners.NotEnglishKeyListener -import com.intellij.openapi.editor.EditorFactory +import com.github.lauvsong.languagecursor.utils.NotifyUtil +import com.intellij.ide.IdeEventQueue +import com.intellij.openapi.Disposable +import com.intellij.openapi.fileEditor.FileEditorManager import com.intellij.openapi.project.Project +import com.intellij.openapi.project.ProjectManager +import com.intellij.openapi.project.ProjectManagerListener import com.intellij.openapi.startup.StartupActivity +import org.apache.commons.lang3.SystemUtils class ProjectOpenStartUpActivity : StartupActivity.DumbAware { override fun runActivity(project: Project) { - val editorFactory = EditorFactory.getInstance() - val listener = NotEnglishKeyListener() - editorFactory.eventMulticaster.addCaretListener(listener, project) if (isNotSupportedOs()) { notifyNotSupportedOs(project) } + listenNotEnglishKeyLayout(project) + } + + private fun listenNotEnglishKeyLayout(project: Project) { + // Why trigger listener logic by all type of event: + // In some cases, `KeyEvent` may not trigger for system keys. + // Although monitoring all events may impact performance, this approach is the only way I found + // to detect language changes when `KeyEvent` is not working, + IdeEventQueue.getInstance().addDispatcher({ _ -> + val editor = FileEditorManager.getInstance(project).selectedTextEditor + if (editor != null) { + CursorColorManager.updateCursorColor(editor) + } + false + }, createDisposableIfProjectClosed(project)) + } + + private fun createDisposableIfProjectClosed(project: Project): Disposable { + val connection = project.messageBus.connect() + connection.subscribe(ProjectManager.TOPIC, object : ProjectManagerListener { + override fun projectClosed(project: Project) { + connection.dispose() + } + }) + return connection + } + private fun isNotSupportedOs(): Boolean { return !(SystemUtils.IS_OS_WINDOWS || SystemUtils.IS_OS_MAC) }