chore: improve sftp tab (#583)

This commit is contained in:
hstyi
2025-05-14 23:24:52 +08:00
committed by GitHub
parent fc46216a3f
commit 68788905fe
2 changed files with 17 additions and 3 deletions

View File

@@ -56,6 +56,16 @@ class SFTPAction : AnAction("SFTP", Icons.folder) {
} }
val host = hostManager.getHost(hostId) ?: return val host = hostManager.getHost(hostId) ?: return
for (i in 0 until tabbed.tabCount) {
val c = tabbed.getComponentAt(i)
if (c is SFTPFileSystemViewPanel) {
if (c.state == SFTPFileSystemViewPanel.State.Initialized) {
c.selectHost(host)
return
}
}
}
tabbed.addSFTPFileSystemViewPanelTab(host) tabbed.addSFTPFileSystemViewPanelTab(host)
} }

View File

@@ -286,9 +286,7 @@ class SFTPFileSystemViewPanel(
val node = tree.getLastSelectedPathNode() ?: return val node = tree.getLastSelectedPathNode() ?: return
if (node.isFolder) return if (node.isFolder) return
val host = node.data as Host val host = node.data as Host
that.setTabTitle(host.name) selectHost(host)
that.host = host
that.connect()
} }
} }
}) })
@@ -318,6 +316,12 @@ class SFTPFileSystemViewPanel(
} }
} }
fun selectHost(host: Host) {
that.setTabTitle(host.name)
that.host = host
that.connect()
}
private fun setTabTitle(title: String) { private fun setTabTitle(title: String) {
val tabbed = SwingUtilities.getAncestorOfClass(JTabbedPane::class.java, that) val tabbed = SwingUtilities.getAncestorOfClass(JTabbedPane::class.java, that)
if (tabbed is JTabbedPane) { if (tabbed is JTabbedPane) {