chore: improve contextmenu (#251)

This commit is contained in:
hstyi
2025-02-16 11:14:37 +08:00
committed by GitHub
parent 309909cbd7
commit 47d1a13189
4 changed files with 22 additions and 8 deletions

View File

@@ -352,8 +352,10 @@ class HostTree : JTree(), Disposable {
val newFolder = newMenu.add(I18n.getString("termora.welcome.contextmenu.new.folder")) val newFolder = newMenu.add(I18n.getString("termora.welcome.contextmenu.new.folder"))
val newHost = newMenu.add(I18n.getString("termora.welcome.contextmenu.new.host")) val newHost = newMenu.add(I18n.getString("termora.welcome.contextmenu.new.host"))
val open = popupMenu.add(I18n.getString("termora.welcome.contextmenu.open")) val open = popupMenu.add(I18n.getString("termora.welcome.contextmenu.connect"))
val openWithSFTP = popupMenu.add(I18n.getString("termora.welcome.contextmenu.open-with-sftp")) val openWith = popupMenu.add(JMenu(I18n.getString("termora.welcome.contextmenu.connect-with"))) as JMenu
val openWithSFTP = openWith.add("SFTP")
val openWithSFTPCommand = openWith.add(I18n.getString("termora.tabbed.contextmenu.sftp-command"))
val openInNewWindow = popupMenu.add(I18n.getString("termora.welcome.contextmenu.open-in-new-window")) val openInNewWindow = popupMenu.add(I18n.getString("termora.welcome.contextmenu.open-in-new-window"))
popupMenu.addSeparator() popupMenu.addSeparator()
val copy = popupMenu.add(I18n.getString("termora.welcome.contextmenu.copy")) val copy = popupMenu.add(I18n.getString("termora.welcome.contextmenu.copy"))
@@ -380,10 +382,13 @@ class HostTree : JTree(), Disposable {
open.addActionListener { openHosts(it, false) } open.addActionListener { openHosts(it, false) }
openWithSFTP.addActionListener { openWithSFTP(it) } openWithSFTP.addActionListener { openWithSFTP(it) }
openWithSFTPCommand.addActionListener { openWithSFTPCommand(it) }
openInNewWindow.addActionListener { openHosts(it, true) } openInNewWindow.addActionListener { openHosts(it, true) }
// 如果选中了 SSH 服务器,那么才启用 // 如果选中了 SSH 服务器,那么才启用
openWithSFTP.isEnabled = getSelectionNodes().any { it.protocol == Protocol.SSH } openWithSFTP.isEnabled = getSelectionNodes().any { it.protocol == Protocol.SSH }
openWithSFTPCommand.isEnabled = openWithSFTP.isEnabled
openWith.isEnabled = openWith.menuComponents.any { it is JMenuItem && it.isEnabled }
rename.addActionListener { rename.addActionListener {
startEditingAtPath(TreePath(model.getPathToRoot(lastHost))) startEditingAtPath(TreePath(model.getPathToRoot(lastHost)))
@@ -523,6 +528,15 @@ class HostTree : JTree(), Disposable {
} }
} }
private fun openWithSFTPCommand(evt: EventObject) {
val nodes = getSelectionNodes().filter { it.protocol == Protocol.SSH }
if (nodes.isEmpty()) return
val action = ActionManager.getInstance().getAction(OpenHostAction.OPEN_HOST) ?: return
for (host in nodes) {
action.actionPerformed(OpenHostActionEvent(this, host.copy(protocol = Protocol.SFTPPty), evt))
}
}
fun expandNode(node: Host, including: Boolean = false) { fun expandNode(node: Host, including: Boolean = false) {
expandPath(TreePath(model.getPathToRoot(node))) expandPath(TreePath(model.getPathToRoot(node)))
if (including) { if (including) {

View File

@@ -128,8 +128,8 @@ termora.find-everywhere.double-shift-deprecated-instead=${termora.find-everywher
# Welcome # Welcome
termora.welcome.my-hosts=My hosts termora.welcome.my-hosts=My hosts
termora.welcome.contextmenu.open=Open termora.welcome.contextmenu.connect=Connect
termora.welcome.contextmenu.open-with-sftp=Open with SFTP termora.welcome.contextmenu.connect-with=Connect with
termora.welcome.contextmenu.open-in-new-window=${termora.tabbed.contextmenu.open-in-new-window} termora.welcome.contextmenu.open-in-new-window=${termora.tabbed.contextmenu.open-in-new-window}
termora.welcome.contextmenu.copy=${termora.copy} termora.welcome.contextmenu.copy=${termora.copy}
termora.welcome.contextmenu.remove=${termora.remove} termora.welcome.contextmenu.remove=${termora.remove}

View File

@@ -118,8 +118,8 @@ termora.settings.sftp.edit-command=编辑命令
# Welcome # Welcome
termora.welcome.my-hosts=我的主机 termora.welcome.my-hosts=我的主机
termora.welcome.contextmenu.open=打开 termora.welcome.contextmenu.connect=连接
termora.welcome.contextmenu.open-with-sftp=使用 SFTP 打开 termora.welcome.contextmenu.connect-with=连接到
termora.welcome.contextmenu.copy=${termora.copy} termora.welcome.contextmenu.copy=${termora.copy}
termora.welcome.contextmenu.remove=${termora.remove} termora.welcome.contextmenu.remove=${termora.remove}
termora.welcome.contextmenu.rename=重命名 termora.welcome.contextmenu.rename=重命名

View File

@@ -117,8 +117,8 @@ termora.settings.about.termora=<html><b>${termora.title}</b> ({0}) 是一個跨
# Welcome # Welcome
termora.welcome.my-hosts=我的主機 termora.welcome.my-hosts=我的主機
termora.welcome.contextmenu.open=打開 termora.welcome.contextmenu.connect=連接
termora.welcome.contextmenu.open-with-sftp=使用 SFTP 打開 termora.welcome.contextmenu.connect-with=連接到
termora.welcome.contextmenu.copy=複製 termora.welcome.contextmenu.copy=複製
termora.welcome.contextmenu.remove=${termora.remove} termora.welcome.contextmenu.remove=${termora.remove}
termora.welcome.contextmenu.rename=重新命名 termora.welcome.contextmenu.rename=重新命名