diff options
Diffstat (limited to 'src/main/kotlin/me/kyren223/trident/ui')
3 files changed, 254 insertions, 255 deletions
diff --git a/src/main/kotlin/me/kyren223/trident/ui/SettingsConfigurable.kt b/src/main/kotlin/me/kyren223/trident/ui/SettingsConfigurable.kt index f6979b1..085c6f2 100644 --- a/src/main/kotlin/me/kyren223/trident/ui/SettingsConfigurable.kt +++ b/src/main/kotlin/me/kyren223/trident/ui/SettingsConfigurable.kt @@ -1,67 +1,67 @@ -// Copyright 2000-2022 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -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 javax.swing.JComponent - -class SettingsConfigurable : Configurable { - - private var settings: SettingsData? = null - - override fun getDisplayName(): @ConfigurableName String { - return "Trident Settings" - } - - override fun createComponent(): JComponent { - settings = SettingsData() - return settings!!.panel - } - - override fun isModified(): Boolean { - val settings = SettingsState.instance - if (settings.width != this.settings!!.getWidth()) return true - if (settings.height != this.settings!!.getHeight()) return true - if (settings.fontSize != this.settings!!.getFontSize()) return true - if (settings.enterToSelect != this.settings!!.getEnterToSelect()) return true - if (settings.automaticMapping != this.settings!!.getAutomaticMapping()) return true - if (settings.automaticReplacing != this.settings!!.getAutomaticReplacing()) 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 - settings.width = this.settings!!.getWidth() - settings.height = this.settings!!.getHeight() - settings.fontSize = this.settings!!.getFontSize() - settings.enterToSelect = this.settings!!.getEnterToSelect() - settings.automaticMapping = this.settings!!.getAutomaticMapping() - settings.automaticReplacing = this.settings!!.getAutomaticReplacing() - settings.recursiveMapping = this.settings!!.getRecursiveMapping() - settings.rememberLine = this.settings!!.getRememberLine() - settings.indexCycling = this.settings!!.getIndexCycling() - } - - override fun reset() { - val settings = SettingsState.instance - if (this.settings == null) this.settings = SettingsData() - this.settings!!.setWidth(settings.width) - this.settings!!.setHeight(settings.height) - this.settings!!.setFontSize(settings.fontSize) - this.settings!!.setEnterToSelect(settings.enterToSelect) - this.settings!!.setAutomaticMapping(settings.automaticMapping) - this.settings!!.setAutomaticReplacing(settings.automaticReplacing) - this.settings!!.setRecursiveMapping(settings.recursiveMapping) - this.settings!!.setRememberLine(settings.rememberLine) - this.settings!!.setIndexCycling(settings.indexCycling) - } - - override fun disposeUIResources() { - settings = null - } -} +// Copyright 2000-2022 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+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 javax.swing.JComponent
+
+class SettingsConfigurable : Configurable {
+
+ private var settings: SettingsData? = null
+
+ override fun getDisplayName(): @ConfigurableName String {
+ return "Trident Settings"
+ }
+
+ override fun createComponent(): JComponent {
+ settings = SettingsData()
+ return settings!!.panel
+ }
+
+ override fun isModified(): Boolean {
+ val settings = SettingsState.instance
+ if (settings.width != this.settings!!.getWidth()) return true
+ if (settings.height != this.settings!!.getHeight()) return true
+ if (settings.fontSize != this.settings!!.getFontSize()) return true
+ if (settings.enterToSelect != this.settings!!.getEnterToSelect()) return true
+ if (settings.automaticMapping != this.settings!!.getAutomaticMapping()) return true
+ if (settings.automaticReplacing != this.settings!!.getAutomaticReplacing()) 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
+ settings.width = this.settings!!.getWidth()
+ settings.height = this.settings!!.getHeight()
+ settings.fontSize = this.settings!!.getFontSize()
+ settings.enterToSelect = this.settings!!.getEnterToSelect()
+ settings.automaticMapping = this.settings!!.getAutomaticMapping()
+ settings.automaticReplacing = this.settings!!.getAutomaticReplacing()
+ settings.recursiveMapping = this.settings!!.getRecursiveMapping()
+ settings.rememberLine = this.settings!!.getRememberLine()
+ settings.indexCycling = this.settings!!.getIndexCycling()
+ }
+
+ override fun reset() {
+ val settings = SettingsState.instance
+ if (this.settings == null) this.settings = SettingsData()
+ this.settings!!.setWidth(settings.width)
+ this.settings!!.setHeight(settings.height)
+ this.settings!!.setFontSize(settings.fontSize)
+ this.settings!!.setEnterToSelect(settings.enterToSelect)
+ this.settings!!.setAutomaticMapping(settings.automaticMapping)
+ this.settings!!.setAutomaticReplacing(settings.automaticReplacing)
+ this.settings!!.setRecursiveMapping(settings.recursiveMapping)
+ this.settings!!.setRememberLine(settings.rememberLine)
+ this.settings!!.setIndexCycling(settings.indexCycling)
+ }
+
+ override fun disposeUIResources() {
+ settings = null
+ }
+}
diff --git a/src/main/kotlin/me/kyren223/trident/ui/TridentListMenu.kt b/src/main/kotlin/me/kyren223/trident/ui/TridentListMenu.kt index 75e059a..45eaf76 100644 --- a/src/main/kotlin/me/kyren223/trident/ui/TridentListMenu.kt +++ b/src/main/kotlin/me/kyren223/trident/ui/TridentListMenu.kt @@ -1,102 +1,102 @@ -package me.kyren223.trident.ui - -import com.intellij.openapi.editor.EditorSettings -import com.intellij.openapi.editor.LogicalPosition -import com.intellij.openapi.fileEditor.FileEditorManager -import com.intellij.openapi.project.Project -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.utils.TridentList -import me.kyren223.trident.utils.injectEnterToSelectMapping -import me.kyren223.trident.utils.setEditorMode -import java.awt.event.FocusEvent -import java.awt.event.FocusListener -import javax.swing.JComponent - -class TridentListMenu(private val content: String) : DialogWrapper(true) { - - private lateinit var editor: EditorTextField - - init { - this.title = "Trident List" - val settings = SettingsState.instance - setSize(settings.width, settings.height) - super.init() - } - - override fun createCenterPanel(): JComponent { - editor = EditorTextField(this.content) - editor.setOneLineMode(false) - editor.addSettingsProvider { - it.setFontSize(SettingsState.instance.fontSize) - it.isInsertMode = false - val lineNumber = if (SettingsState.instance.rememberLine) line else 0 - it.caretModel.moveToLogicalPosition(LogicalPosition(lineNumber, 0)) - it.settings.isLineNumbersShown = true - it.settings.lineNumerationType = EditorSettings.LineNumerationType.ABSOLUTE - } - - editor.addFocusListener(object : FocusListener { - override fun focusGained(e: FocusEvent?) { - val editor = editor.editor!!.vim - setEditorMode(editor, Mode.NORMAL()) - } - - override fun focusLost(e: FocusEvent?) { /* Do nothing */ - } - }) - - return editor - } - - - override fun getPreferredFocusedComponent(): JComponent { - return this.editor - } - - fun select() { - doOKAction() - } - - override fun doOKAction() { - save() - super.doOKAction() - } - - override fun doCancelAction() { - save() - super.doCancelAction() - } - - private fun save() { - instance = null - files = editor.text.split("\n") - line = editor.editor?.caretModel?.logicalPosition?.line ?: 0 - } - - override fun createSouthPanel(): JComponent? { - return null - } - - 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") - 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) - } - } -} +package me.kyren223.trident.ui
+
+import com.intellij.openapi.editor.EditorSettings
+import com.intellij.openapi.editor.LogicalPosition
+import com.intellij.openapi.fileEditor.FileEditorManager
+import com.intellij.openapi.project.Project
+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.utils.TridentList
+import me.kyren223.trident.utils.injectEnterToSelectMapping
+import java.awt.event.FocusEvent
+import java.awt.event.FocusListener
+import javax.swing.JComponent
+
+class TridentListMenu(private val content: String) : DialogWrapper(true) {
+
+ private lateinit var editor: EditorTextField
+
+ init {
+ this.title = "Trident List"
+ val settings = SettingsState.instance
+ setSize(settings.width, settings.height)
+ super.init()
+ }
+
+ override fun createCenterPanel(): JComponent {
+ editor = EditorTextField(this.content)
+ editor.setOneLineMode(false)
+ editor.addSettingsProvider {
+ it.setFontSize(SettingsState.instance.fontSize)
+ it.isInsertMode = false
+ val lineNumber = if (SettingsState.instance.rememberLine) line else 0
+ it.caretModel.moveToLogicalPosition(LogicalPosition(lineNumber, 0))
+ it.settings.isLineNumbersShown = true
+ it.settings.lineNumerationType = EditorSettings.LineNumerationType.ABSOLUTE
+ }
+
+ editor.addFocusListener(object : FocusListener {
+ override fun focusGained(e: FocusEvent?) {
+ val editor = editor.editor!!.vim
+ editor.mode = Mode.NORMAL()
+// setEditorMode(editor, Mode.NORMAL())
+ }
+
+ override fun focusLost(e: FocusEvent?) { /* Do nothing */
+ }
+ })
+
+ return editor
+ }
+
+
+ override fun getPreferredFocusedComponent(): JComponent {
+ return this.editor
+ }
+
+ fun select() {
+ doOKAction()
+ }
+
+ override fun doOKAction() {
+ save()
+ super.doOKAction()
+ }
+
+ override fun doCancelAction() {
+ save()
+ super.doCancelAction()
+ }
+
+ private fun save() {
+ instance = null
+ files = editor.text.split("\n")
+ line = editor.editor?.caretModel?.logicalPosition?.line ?: 0
+ }
+
+ override fun createSouthPanel(): JComponent? {
+ return null
+ }
+
+ 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")
+ 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 79f1df8..062c618 100644 --- a/src/main/kotlin/me/kyren223/trident/ui/TridentMappingsMenu.kt +++ b/src/main/kotlin/me/kyren223/trident/ui/TridentMappingsMenu.kt @@ -1,86 +1,85 @@ -package me.kyren223.trident.ui - -import com.intellij.openapi.editor.EditorSettings -import com.intellij.openapi.editor.LogicalPosition -import com.intellij.openapi.project.Project -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.utils.TridentMappings -import me.kyren223.trident.utils.setEditorMode -import java.awt.event.FocusEvent -import java.awt.event.FocusListener -import javax.swing.JComponent - -class TridentMappingsMenu(private val content: String) : DialogWrapper(true) { - private lateinit var editor: EditorTextField - - init { - val settings = SettingsState.instance.state - this.title = "Trident Mappings" - setSize(settings.width, settings.height) - super.init() - } - - override fun createCenterPanel(): JComponent { - editor = EditorTextField(this.content) - editor.setOneLineMode(false) - editor.addSettingsProvider { - it.setFontSize(SettingsState.instance.fontSize) - it.isInsertMode = false - it.caretModel.moveToLogicalPosition(LogicalPosition(0, 0)) - it.settings.isLineNumbersShown = true - it.settings.lineNumerationType = EditorSettings.LineNumerationType.ABSOLUTE - } - - editor.addFocusListener(object : FocusListener { - override fun focusGained(e: FocusEvent?) { - val editor = editor.editor!!.vim - setEditorMode(editor, Mode.NORMAL()) - } - - override fun focusLost(e: FocusEvent?) { /* Do nothing */ } - }) - - return editor - } - - override fun getPreferredFocusedComponent(): JComponent { - return this.editor - } - - override fun doOKAction() { - save() - super.doOKAction() - } - - override fun doCancelAction() { - save() - super.doCancelAction() - } - - private fun save() { - map = editor.text.split("\n") - .map { entry -> entry.split("=") } - .filter { entry -> entry.size == 2 } - .associate { it[0] to it[1] } - } - - override fun createSouthPanel(): JComponent? { - return null - } - - 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 - } - } -} +package me.kyren223.trident.ui
+
+import com.intellij.openapi.editor.EditorSettings
+import com.intellij.openapi.editor.LogicalPosition
+import com.intellij.openapi.project.Project
+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.utils.TridentMappings
+import java.awt.event.FocusEvent
+import java.awt.event.FocusListener
+import javax.swing.JComponent
+
+class TridentMappingsMenu(private val content: String) : DialogWrapper(true) {
+ private lateinit var editor: EditorTextField
+
+ init {
+ val settings = SettingsState.instance.state
+ this.title = "Trident Mappings"
+ setSize(settings.width, settings.height)
+ super.init()
+ }
+
+ override fun createCenterPanel(): JComponent {
+ editor = EditorTextField(this.content)
+ editor.setOneLineMode(false)
+ editor.addSettingsProvider {
+ it.setFontSize(SettingsState.instance.fontSize)
+ it.isInsertMode = false
+ it.caretModel.moveToLogicalPosition(LogicalPosition(0, 0))
+ it.settings.isLineNumbersShown = true
+ it.settings.lineNumerationType = EditorSettings.LineNumerationType.ABSOLUTE
+ }
+
+ editor.addFocusListener(object : FocusListener {
+ override fun focusGained(e: FocusEvent?) {
+ val editor = editor.editor!!.vim
+ editor.mode = Mode.NORMAL()
+ }
+
+ override fun focusLost(e: FocusEvent?) { /* Do nothing */ }
+ })
+
+ return editor
+ }
+
+ override fun getPreferredFocusedComponent(): JComponent {
+ return this.editor
+ }
+
+ override fun doOKAction() {
+ save()
+ super.doOKAction()
+ }
+
+ override fun doCancelAction() {
+ save()
+ super.doCancelAction()
+ }
+
+ private fun save() {
+ map = editor.text.split("\n")
+ .map { entry -> entry.split("=") }
+ .filter { entry -> entry.size == 2 }
+ .associate { it[0] to it[1] }
+ }
+
+ override fun createSouthPanel(): JComponent? {
+ return null
+ }
+
+ 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
+ }
+ }
+}
|
