summaryrefslogtreecommitdiff
path: root/src/main/kotlin/me/kyren223/trident/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/me/kyren223/trident/ui')
-rw-r--r--src/main/kotlin/me/kyren223/trident/ui/SettingsConfigurable.kt11
-rw-r--r--src/main/kotlin/me/kyren223/trident/ui/TridentListMenu.kt36
-rw-r--r--src/main/kotlin/me/kyren223/trident/ui/TridentMappingsMenu.kt12
3 files changed, 36 insertions, 23 deletions
diff --git a/src/main/kotlin/me/kyren223/trident/ui/SettingsConfigurable.kt b/src/main/kotlin/me/kyren223/trident/ui/SettingsConfigurable.kt
index 6283a29..79c4fdc 100644
--- a/src/main/kotlin/me/kyren223/trident/ui/SettingsConfigurable.kt
+++ b/src/main/kotlin/me/kyren223/trident/ui/SettingsConfigurable.kt
@@ -4,7 +4,7 @@ package me.kyren223.trident.ui
import com.intellij.openapi.options.Configurable
import com.intellij.openapi.util.NlsContexts.ConfigurableName
import me.kyren223.trident.data.SettingsData
-import me.kyren223.trident.data.SettingsState
+import me.kyren223.trident.data.Settings
import javax.swing.JComponent
class SettingsConfigurable : Configurable {
@@ -21,7 +21,7 @@ class SettingsConfigurable : Configurable {
}
override fun isModified(): Boolean {
- val settings = SettingsState.instance
+ val settings = Settings.state
if (settings.width != this.settings!!.getWidth()) return true
if (settings.height != this.settings!!.getHeight()) return true
if (settings.fontSize != this.settings!!.getFontSize()) return true
@@ -29,11 +29,12 @@ class SettingsConfigurable : Configurable {
if (settings.automaticMapping != this.settings!!.getAutomaticMapping()) return true
if (settings.recursiveMapping != this.settings!!.getRecursiveMapping()) return true
if (settings.rememberLine != this.settings!!.getRememberLine()) return true
+ if (settings.indexCycling != this.settings!!.getIndexCycling()) return true
return false
}
override fun apply() {
- val settings = SettingsState.instance
+ val settings = Settings.state
settings.width = this.settings!!.getWidth()
settings.height = this.settings!!.getHeight()
settings.fontSize = this.settings!!.getFontSize()
@@ -41,10 +42,11 @@ class SettingsConfigurable : Configurable {
settings.automaticMapping = this.settings!!.getAutomaticMapping()
settings.recursiveMapping = this.settings!!.getRecursiveMapping()
settings.rememberLine = this.settings!!.getRememberLine()
+ settings.indexCycling = this.settings!!.getIndexCycling()
}
override fun reset() {
- val settings = SettingsState.instance
+ val settings = Settings.state
if (this.settings == null) {
this.settings = SettingsData()
}
@@ -55,6 +57,7 @@ class SettingsConfigurable : Configurable {
this.settings!!.setAutomaticMapping(settings.automaticMapping)
this.settings!!.setRecursiveMapping(settings.recursiveMapping)
this.settings!!.setRememberLine(settings.rememberLine)
+ this.settings!!.setIndexCycling(settings.indexCycling)
}
override fun disposeUIResources() {
diff --git a/src/main/kotlin/me/kyren223/trident/ui/TridentListMenu.kt b/src/main/kotlin/me/kyren223/trident/ui/TridentListMenu.kt
index 4062837..af04b7c 100644
--- a/src/main/kotlin/me/kyren223/trident/ui/TridentListMenu.kt
+++ b/src/main/kotlin/me/kyren223/trident/ui/TridentListMenu.kt
@@ -1,5 +1,3 @@
-@file:Suppress("SameParameterValue")
-
package me.kyren223.trident.ui
import com.intellij.openapi.editor.EditorSettings
@@ -10,8 +8,9 @@ import com.intellij.openapi.ui.DialogWrapper
import com.intellij.ui.EditorTextField
import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.state.mode.Mode
-import me.kyren223.trident.data.SettingsState
+import me.kyren223.trident.data.Settings
import me.kyren223.trident.utils.TridentList
+import me.kyren223.trident.utils.injectEnterToSelectMapping
import me.kyren223.trident.utils.setEditorMode
import java.awt.event.FocusEvent
import java.awt.event.FocusListener
@@ -23,7 +22,7 @@ class TridentListMenu(private val content: String) : DialogWrapper(true) {
init {
this.title = "Trident List"
- val settings = SettingsState.instance
+ val settings = Settings.state
setSize(settings.width, settings.height)
super.init()
}
@@ -32,9 +31,9 @@ class TridentListMenu(private val content: String) : DialogWrapper(true) {
editor = EditorTextField(this.content)
editor.setOneLineMode(false)
editor.addSettingsProvider {
- it.setFontSize(SettingsState.instance.fontSize)
+ it.setFontSize(Settings.state.fontSize)
it.isInsertMode = false
- val lineNumber = if (SettingsState.instance.rememberLine) line else 0
+ val lineNumber = if (Settings.state.rememberLine) line else 0
it.caretModel.moveToLogicalPosition(LogicalPosition(lineNumber, 0))
it.settings.isLineNumbersShown = true
it.settings.lineNumerationType = EditorSettings.LineNumerationType.ABSOLUTE
@@ -46,7 +45,8 @@ class TridentListMenu(private val content: String) : DialogWrapper(true) {
setEditorMode(editor, Mode.NORMAL())
}
- override fun focusLost(e: FocusEvent?) { /* Do nothing */ }
+ override fun focusLost(e: FocusEvent?) { /* Do nothing */
+ }
})
return editor
@@ -58,10 +58,7 @@ class TridentListMenu(private val content: String) : DialogWrapper(true) {
}
fun select() {
- val project = editor.project
doOKAction()
- val file = TridentList.select(project, line) ?: return
- FileEditorManager.getInstance(project).openFile(file, true)
}
override fun doOKAction() {
@@ -75,8 +72,9 @@ class TridentListMenu(private val content: String) : DialogWrapper(true) {
}
private fun save() {
- TridentList.set(editor.project, editor.text.split("\n"))
- line = editor.editor!!.caretModel.logicalPosition.line
+ instance = null
+ files = editor.text.split("\n")
+ line = editor.editor?.caretModel?.logicalPosition?.line ?: 0
}
override fun createSouthPanel(): JComponent? {
@@ -84,11 +82,21 @@ class TridentListMenu(private val content: String) : DialogWrapper(true) {
}
companion object {
+ var instance: TridentListMenu? = null
+ var files: List<String>? = null
var line = 0
fun open(project: Project) {
val content = TridentList.get(project).joinToString("\n")
- val menu = TridentListMenu(content)
- menu.show()
+ instance = TridentListMenu(content)
+ injectEnterToSelectMapping()
+ val selected = instance!!.showAndGet()
+
+ files?.let { TridentList.set(project, it) }
+ files = null
+
+ if (!selected) return
+ val file = TridentList.select(project, line) ?: return
+ FileEditorManager.getInstance(project).openFile(file, true)
}
}
}
diff --git a/src/main/kotlin/me/kyren223/trident/ui/TridentMappingsMenu.kt b/src/main/kotlin/me/kyren223/trident/ui/TridentMappingsMenu.kt
index a84b561..4a6d859 100644
--- a/src/main/kotlin/me/kyren223/trident/ui/TridentMappingsMenu.kt
+++ b/src/main/kotlin/me/kyren223/trident/ui/TridentMappingsMenu.kt
@@ -7,7 +7,7 @@ import com.intellij.openapi.ui.DialogWrapper
import com.intellij.ui.EditorTextField
import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.state.mode.Mode
-import me.kyren223.trident.data.SettingsState
+import me.kyren223.trident.data.Settings
import me.kyren223.trident.utils.TridentMappings
import me.kyren223.trident.utils.setEditorMode
import java.awt.event.FocusEvent
@@ -18,7 +18,7 @@ class TridentMappingsMenu(private val content: String) : DialogWrapper(true) {
private lateinit var editor: EditorTextField
init {
- val settings = SettingsState.instance
+ val settings = Settings.state
this.title = "Trident Mappings"
setSize(settings.width, settings.height)
super.init()
@@ -28,7 +28,7 @@ class TridentMappingsMenu(private val content: String) : DialogWrapper(true) {
editor = EditorTextField(this.content)
editor.setOneLineMode(false)
editor.addSettingsProvider {
- it.setFontSize(SettingsState.instance.fontSize)
+ it.setFontSize(Settings.state.fontSize)
it.isInsertMode = false
it.caretModel.moveToLogicalPosition(LogicalPosition(0, 0))
it.settings.isLineNumbersShown = true
@@ -62,11 +62,10 @@ class TridentMappingsMenu(private val content: String) : DialogWrapper(true) {
}
private fun save() {
- val map = editor.text.split("\n")
+ map = editor.text.split("\n")
.map { entry -> entry.split("=") }
.filter { entry -> entry.size == 2 }
.associate { it[0] to it[1] }
- TridentMappings.set(editor.project, map)
}
override fun createSouthPanel(): JComponent? {
@@ -74,11 +73,14 @@ class TridentMappingsMenu(private val content: String) : DialogWrapper(true) {
}
companion object {
+ var map: Map<String, String>? = null
fun open(project: Project) {
val content = TridentMappings.get(project).entries
.joinToString("\n") { "${it.key}=${it.value}" }
val menu = TridentMappingsMenu(content)
menu.show()
+ map?.let { TridentMappings.set(project, it) }
+ map = null
}
}
}