From 0015c3a7fba568b4f8c0d8d523f720a0d9100a35 Mon Sep 17 00:00:00 2001 From: hstyi Date: Wed, 20 Aug 2025 17:04:58 +0800 Subject: [PATCH] chore: select host --- .../kotlin/app/termora/TermoraFencePanel.kt | 42 +++++++++++++++++-- src/main/kotlin/app/termora/TermoraFrame.kt | 2 +- ...mmandTerminalTabbedContextMenuExtension.kt | 3 ++ src/main/resources/i18n/messages.properties | 1 + .../resources/i18n/messages_ru_RU.properties | 1 + .../resources/i18n/messages_zh_CN.properties | 1 + .../resources/i18n/messages_zh_TW.properties | 1 + 7 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/app/termora/TermoraFencePanel.kt b/src/main/kotlin/app/termora/TermoraFencePanel.kt index 0452b0f..6b7d4e7 100644 --- a/src/main/kotlin/app/termora/TermoraFencePanel.kt +++ b/src/main/kotlin/app/termora/TermoraFencePanel.kt @@ -2,6 +2,7 @@ package app.termora import app.termora.actions.AnAction import app.termora.actions.AnActionEvent +import app.termora.plugin.internal.extension.DynamicExtensionHandler import app.termora.tree.NewHostTree import com.formdev.flatlaf.extras.components.FlatTabbedPane import com.formdev.flatlaf.extras.components.FlatToolBar @@ -9,15 +10,14 @@ import com.formdev.flatlaf.util.SystemInfo import java.awt.BorderLayout import java.awt.Dimension import java.awt.Font -import java.awt.event.ComponentAdapter -import java.awt.event.ComponentEvent -import java.awt.event.KeyEvent -import java.awt.event.MouseAdapter +import java.awt.event.* import javax.swing.* +import javax.swing.tree.TreePath import kotlin.math.max class TermoraFencePanel( + private val ws: WindowScope, private val terminalTabbed: TerminalTabbed, private val tabbed: FlatTabbedPane, private val moveMouseAdapter: MouseAdapter, @@ -98,6 +98,40 @@ class TermoraFencePanel( toggle() } + + DynamicExtensionHandler.getInstance() + .register(TerminalTabbedContextMenuExtension::class.java, object : TerminalTabbedContextMenuExtension { + override fun createJMenuItem( + windowScope: WindowScope, + tab: TerminalTab + ): JMenuItem { + if (windowScope != ws) throw UnsupportedOperationException() + if (tab !is HostTerminalTab) throw UnsupportedOperationException() + if (tab.host.isTemporary) throw UnsupportedOperationException() + if (tab.host.id == "local") throw UnsupportedOperationException() + + val item = JMenuItem(I18n.getString("termora.tabbed.contextmenu.select-host")) + item.addActionListener(object : AbstractAction() { + override fun actionPerformed(e: ActionEvent) { + val tree = getHostTree() + for (node in tree.simpleTreeModel.root.getAllChildren()) { + if (node.id == tab.host.id) { + tree.selectionPath = TreePath(tree.simpleTreeModel.getPathToRoot(node)) + tree.requestFocusInWindow() + break + } + } + } + }) + + return item + } + + override fun ordered(): Long { + return Long.MAX_VALUE + } + + }).let { Disposer.register(this, it) } } private inner class LeftTreePanel : JPanel(BorderLayout()), Disposable { diff --git a/src/main/kotlin/app/termora/TermoraFrame.kt b/src/main/kotlin/app/termora/TermoraFrame.kt index 902e2db..9bbc811 100644 --- a/src/main/kotlin/app/termora/TermoraFrame.kt +++ b/src/main/kotlin/app/termora/TermoraFrame.kt @@ -212,7 +212,7 @@ class TermoraFrame : JFrame(), DataProvider { } if (layout == TermoraLayout.Fence) { - val fencePanel = TermoraFencePanel(terminalTabbed, tabbedPane, moveMouseAdapter) + val fencePanel = TermoraFencePanel(windowScope, terminalTabbed, tabbedPane, moveMouseAdapter) add(fencePanel, BorderLayout.CENTER) dataProviderSupport.addData(DataProviders.Welcome.HostTree, fencePanel.getHostTree()) Disposer.register(windowScope, fencePanel) diff --git a/src/main/kotlin/app/termora/plugin/internal/ssh/SftpCommandTerminalTabbedContextMenuExtension.kt b/src/main/kotlin/app/termora/plugin/internal/ssh/SftpCommandTerminalTabbedContextMenuExtension.kt index 511b460..9b8eb07 100644 --- a/src/main/kotlin/app/termora/plugin/internal/ssh/SftpCommandTerminalTabbedContextMenuExtension.kt +++ b/src/main/kotlin/app/termora/plugin/internal/ssh/SftpCommandTerminalTabbedContextMenuExtension.kt @@ -69,4 +69,7 @@ class SftpCommandTerminalTabbedContextMenuExtension private constructor() : Term openHostAction.actionPerformed(OpenHostActionEvent(evt.source, host, evt)) } + override fun ordered(): Long { + return 1 + } } \ No newline at end of file diff --git a/src/main/resources/i18n/messages.properties b/src/main/resources/i18n/messages.properties index f92f91d..9b12cc3 100644 --- a/src/main/resources/i18n/messages.properties +++ b/src/main/resources/i18n/messages.properties @@ -250,6 +250,7 @@ termora.keymgr.ssh-copy-id.end=End of public key copying # Tabbed termora.tabbed.contextmenu.rename=Rename +termora.tabbed.contextmenu.select-host=Select Host termora.tabbed.contextmenu.sftp-command=SFTP Command termora.tabbed.contextmenu.sftp-not-install=SFTP programme not found, please install and try again termora.tabbed.contextmenu.clone=Clone diff --git a/src/main/resources/i18n/messages_ru_RU.properties b/src/main/resources/i18n/messages_ru_RU.properties index d98aef9..e03ed8a 100644 --- a/src/main/resources/i18n/messages_ru_RU.properties +++ b/src/main/resources/i18n/messages_ru_RU.properties @@ -193,6 +193,7 @@ termora.keymgr.ssh-copy-id.end=Копирования открытого клю # Tabbed termora.tabbed.contextmenu.rename=Переименовать +termora.tabbed.contextmenu.select-host=Выбрать хост termora.tabbed.contextmenu.sftp-command=SFTP Команда termora.tabbed.contextmenu.sftp-not-install=Программа SFTP не найдена, пожалуйста, установите и повторите попытку. termora.tabbed.contextmenu.clone=Дублировать diff --git a/src/main/resources/i18n/messages_zh_CN.properties b/src/main/resources/i18n/messages_zh_CN.properties index e47d962..15c561b 100644 --- a/src/main/resources/i18n/messages_zh_CN.properties +++ b/src/main/resources/i18n/messages_zh_CN.properties @@ -246,6 +246,7 @@ termora.tools.multiple=将命令发送到当前窗口会话 # Tabbed termora.tabbed.contextmenu.rename=重命名 +termora.tabbed.contextmenu.select-host=选中主机 termora.tabbed.contextmenu.sftp-command=SFTP 终端 termora.tabbed.contextmenu.sftp-not-install=没有找到 SFTP 程序,请安装后重试 termora.tabbed.contextmenu.clone=克隆 diff --git a/src/main/resources/i18n/messages_zh_TW.properties b/src/main/resources/i18n/messages_zh_TW.properties index ad43a17..7740ab1 100644 --- a/src/main/resources/i18n/messages_zh_TW.properties +++ b/src/main/resources/i18n/messages_zh_TW.properties @@ -241,6 +241,7 @@ termora.tools.multiple=將命令傳送到目前視窗會話 # Tabbed termora.tabbed.contextmenu.rename=重新命名 +termora.tabbed.contextmenu.select-host=選取主機 termora.tabbed.contextmenu.sftp-command=SFTP 終端 termora.tabbed.contextmenu.sftp-not-install=沒有找到 SFTP 程序,請安裝後重試 termora.tabbed.contextmenu.clone=克隆