feat: improve SFTP (#572)

This commit is contained in:
hstyi
2025-05-12 15:37:39 +08:00
committed by GitHub
parent ea25b5b46f
commit 928a866fe7
2 changed files with 32 additions and 24 deletions

View File

@@ -27,6 +27,8 @@ import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent import java.awt.event.MouseEvent
import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicBoolean
import javax.swing.* import javax.swing.*
import javax.swing.event.TreeExpansionEvent
import javax.swing.event.TreeExpansionListener
class SFTPFileSystemViewPanel( class SFTPFileSystemViewPanel(
var host: Host? = null, var host: Host? = null,
@@ -35,17 +37,18 @@ class SFTPFileSystemViewPanel(
companion object { companion object {
private val log = LoggerFactory.getLogger(SFTPFileSystemViewPanel::class.java) private val log = LoggerFactory.getLogger(SFTPFileSystemViewPanel::class.java)
}
private enum class State { enum class State {
Initialized, Initialized,
Connecting, Connecting,
Connected, Connected,
ConnectFailed, ConnectFailed,
} }
}
@Volatile @Volatile
private var state = State.Initialized var state = State.Initialized
private set
private val cardLayout = CardLayout() private val cardLayout = CardLayout()
private val cardPanel = JPanel(cardLayout) private val cardPanel = JPanel(cardLayout)
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO) private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
@@ -289,6 +292,16 @@ class SFTPFileSystemViewPanel(
} }
} }
}) })
tree.addTreeExpansionListener(object : TreeExpansionListener {
override fun treeExpanded(event: TreeExpansionEvent) {
properties.putString("SFTPTabbed.Tree.state", TreeUtils.saveExpansionState(tree))
}
override fun treeCollapsed(event: TreeExpansionEvent) {
properties.putString("SFTPTabbed.Tree.state", TreeUtils.saveExpansionState(tree))
}
})
} }
override fun dispose() { override fun dispose() {

View File

@@ -5,7 +5,6 @@ import app.termora.actions.AnAction
import app.termora.actions.AnActionEvent import app.termora.actions.AnActionEvent
import com.formdev.flatlaf.extras.components.FlatPopupMenu import com.formdev.flatlaf.extras.components.FlatPopupMenu
import com.formdev.flatlaf.extras.components.FlatTabbedPane import com.formdev.flatlaf.extras.components.FlatTabbedPane
import java.awt.Point
import java.awt.event.MouseAdapter import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent import java.awt.event.MouseEvent
import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicBoolean
@@ -13,7 +12,6 @@ import javax.swing.JButton
import javax.swing.JToolBar import javax.swing.JToolBar
import javax.swing.SwingUtilities import javax.swing.SwingUtilities
import javax.swing.UIManager import javax.swing.UIManager
import kotlin.math.max
@Suppress("DuplicatedCode") @Suppress("DuplicatedCode")
class SFTPTabbed(private val transportManager: TransportManager) : FlatTabbedPane(), Disposable { class SFTPTabbed(private val transportManager: TransportManager) : FlatTabbedPane(), Disposable {
@@ -43,23 +41,20 @@ class SFTPTabbed(private val transportManager: TransportManager) : FlatTabbedPan
private fun initEvents() { private fun initEvents() {
addBtn.addActionListener(object : AnAction() { addBtn.addActionListener(object : AnAction() {
override fun actionPerformed(evt: AnActionEvent) { override fun actionPerformed(evt: AnActionEvent) {
val dialog = NewHostTreeDialog(SwingUtilities.getWindowAncestor(tabbed)) for (i in 0 until tabCount) {
dialog.location = Point( val c = getComponentAt(i)
max(0, addBtn.locationOnScreen.x - dialog.width / 2 + addBtn.width / 2), if (c !is SFTPFileSystemViewPanel) continue
addBtn.locationOnScreen.y + max(tabHeight, addBtn.height) if (c.state != SFTPFileSystemViewPanel.State.Initialized) continue
) selectedIndex = i
dialog.setFilter { it.host.protocol == Protocol.SSH } return
dialog.setTreeName("SFTPTabbed.Tree")
dialog.allowMulti = true
dialog.isVisible = true
val hosts = dialog.hosts
if (hosts.isEmpty()) return
for (host in hosts) {
addSFTPFileSystemViewPanelTab(host)
} }
// 添加一个新的
addTab(
I18n.getString("termora.transport.sftp.select-host"),
SFTPFileSystemViewPanel(transportManager = transportManager)
)
selectedIndex = tabCount - 1
} }
}) })