From 68788905fe1ecc4d0e76d4ea60620e91531cdd5f Mon Sep 17 00:00:00 2001 From: hstyi Date: Wed, 14 May 2025 23:24:52 +0800 Subject: [PATCH] chore: improve sftp tab (#583) --- src/main/kotlin/app/termora/sftp/SFTPAction.kt | 10 ++++++++++ .../kotlin/app/termora/sftp/SFTPFileSystemViewPanel.kt | 10 +++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/app/termora/sftp/SFTPAction.kt b/src/main/kotlin/app/termora/sftp/SFTPAction.kt index 8578c96..88cd26e 100644 --- a/src/main/kotlin/app/termora/sftp/SFTPAction.kt +++ b/src/main/kotlin/app/termora/sftp/SFTPAction.kt @@ -56,6 +56,16 @@ class SFTPAction : AnAction("SFTP", Icons.folder) { } 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) } diff --git a/src/main/kotlin/app/termora/sftp/SFTPFileSystemViewPanel.kt b/src/main/kotlin/app/termora/sftp/SFTPFileSystemViewPanel.kt index e61094c..e9e93c8 100644 --- a/src/main/kotlin/app/termora/sftp/SFTPFileSystemViewPanel.kt +++ b/src/main/kotlin/app/termora/sftp/SFTPFileSystemViewPanel.kt @@ -286,9 +286,7 @@ class SFTPFileSystemViewPanel( val node = tree.getLastSelectedPathNode() ?: return if (node.isFolder) return val host = node.data as Host - that.setTabTitle(host.name) - that.host = host - that.connect() + selectHost(host) } } }) @@ -318,6 +316,12 @@ class SFTPFileSystemViewPanel( } } + fun selectHost(host: Host) { + that.setTabTitle(host.name) + that.host = host + that.connect() + } + private fun setTabTitle(title: String) { val tabbed = SwingUtilities.getAncestorOfClass(JTabbedPane::class.java, that) if (tabbed is JTabbedPane) {