diff options
| author | Kyren223 <ulmliad223@gmail.com> | 2024-02-23 23:11:09 +0200 |
|---|---|---|
| committer | Kyren223 <ulmliad223@gmail.com> | 2024-02-23 23:11:09 +0200 |
| commit | 5da72c7ec98edfab7fbebc335e1a9fba116988a5 (patch) | |
| tree | b44ff2e0a10c1f5c58c7da50c91efc1b7dd2be9d /src/main/kotlin/me/kyren223/trident/PathMappingsMenu.kt | |
| parent | 1017f0d17aa1c745ec0af2de4239c37816d040eb (diff) | |
Added a new menu for path mappings to allow shortcuts like the built-in `...`
Note: need to rethink how normal paths are saved, they should potentially be saved raw (not absolute paths) and then the virtual file list needs to change to string and then dynamically on the fly replace with mappings of key -> value to make an absolute path that then will be used
Diffstat (limited to 'src/main/kotlin/me/kyren223/trident/PathMappingsMenu.kt')
| -rw-r--r-- | src/main/kotlin/me/kyren223/trident/PathMappingsMenu.kt | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/main/kotlin/me/kyren223/trident/PathMappingsMenu.kt b/src/main/kotlin/me/kyren223/trident/PathMappingsMenu.kt new file mode 100644 index 0000000..d098323 --- /dev/null +++ b/src/main/kotlin/me/kyren223/trident/PathMappingsMenu.kt @@ -0,0 +1,63 @@ +package me.kyren223.trident + +import com.intellij.openapi.editor.LogicalPosition +import com.intellij.openapi.ui.DialogWrapper +import com.intellij.ui.EditorTextField +import com.maddyhome.idea.vim.api.injector +import com.maddyhome.idea.vim.newapi.vim +import java.awt.event.FocusEvent +import java.awt.event.FocusListener +import javax.swing.JComponent + +class PathMappingsMenu(private val content: String) : DialogWrapper(true) { + private lateinit var editorTextField: EditorTextField + + init { + val settings = SettingsState.instance + this.title = "Trident Path Mappings Menu" + setSize(settings.width, settings.height) + super.init() + } + + override fun createCenterPanel(): JComponent { + val settings = SettingsState.instance + editorTextField = EditorTextField(this.content) + editorTextField.setOneLineMode(false) + editorTextField.addSettingsProvider { + it.setFontSize(settings.fontSize) + it.isInsertMode = true + it.caretModel.moveToLogicalPosition(LogicalPosition(0, 0)) + it.settings.isLineNumbersShown = true + } + + editorTextField.addFocusListener(object : FocusListener { + override fun focusGained(e: FocusEvent?) { + val editor = editorTextField.editor!!.vim + val context = injector.executionContextManager.onEditor(editor, null) + simulateKeyPress("<ESC>", editor, context) + } + + override fun focusLost(e: FocusEvent?) { /* Do nothing */ } + }) + + return editorTextField + } + + override fun getPreferredFocusedComponent(): JComponent { + return this.editorTextField + } + + override fun doOKAction() { + TridentState.pathMappingsContent = editorTextField.text + super.doOKAction() + } + + override fun doCancelAction() { + TridentState.pathMappingsContent = editorTextField.text + super.doCancelAction() + } + + override fun createSouthPanel(): JComponent? { + return null + } +} |
