diff options
| author | Kyren223 <ulmliad223@gmail.com> | 2024-02-14 11:36:29 +0200 |
|---|---|---|
| committer | Kyren223 <ulmliad223@gmail.com> | 2024-02-14 11:36:29 +0200 |
| commit | b11d3305fa409d3ec3f2c9a0f43b1667f8c64cb5 (patch) | |
| tree | 30d11a23ed65c041f40117c692e416efbd8018de /src/main/kotlin | |
| parent | efe9b7e3b4ad2c1960aff5a5d1569cac98e281d0 (diff) | |
Fixed issue with file not saving when cancelled
You can now delete/move/add files
Shortcut paths (using $ syntax) not implemented yet
Diffstat (limited to 'src/main/kotlin')
| -rw-r--r-- | src/main/kotlin/me/kyren223/harpoonforjb/HarpoonQuickMenu.kt | 16 | ||||
| -rw-r--r-- | src/main/kotlin/me/kyren223/harpoonforjb/HarpoonState.kt | 60 |
2 files changed, 53 insertions, 23 deletions
diff --git a/src/main/kotlin/me/kyren223/harpoonforjb/HarpoonQuickMenu.kt b/src/main/kotlin/me/kyren223/harpoonforjb/HarpoonQuickMenu.kt index baf027b..3417d7c 100644 --- a/src/main/kotlin/me/kyren223/harpoonforjb/HarpoonQuickMenu.kt +++ b/src/main/kotlin/me/kyren223/harpoonforjb/HarpoonQuickMenu.kt @@ -2,9 +2,7 @@ package me.kyren223.harpoonforjb -import com.intellij.ide.plugins.PluginManagerCore import com.intellij.openapi.editor.LogicalPosition -import com.intellij.openapi.extensions.PluginId import com.intellij.openapi.ui.DialogWrapper import com.intellij.ui.EditorTextField import com.maddyhome.idea.vim.KeyHandler @@ -27,7 +25,6 @@ class HarpoonQuickMenu(private val content: String) : DialogWrapper(true) { } override fun createCenterPanel(): JComponent { - println("Content: \n$content") val settings = AppSettingsState.instance editorTextField = EditorTextField(this.content) editorTextField.setOneLineMode(false) @@ -55,17 +52,26 @@ class HarpoonQuickMenu(private val content: String) : DialogWrapper(true) { KeyHandler.getInstance().handleKey(editor, injector.parser.parseKeys(key)[0], context) } - override fun getPreferredFocusedComponent(): JComponent? { + override fun getPreferredFocusedComponent(): JComponent { return this.editorTextField } fun select() { if (this.editorTextField.editor == null) return - HarpoonState.quickMenuContent = this.editorTextField.text HarpoonState.quickMenuSelectedIndex = this.editorTextField.editor!!.caretModel.logicalPosition.line doOKAction() } + override fun doOKAction() { + HarpoonState.quickMenuContent = editorTextField.text + super.doOKAction() + } + + override fun doCancelAction() { + HarpoonState.quickMenuContent = editorTextField.text + super.doCancelAction() + } + override fun createSouthPanel(): JComponent? { return null } diff --git a/src/main/kotlin/me/kyren223/harpoonforjb/HarpoonState.kt b/src/main/kotlin/me/kyren223/harpoonforjb/HarpoonState.kt index 36f3b0c..3b476c2 100644 --- a/src/main/kotlin/me/kyren223/harpoonforjb/HarpoonState.kt +++ b/src/main/kotlin/me/kyren223/harpoonforjb/HarpoonState.kt @@ -13,14 +13,6 @@ object HarpoonState { var quickMenuSelectedIndex: Int? = null var quickMenuContent: String? = "" - fun setFile(project: Project, index: Int, file: VirtualFile) { - if (index < 0) return - loadProject(project) - val files = projectFiles[project.name] - if (files!!.size <= index) return - files[index] = file - saveProject(project) - } fun appendFile(project: Project, file: VirtualFile) { if (!file.isValid) return @@ -80,23 +72,32 @@ object HarpoonState { } fun toggleQuickMenu(project: Project) { - loadProject(project) - val content = projectFiles[project.name]!! - .joinToString("\n") { it.path } - .replace(project.basePath!!, "...") - .trim() + if (quickMenu != null && quickMenu!!.isShowing) { + println("Canceling quick menu") + quickMenu!!.doCancelAction() + return + } + loadProject(project) + val content = getProjectContent(project) quickMenu = HarpoonQuickMenu(content) val result = quickMenu!!.showAndGet() - if (content != quickMenuContent) { + if (quickMenuContent != null && content != quickMenuContent) { // Update the content - // TODO: Update the content +// println("Content Before:\n${quickMenuContent}") + retrieveProjectFiles(project, quickMenuContent!!) +// val contentAfter = projectFiles[project.name]!! +// .joinToString("\n") { it.path } +// .trim() +// println("Content After:\n${contentAfter}") + saveProject(project) } - if (!result || quickMenuSelectedIndex == null) return - println("Selected index: $quickMenuSelectedIndex") - val file = selectFile(project, quickMenuSelectedIndex!!) ?: return + if (!result) return + val index = quickMenuSelectedIndex ?: return + quickMenuSelectedIndex = null + val file = selectFile(project, index) ?: return FileEditorManager.getInstance(project).openFile(file, true) } @@ -104,4 +105,27 @@ object HarpoonState { if (quickMenu == null || !quickMenu!!.isShowing) return quickMenu!!.select() } + + private fun getProjectContent(project: Project): String { + val content = projectFiles[project.name]!! + .joinToString("\n") { it.path } + .replace(project.basePath!!, "...") + .trim() + return content + } + + private fun retrieveProjectFiles(project: Project, content: String) { + loadProject(project) + val files = content + .split("\n") + .asSequence() + .map { it.trim() } + .map { it.replace("...", project.basePath!!) } + .filter { it.isNotBlank() } + .map { LocalFileSystem.getInstance().findFileByPath(it) } + .filterNotNull() + .filter { it.isValid } + .toMutableList() + projectFiles[project.name] = files + } }
\ No newline at end of file |
