From e591841ec81d654e9e161af54d512bcb9ef8c748 Mon Sep 17 00:00:00 2001 From: "breandan.considine" Date: Tue, 11 Jul 2017 01:04:05 -0400 Subject: [PATCH] fixes #28 --- .../johnlindquist/acejump/KeyboardHandler.kt | 7 +- .../johnlindquist/acejump/search/Finder.kt | 5 +- .../acejump/settings/AceConfig.kt | 44 +++++++- .../acejump/settings/AceSettings.form | 36 ------ .../acejump/settings/AceSettingsPage.form | 106 ++++++++++++++++++ .../acejump/settings/AceSettingsPage.kt | 43 +++++++ .../acejump/settings/AceSettingsProvider.kt | 22 ---- .../com/johnlindquist/acejump/ui/AceUI.kt | 19 +++- .../com/johnlindquist/acejump/ui/JumpInfo.kt | 13 +-- src/main/resources/META-INF/plugin.xml | 7 ++ 10 files changed, 221 insertions(+), 81 deletions(-) delete mode 100644 src/main/kotlin/com/johnlindquist/acejump/settings/AceSettings.form create mode 100644 src/main/kotlin/com/johnlindquist/acejump/settings/AceSettingsPage.form create mode 100644 src/main/kotlin/com/johnlindquist/acejump/settings/AceSettingsPage.kt delete mode 100644 src/main/kotlin/com/johnlindquist/acejump/settings/AceSettingsProvider.kt diff --git a/src/main/kotlin/com/johnlindquist/acejump/KeyboardHandler.kt b/src/main/kotlin/com/johnlindquist/acejump/KeyboardHandler.kt index fb48e644..233a04e7 100755 --- a/src/main/kotlin/com/johnlindquist/acejump/KeyboardHandler.kt +++ b/src/main/kotlin/com/johnlindquist/acejump/KeyboardHandler.kt @@ -22,11 +22,10 @@ import com.johnlindquist.acejump.search.Pattern.* import com.johnlindquist.acejump.search.Skipper import com.johnlindquist.acejump.ui.AceUI.editor import com.johnlindquist.acejump.ui.AceUI.restoreEditorSettings +import com.johnlindquist.acejump.ui.AceUI.settings import com.johnlindquist.acejump.ui.AceUI.setupCursor import com.johnlindquist.acejump.ui.Canvas import org.jetbrains.concurrency.runAsync -import java.awt.Color.BLUE -import java.awt.Color.RED import java.awt.event.FocusEvent import java.awt.event.FocusListener import java.awt.event.KeyEvent.* @@ -226,9 +225,9 @@ object KeyboardHandler { fun toggleTargetMode(status: Boolean? = null) = editor.colorsScheme.run { if (Finder.toggleTargetMode(status)) - setColor(CARET_COLOR, RED) + setColor(CARET_COLOR, settings.targetModeColor) else - setColor(CARET_COLOR, BLUE) + setColor(CARET_COLOR, settings.jumpModeColor) Canvas.repaint() } } \ No newline at end of file diff --git a/src/main/kotlin/com/johnlindquist/acejump/search/Finder.kt b/src/main/kotlin/com/johnlindquist/acejump/search/Finder.kt index 2ee2fdd3..544f5a45 100755 --- a/src/main/kotlin/com/johnlindquist/acejump/search/Finder.kt +++ b/src/main/kotlin/com/johnlindquist/acejump/search/Finder.kt @@ -9,6 +9,7 @@ import com.johnlindquist.acejump.search.Pattern.Companion.adjacent import com.johnlindquist.acejump.search.Pattern.Companion.nearby import com.johnlindquist.acejump.ui.AceUI.editor import com.johnlindquist.acejump.ui.AceUI.editorText +import com.johnlindquist.acejump.ui.AceUI.settings import com.johnlindquist.acejump.ui.JumpInfo import java.lang.Math.max import java.lang.Math.min @@ -78,9 +79,9 @@ object Finder { } } - private fun determineJumpLocations(): Collection { + fun allBigrams() = with(settings.allowedChars) { flatMap { e -> map { c -> "$e$c" } } } - fun allBigrams() = with('a'..'z') { flatMap { e -> map { c -> "$e$c" } } } + private fun determineJumpLocations(): Collection { unseen2grams = LinkedHashSet(allBigrams()) if (!isRegex || sitesToCheck.isEmpty()) { diff --git a/src/main/kotlin/com/johnlindquist/acejump/settings/AceConfig.kt b/src/main/kotlin/com/johnlindquist/acejump/settings/AceConfig.kt index fe9306b6..1e9acbc0 100644 --- a/src/main/kotlin/com/johnlindquist/acejump/settings/AceConfig.kt +++ b/src/main/kotlin/com/johnlindquist/acejump/settings/AceConfig.kt @@ -1,7 +1,45 @@ package com.johnlindquist.acejump.settings -import javax.swing.* +import com.intellij.openapi.components.State +import com.intellij.openapi.options.Configurable +import com.johnlindquist.acejump.ui.AceUI.defaults +import com.johnlindquist.acejump.ui.AceUI.gui +import com.johnlindquist.acejump.ui.AceUI.settings +import javax.swing.JComponent -class AceConfig { - lateinit var tagCharacters: JTextField +@State(name = "AceConfig") +object AceConfig : Configurable { +// override fun getState() = settings +// override fun loadState(state: UserSettings) {settings = state} +// +// override fun getId() = "preferences.AceConfigurable" + + override fun getDisplayName() = "AceJump Config" + + override fun createComponent(): JComponent { + gui = AceSettingsPage() + reset() + return gui.rootPanel + } + + override fun isModified() = settings != defaults + + override fun apply() { + settings.allowedChars = gui.allowedChars + settings.jumpModeColor = gui.jumpModeColor ?: defaults.jumpModeColor + settings.targetModeColor = gui.targetModeColor ?: defaults.targetModeColor + settings.textHighLightColor = gui.textHighlighterColor ?: defaults.textHighLightColor + settings.tagForegroundColor = gui.tagForegroundColor ?: defaults.tagForegroundColor + settings.tagBackgroundColor = gui.tagBackgroundColor ?: defaults.tagBackgroundColor + } + + override fun reset() { + gui.allowedChars = defaults.allowedChars + gui.allowedChars + gui.jumpModeColor = defaults.jumpModeColor + gui.targetModeColor = defaults.targetModeColor + gui.textHighlighterColor = defaults.textHighLightColor + gui.tagForegroundColor = defaults.tagForegroundColor + gui.tagBackgroundColor = defaults.tagBackgroundColor + } } diff --git a/src/main/kotlin/com/johnlindquist/acejump/settings/AceSettings.form b/src/main/kotlin/com/johnlindquist/acejump/settings/AceSettings.form deleted file mode 100644 index 350fe449..00000000 --- a/src/main/kotlin/com/johnlindquist/acejump/settings/AceSettings.form +++ /dev/null @@ -1,36 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/src/main/kotlin/com/johnlindquist/acejump/settings/AceSettingsPage.form b/src/main/kotlin/com/johnlindquist/acejump/settings/AceSettingsPage.form new file mode 100644 index 00000000..aa354aed --- /dev/null +++ b/src/main/kotlin/com/johnlindquist/acejump/settings/AceSettingsPage.form @@ -0,0 +1,106 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/main/kotlin/com/johnlindquist/acejump/settings/AceSettingsPage.kt b/src/main/kotlin/com/johnlindquist/acejump/settings/AceSettingsPage.kt new file mode 100644 index 00000000..24944097 --- /dev/null +++ b/src/main/kotlin/com/johnlindquist/acejump/settings/AceSettingsPage.kt @@ -0,0 +1,43 @@ +package com.johnlindquist.acejump.settings + +import com.intellij.ui.ColorPanel +import java.awt.Color +import javax.swing.JPanel +import javax.swing.JTextField + +class AceSettingsPage { + lateinit var tagCharacters: JTextField + lateinit var jumpModeColorChooser: ColorPanel + lateinit var targetModeColorChooser: ColorPanel + lateinit var textHighlightColorChooser: ColorPanel + lateinit var tagForegroundColorChooser: ColorPanel + lateinit var tagBackgroundColorChooser: ColorPanel + lateinit var rootPanel: JPanel + + var allowedChars: List + get() = tagCharacters.text.toList().distinct() + set(value) = tagCharacters.setText(value.joinToString("")) + + var jumpModeColor: Color? + get() = jumpModeColorChooser.selectedColor + set(value) { jumpModeColorChooser.selectedColor = value } + + + var targetModeColor: Color? + get() = targetModeColorChooser.selectedColor + set(value) { targetModeColorChooser.selectedColor = value } + + var textHighlighterColor: Color? + get() = textHighlightColorChooser.selectedColor + set(value) { textHighlightColorChooser.selectedColor = value } + + + var tagForegroundColor: Color? + get() = tagForegroundColorChooser.selectedColor + set(value) { tagForegroundColorChooser.selectedColor = value } + + + var tagBackgroundColor: Color? + get() = tagBackgroundColorChooser.selectedColor + set(value) { tagBackgroundColorChooser.selectedColor = value } +} diff --git a/src/main/kotlin/com/johnlindquist/acejump/settings/AceSettingsProvider.kt b/src/main/kotlin/com/johnlindquist/acejump/settings/AceSettingsProvider.kt deleted file mode 100644 index 7434bd92..00000000 --- a/src/main/kotlin/com/johnlindquist/acejump/settings/AceSettingsProvider.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.johnlindquist.acejump.settings - -import com.intellij.openapi.components.PersistentStateComponent -import com.intellij.openapi.components.State -import com.intellij.openapi.components.ServiceManager.getService - -@State(name = "AceConfigProvider") -class AceConfigProvider : PersistentStateComponent { - override fun getState() = state - private var state: State = State() - - data class State(var allowedChars: String = "abc") - - override fun loadState(state: State) { - this.state = state - } - - companion object { - val instance: AceConfigProvider - get() = getService(AceConfigProvider::class.java) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/johnlindquist/acejump/ui/AceUI.kt b/src/main/kotlin/com/johnlindquist/acejump/ui/AceUI.kt index 6f49b94e..aba9b064 100644 --- a/src/main/kotlin/com/johnlindquist/acejump/ui/AceUI.kt +++ b/src/main/kotlin/com/johnlindquist/acejump/ui/AceUI.kt @@ -13,6 +13,8 @@ import com.intellij.openapi.editor.markup.TextAttributes import com.intellij.openapi.project.Project import com.johnlindquist.acejump.KeyboardHandler import com.johnlindquist.acejump.search.getDefaultEditor +import com.johnlindquist.acejump.settings.AceSettingsPage +import java.awt.Color import java.awt.Color.* import java.awt.Font import java.awt.Font.BOLD @@ -57,16 +59,21 @@ object AceUI { get() = editor.colorsScheme.editorFontSize val lineHeight: Int get() = editor.lineHeight - val lineSpacing: Float - get() = scheme.lineSpacing val rectHeight: Int get() = fontHeight + 3 val rectHOffset: Int get() = lineHeight - (editor as EditorImpl).descent - fontHeight - val boxColor = red - val editorHighlightColor = yellow - val acejumpHighlightColor = green + data class UserSettings(var allowedChars: List = ('a'..'z').toList(), + var jumpModeColor: Color = blue, + var targetModeColor: Color = red, + var textHighLightColor: Color = green, + var tagForegroundColor: Color = black, + var tagBackgroundColor: Color = yellow) + + var settings = UserSettings() + var defaults = UserSettings() + var gui = AceSettingsPage() fun Editor.setupCursor() { naturalBlock = settings.isBlockCursor @@ -76,7 +83,7 @@ object AceUI { settings.isBlinkCaret = false naturalColor = colorsScheme.getColor(CARET_COLOR)!! - colorsScheme.setColor(CARET_COLOR, BLUE) + colorsScheme.setColor(CARET_COLOR, AceUI.settings.jumpModeColor) } fun restoreEditorSettings() { diff --git a/src/main/kotlin/com/johnlindquist/acejump/ui/JumpInfo.kt b/src/main/kotlin/com/johnlindquist/acejump/ui/JumpInfo.kt index 93fd03cc..3d7f6da3 100644 --- a/src/main/kotlin/com/johnlindquist/acejump/ui/JumpInfo.kt +++ b/src/main/kotlin/com/johnlindquist/acejump/ui/JumpInfo.kt @@ -6,19 +6,16 @@ import com.johnlindquist.acejump.search.Finder.query import com.johnlindquist.acejump.search.getPointFromIndex import com.johnlindquist.acejump.search.isFirstCharacterOfLine import com.johnlindquist.acejump.search.wordBounds -import com.johnlindquist.acejump.ui.AceUI.acejumpHighlightColor -import com.johnlindquist.acejump.ui.AceUI.boxColor import com.johnlindquist.acejump.ui.AceUI.editor -import com.johnlindquist.acejump.ui.AceUI.editorHighlightColor import com.johnlindquist.acejump.ui.AceUI.editorText import com.johnlindquist.acejump.ui.AceUI.fontHeight import com.johnlindquist.acejump.ui.AceUI.fontWidth import com.johnlindquist.acejump.ui.AceUI.rectHOffset import com.johnlindquist.acejump.ui.AceUI.rectHeight +import com.johnlindquist.acejump.ui.AceUI.settings import com.johnlindquist.acejump.ui.JumpInfo.Alignment.* import java.awt.AlphaComposite.SRC_OVER import java.awt.AlphaComposite.getInstance -import java.awt.Color.BLACK import java.awt.Graphics2D import java.awt.Point import java.awt.RenderingHints.KEY_ANTIALIASING @@ -57,7 +54,7 @@ class JumpInfo(val tag: String, val index: Int) { //the foreground text font = AceUI.font - color = BLACK + color = settings.tagForegroundColor drawString(tag.toUpperCase(), tagPosition.x, tagPosition.y + fontHeight) } @@ -105,7 +102,7 @@ class JumpInfo(val tag: String, val index: Int) { // TODO: Use the built-in find-highlighter fun highlightAlreadyTyped() { g2d.composite = getInstance(SRC_OVER, 0.40.toFloat()) - g2d.color = acejumpHighlightColor + g2d.color = settings.textHighLightColor if (lastQueryChar == tag.first() && lastQueryChar != editorChar) { g2d.fillRoundRect(tagX, point.y, fontWidth, rectHeight, rectHeight - 6, rectHeight - 6) tagX += fontWidth @@ -116,7 +113,7 @@ class JumpInfo(val tag: String, val index: Int) { } fun highlightRemaining() { - g2d.color = editorHighlightColor + g2d.color = settings.tagBackgroundColor val hasSpaceToTheRight = editorText.length <= index + 1 || editorText[index + 1].isWhitespace() @@ -129,7 +126,7 @@ class JumpInfo(val tag: String, val index: Int) { fun surroundTargetWord() { g2d.composite = getInstance(SRC_OVER, 1.toFloat()) val (wordStart, wordEnd) = editorText.wordBounds(index) - g2d.color = boxColor + g2d.color = settings.targetModeColor val xPosition = editor.getPointFromIndex(wordStart).x val width = (wordEnd - wordStart) * fontWidth diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 7316d8a6..69f58be5 100755 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -22,6 +22,13 @@ AceJump + + + + + + +