mirror of
https://github.com/TermoraDev/termora.git
synced 2026-01-16 10:22:58 +08:00
feat: SFTP 支持不显示隐藏文件
This commit is contained in:
@@ -8,6 +8,8 @@ object Icons {
|
||||
val moveDown by lazy { DynamicIcon("icons/moveDown.svg", "icons/moveDown_dark.svg") }
|
||||
val close by lazy { DynamicIcon("icons/close.svg", "icons/close_dark.svg") }
|
||||
val searchHistory by lazy { DynamicIcon("icons/searchHistory.svg", "icons/searchHistory_dark.svg") }
|
||||
val eye by lazy { DynamicIcon("icons/eye.svg", "icons/eye_dark.svg") }
|
||||
val eyeClose by lazy { DynamicIcon("icons/eyeClose.svg", "icons/eyeClose_dark.svg") }
|
||||
val matchCase by lazy { DynamicIcon("icons/matchCase.svg", "icons/matchCase_dark.svg") }
|
||||
val regex by lazy { DynamicIcon("icons/regex.svg", "icons/regex_dark.svg") }
|
||||
val vcs by lazy { DynamicIcon("icons/vcs.svg", "icons/vcs_dark.svg") }
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.formdev.flatlaf.extras.components.FlatPopupMenu
|
||||
import com.formdev.flatlaf.extras.components.FlatToolBar
|
||||
import com.formdev.flatlaf.icons.FlatFileViewDirectoryIcon
|
||||
import com.formdev.flatlaf.icons.FlatFileViewFileIcon
|
||||
import com.formdev.flatlaf.ui.FlatTableUI
|
||||
import com.formdev.flatlaf.util.SystemInfo
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.swing.Swing
|
||||
@@ -42,8 +43,7 @@ class FileSystemPanel(
|
||||
private val fileSystem: FileSystem,
|
||||
private val transportManager: TransportManager,
|
||||
private val host: Host
|
||||
) : JPanel(BorderLayout()), Disposable,
|
||||
FileSystemTransportListener.Provider {
|
||||
) : JPanel(BorderLayout()), Disposable, FileSystemTransportListener.Provider {
|
||||
|
||||
companion object {
|
||||
private val log = LoggerFactory.getLogger(FileSystemPanel::class.java)
|
||||
@@ -58,6 +58,10 @@ class FileSystemPanel(
|
||||
private val loadingPanel = LoadingPanel()
|
||||
private val bookmarkBtn = BookmarkButton()
|
||||
private val homeBtn = JButton(Icons.homeFolder)
|
||||
private val showHiddenFilesBtn = JButton(Icons.eyeClose)
|
||||
private val properties get() = Database.getDatabase().properties
|
||||
private var isShowHiddenFiles = false
|
||||
private val showHiddenFilesKey by lazy { "termora.transport.host.${host.id}.show-hidden-files" }
|
||||
|
||||
val workdir get() = tableModel.workdir
|
||||
|
||||
@@ -72,6 +76,8 @@ class FileSystemPanel(
|
||||
bookmarkBtn.name = "Host.${host.id}.Bookmarks"
|
||||
bookmarkBtn.isBookmark = bookmarkBtn.getBookmarks().contains(workdir.toString())
|
||||
|
||||
table.setUI(FlatTableUI())
|
||||
table.rowHeight = UIManager.getInt("Table.rowHeight")
|
||||
table.autoResizeMode = JTable.AUTO_RESIZE_OFF
|
||||
table.fillsViewportHeight = true
|
||||
table.putClientProperty(
|
||||
@@ -121,6 +127,16 @@ class FileSystemPanel(
|
||||
})
|
||||
|
||||
parentBtn.toolTipText = I18n.getString("termora.transport.parent-folder")
|
||||
showHiddenFilesBtn.toolTipText = I18n.getString("termora.transport.show-hidden-files")
|
||||
|
||||
if (properties.getString(showHiddenFilesKey, "true").toBoolean()) {
|
||||
showHiddenFilesBtn.icon = Icons.eye
|
||||
tableModel.isShowHiddenFiles = true
|
||||
} else {
|
||||
showHiddenFilesBtn.icon = Icons.eyeClose
|
||||
properties.putString(showHiddenFilesKey, "true")
|
||||
tableModel.isShowHiddenFiles = false
|
||||
}
|
||||
|
||||
|
||||
val toolbar = FlatToolBar()
|
||||
@@ -128,6 +144,7 @@ class FileSystemPanel(
|
||||
toolbar.add(Box.createHorizontalStrut(2))
|
||||
toolbar.add(workdirTextField)
|
||||
toolbar.add(bookmarkBtn)
|
||||
toolbar.add(showHiddenFilesBtn)
|
||||
toolbar.add(parentBtn)
|
||||
toolbar.add(JButton(Icons.refresh).apply {
|
||||
addActionListener { reload() }
|
||||
@@ -290,6 +307,21 @@ class FileSystemPanel(
|
||||
}
|
||||
}
|
||||
|
||||
showHiddenFilesBtn.addActionListener {
|
||||
val showHiddenFiles = tableModel.isShowHiddenFiles
|
||||
tableModel.isShowHiddenFiles = !showHiddenFiles
|
||||
if (tableModel.isShowHiddenFiles) {
|
||||
showHiddenFilesBtn.icon = Icons.eye
|
||||
} else {
|
||||
showHiddenFilesBtn.icon = Icons.eyeClose
|
||||
}
|
||||
}
|
||||
|
||||
Disposer.register(this, object : Disposable {
|
||||
override fun dispose() {
|
||||
properties.putString(showHiddenFilesKey, "${tableModel.isShowHiddenFiles}")
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -45,13 +45,18 @@ class FileSystemTableModel(private val fileSystem: FileSystem) : DefaultTableMod
|
||||
private val propertyChangeListeners = mutableListOf<PropertyChangeListener>()
|
||||
|
||||
val isLocalFileSystem by lazy { FileSystems.getDefault() == fileSystem }
|
||||
var isShowHiddenFiles = false
|
||||
set(value) {
|
||||
field = value
|
||||
fireTableDataChanged()
|
||||
}
|
||||
|
||||
override fun getRowCount(): Int {
|
||||
return files?.size ?: 0
|
||||
return getShownFiles().size
|
||||
}
|
||||
|
||||
override fun getValueAt(row: Int, column: Int): Any {
|
||||
val path = files?.get(row) ?: return StringUtils.EMPTY
|
||||
val path = getShownFiles()[row]
|
||||
|
||||
if (path.fileName == ".." && column != 0) {
|
||||
return StringUtils.EMPTY
|
||||
@@ -98,7 +103,7 @@ class FileSystemTableModel(private val fileSystem: FileSystem) : DefaultTableMod
|
||||
}
|
||||
|
||||
fun getCacheablePath(index: Int): CacheablePath {
|
||||
return files?.get(index) ?: throw IndexOutOfBoundsException()
|
||||
return getShownFiles()[index]
|
||||
}
|
||||
|
||||
override fun isCellEditable(row: Int, column: Int): Boolean {
|
||||
@@ -106,7 +111,8 @@ class FileSystemTableModel(private val fileSystem: FileSystem) : DefaultTableMod
|
||||
}
|
||||
|
||||
override fun removeRow(row: Int) {
|
||||
files?.removeAt(row) ?: return
|
||||
val e = getShownFiles()[row]
|
||||
files?.removeIf { it == e }
|
||||
fireTableRowsDeleted(row, row)
|
||||
}
|
||||
|
||||
@@ -155,11 +161,19 @@ class FileSystemTableModel(private val fileSystem: FileSystem) : DefaultTableMod
|
||||
propertyChangeListeners.add(propertyChangeListener)
|
||||
}
|
||||
|
||||
private fun getShownFiles(): List<CacheablePath> {
|
||||
if (isShowHiddenFiles) {
|
||||
return files ?: emptyList()
|
||||
}
|
||||
return files?.filter { !it.isHidden } ?: emptyList()
|
||||
}
|
||||
|
||||
open class CacheablePath(val path: Path) {
|
||||
val fileName by lazy { path.fileName.toString() }
|
||||
val extension by lazy { path.extension }
|
||||
|
||||
open val isDirectory by lazy { path.isDirectory() }
|
||||
open val isHidden by lazy { fileName != ".." && path.isHidden() }
|
||||
open val fileSize by lazy { path.fileSize() }
|
||||
open val lastModifiedTime by lazy { Files.getLastModifiedTime(path).toMillis() }
|
||||
open val owner by lazy { path.getOwner().toString() }
|
||||
@@ -216,6 +230,9 @@ class FileSystemTableModel(private val fileSystem: FileSystem) : DefaultTableMod
|
||||
override val isDirectory: Boolean
|
||||
get() = attributes.isDirectory
|
||||
|
||||
override val isHidden: Boolean
|
||||
get() = fileName != ".." && fileName.startsWith(".")
|
||||
|
||||
override val fileSize: Long
|
||||
get() = attributes.size
|
||||
|
||||
|
||||
Reference in New Issue
Block a user