mirror of
https://github.com/TermoraDev/termora.git
synced 2026-01-16 02:12:58 +08:00
feat: sftp contextmenu (#366)
This commit is contained in:
@@ -3,13 +3,17 @@ package app.termora.sftp
|
||||
import app.termora.*
|
||||
import app.termora.actions.AnAction
|
||||
import app.termora.actions.AnActionEvent
|
||||
import com.formdev.flatlaf.extras.components.FlatPopupMenu
|
||||
import com.formdev.flatlaf.extras.components.FlatTabbedPane
|
||||
import java.awt.Point
|
||||
import java.awt.event.MouseAdapter
|
||||
import java.awt.event.MouseEvent
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import javax.swing.JButton
|
||||
import javax.swing.JToolBar
|
||||
import javax.swing.SwingUtilities
|
||||
import javax.swing.UIManager
|
||||
import kotlin.io.path.absolutePathString
|
||||
import kotlin.math.max
|
||||
|
||||
@Suppress("DuplicatedCode")
|
||||
@@ -17,6 +21,7 @@ class SFTPTabbed(private val transportManager: TransportManager) : FlatTabbedPan
|
||||
private val addBtn = JButton(Icons.add)
|
||||
private val tabbed = this
|
||||
private val disposed = AtomicBoolean(false)
|
||||
private val hostManager get() = HostManager.getInstance()
|
||||
|
||||
val isDisposed get() = disposed.get()
|
||||
|
||||
@@ -67,6 +72,59 @@ class SFTPTabbed(private val transportManager: TransportManager) : FlatTabbedPan
|
||||
}
|
||||
})
|
||||
|
||||
// 右键菜单
|
||||
addMouseListener(object : MouseAdapter() {
|
||||
override fun mouseClicked(e: MouseEvent) {
|
||||
if (!SwingUtilities.isRightMouseButton(e)) {
|
||||
return
|
||||
}
|
||||
|
||||
val index = indexAtLocation(e.x, e.y)
|
||||
if (index < 0) return
|
||||
|
||||
showContextMenu(index, e)
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
private fun showContextMenu(tabIndex: Int, e: MouseEvent) {
|
||||
val panel = getFileSystemViewPanel(tabIndex) ?: return
|
||||
val popupMenu = FlatPopupMenu()
|
||||
// 克隆
|
||||
val clone = popupMenu.add(I18n.getString("termora.tabbed.contextmenu.clone"))
|
||||
clone.addActionListener(object : AnAction() {
|
||||
override fun actionPerformed(evt: AnActionEvent) {
|
||||
val host = hostManager.getHost(panel.host.id) ?: return
|
||||
addSFTPFileSystemViewPanelTab(
|
||||
host.copy(
|
||||
options = host.options.copy(
|
||||
sftpDefaultDirectory = panel.getWorkdir().absolutePathString()
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
// 编辑
|
||||
val edit = popupMenu.add(I18n.getString("termora.keymgr.edit"))
|
||||
edit.addActionListener(object : AnAction() {
|
||||
override fun actionPerformed(evt: AnActionEvent) {
|
||||
if (panel.host.id == "local") {
|
||||
return
|
||||
}
|
||||
val host = hostManager.getHost(panel.host.id) ?: return
|
||||
val dialog = HostDialog(evt.window, host)
|
||||
dialog.setLocationRelativeTo(evt.window)
|
||||
dialog.isVisible = true
|
||||
hostManager.addHost(dialog.host ?: return)
|
||||
}
|
||||
})
|
||||
|
||||
clone.isEnabled = panel.host.id != "local"
|
||||
edit.isEnabled = clone.isEnabled
|
||||
|
||||
popupMenu.show(this, e.x, e.y)
|
||||
}
|
||||
|
||||
fun addSFTPFileSystemViewPanelTab(host: Host) {
|
||||
|
||||
Reference in New Issue
Block a user