Skip to content

Commit

Permalink
feat: add setting component :: english cursor color (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
lauvsong committed Feb 20, 2024
1 parent eb1844e commit c2114da
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.github.lauvsong.langcursor

import com.github.lauvsong.langcursor.core.*
import com.github.lauvsong.langcursor.core.CapsLockCheckStrategy
import com.github.lauvsong.langcursor.core.LanguageCheckStrategy
import com.github.lauvsong.langcursor.core.defaultCapsLockCheckStrategy
import com.github.lauvsong.langcursor.core.defaultLanguageCheckStrategy
import com.github.lauvsong.langcursor.core.windowsLanguageCheckStrategy
import com.github.lauvsong.langcursor.services.CursorColorService
import org.apache.commons.lang3.SystemUtils
import java.util.concurrent.Executors
Expand Down Expand Up @@ -37,7 +41,7 @@ object InputChecker {
} else if (!languageCheckStrategy.isEnglishInput()) {
CursorColorService.toNonEnglishCursorColor()
} else {
CursorColorService.toOriginalCursorColor()
CursorColorService.toEnglishCursorColor()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,9 @@ package com.github.lauvsong.langcursor.services

import com.github.lauvsong.langcursor.settings.AppSettingsState
import com.github.lauvsong.langcursor.utils.CursorColorUtil
import com.intellij.openapi.editor.colors.EditorColors
import com.intellij.openapi.editor.colors.EditorColorsManager
import com.intellij.ui.JBColor
import java.awt.Color

object CursorColorService {

private val originalCursorColor: Color = EditorColorsManager.getInstance()
.globalScheme
.getColor(EditorColors.CARET_COLOR)
?: JBColor.BLACK

fun toNonEnglishCursorColor() {
val settings = AppSettingsState.instance
CursorColorUtil.setGlobalCursorColor(settings.nonEnglishCursorColor)
Expand All @@ -24,7 +15,8 @@ object CursorColorService {
CursorColorUtil.setGlobalCursorColor(settings.capsLockCursorColor)
}

fun toOriginalCursorColor() {
CursorColorUtil.setGlobalCursorColor(originalCursorColor)
fun toEnglishCursorColor() {
val settings = AppSettingsState.instance
CursorColorUtil.setGlobalCursorColor(settings.englishCursorColor)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import javax.swing.JPanel
class AppSettingsComponent {
val mainPanel: JPanel by lazy {
FormBuilder.createFormBuilder()
.addLabeledComponent(JBLabel("Cursor color: "), nonEnglishCursorColor, 1, false)
.addLabeledComponent(JBLabel("CapsLock cursor color: "), capsLockCursorColor, 2, false)
.addLabeledComponent(JBLabel("English Cursor color: "), englishCursorColor, 1, false)
.addLabeledComponent(JBLabel("Non-English Cursor color: "), nonEnglishCursorColor, 2, false)
.addLabeledComponent(JBLabel("CapsLock cursor color: "), capsLockCursorColor, 3, false)
.addComponentFillVertically(JPanel(), 0)
.panel
}

val englishCursorColor: ColorPanel = ColorPanel()

val nonEnglishCursorColor: ColorPanel = ColorPanel()

val capsLockCursorColor: ColorPanel = ColorPanel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@ class AppSettingsConfigurable : Configurable {

override fun isModified(): Boolean {
val settings = AppSettingsState.instance
return settings.nonEnglishCursorColor != settingsComponent.nonEnglishCursorColor
return ((settings.englishCursorColor != settingsComponent.englishCursorColor)
|| (settings.nonEnglishCursorColor != settingsComponent.nonEnglishCursorColor)
|| (settings.capsLockCursorColor != settingsComponent.capsLockCursorColor))
}

override fun apply() {
val settings = AppSettingsState.instance
settings.englishCursorColorAsRgb = settingsComponent.englishCursorColor.selectedColor?.rgb ?: settings.englishCursorColorAsRgb
settings.nonEnglishCursorColorAsRgb = settingsComponent.nonEnglishCursorColor.selectedColor?.rgb ?: settings.nonEnglishCursorColorAsRgb
settings.capsLockCursorColorAsRgb = settingsComponent.capsLockCursorColor.selectedColor?.rgb ?: settings.capsLockCursorColorAsRgb
}

override fun reset() {
val settings = AppSettingsState.instance
settingsComponent.englishCursorColor.selectedColor = settings.englishCursorColor
settingsComponent.nonEnglishCursorColor.selectedColor = settings.nonEnglishCursorColor
settingsComponent.capsLockCursorColor.selectedColor = settings.capsLockCursorColor
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
import com.intellij.openapi.components.service
import com.intellij.openapi.editor.colors.EditorColors
import com.intellij.openapi.editor.colors.EditorColorsManager
import com.intellij.ui.JBColor
import com.intellij.util.xmlb.XmlSerializerUtil
import java.awt.Color
Expand All @@ -13,9 +15,18 @@ import java.awt.Color
storages = [Storage("AppSettingsState.xml")]
)
class AppSettingsState : PersistentStateComponent<AppSettingsState> {
private val originalCursorColor: Color = EditorColorsManager.getInstance()
.globalScheme
.getColor(EditorColors.CARET_COLOR)
?: JBColor.BLACK

var englishCursorColorAsRgb: Int = originalCursorColor.rgb
var nonEnglishCursorColorAsRgb: Int = JBColor.RED.rgb
var capsLockCursorColorAsRgb: Int = JBColor.BLUE.rgb

val englishCursorColor: Color
get() = Color(englishCursorColorAsRgb)

val nonEnglishCursorColor: Color
get() = Color(nonEnglishCursorColorAsRgb)

Expand Down

0 comments on commit c2114da

Please sign in to comment.