Skip to content

Commit

Permalink
fixes #28
Browse files Browse the repository at this point in the history
  • Loading branch information
breandan committed Jul 11, 2017
1 parent ced8526 commit e591841
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 81 deletions.
7 changes: 3 additions & 4 deletions src/main/kotlin/com/johnlindquist/acejump/KeyboardHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -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()
}
}
5 changes: 3 additions & 2 deletions src/main/kotlin/com/johnlindquist/acejump/search/Finder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -78,9 +79,9 @@ object Finder {
}
}

private fun determineJumpLocations(): Collection<JumpInfo> {
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<JumpInfo> {
unseen2grams = LinkedHashSet(allBigrams())

if (!isRegex || sitesToCheck.isEmpty()) {
Expand Down
44 changes: 41 additions & 3 deletions src/main/kotlin/com/johnlindquist/acejump/settings/AceConfig.kt
Original file line number Diff line number Diff line change
@@ -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
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.johnlindquist.acejump.settings.AceSettingsPage">
<grid id="27dc6" binding="rootPanel" layout-manager="GridLayoutManager" row-count="8" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="830" y="200" width="336" height="319"/>
</constraints>
<properties/>
<border type="none" title=""/>
<children>
<component id="586f2" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Characters allowed in Tags (sorted by priority):"/>
</properties>
</component>
<component id="14f08" class="javax.swing.JTextField" binding="tagCharacters">
<constraints>
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text resource-bundle="AceResources" key="tagCharacters"/>
</properties>
</component>
<vspacer id="61505">
<constraints>
<grid row="7" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="adf58" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Jump mode color:"/>
</properties>
</component>
<component id="60e62" class="com.intellij.ui.ColorPanel" binding="jumpModeColorChooser">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="e78f1" class="javax.swing.JLabel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Target mode color:"/>
</properties>
</component>
<component id="24934" class="com.intellij.ui.ColorPanel" binding="targetModeColorChooser">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="b3a37" class="javax.swing.JLabel">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Text highlight color:"/>
</properties>
</component>
<component id="6b47a" class="com.intellij.ui.ColorPanel" binding="textHighlightColorChooser">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="4f1" class="javax.swing.JLabel">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Tag foreground color:"/>
</properties>
</component>
<component id="ac9c0" class="com.intellij.ui.ColorPanel" binding="tagForegroundColorChooser">
<constraints>
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="da110" class="javax.swing.JLabel">
<constraints>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Tag background color:"/>
</properties>
</component>
<component id="4a24c" class="com.intellij.ui.ColorPanel" binding="tagBackgroundColorChooser">
<constraints>
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
</form>
Original file line number Diff line number Diff line change
@@ -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<Char>
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 }
}

This file was deleted.

19 changes: 13 additions & 6 deletions src/main/kotlin/com/johnlindquist/acejump/ui/AceUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Char> = ('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
Expand All @@ -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() {
Expand Down
Loading

0 comments on commit e591841

Please sign in to comment.