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) {