mirror of
https://github.com/TermoraDev/termora.git
synced 2026-01-16 02:12:58 +08:00
feat: FindEverywhere show more info
This commit is contained in:
@@ -2,7 +2,6 @@ package app.termora
|
|||||||
|
|
||||||
|
|
||||||
import app.termora.actions.*
|
import app.termora.actions.*
|
||||||
import app.termora.findeverywhere.BasicFilterFindEverywhereProvider
|
|
||||||
import app.termora.findeverywhere.FindEverywhereProvider
|
import app.termora.findeverywhere.FindEverywhereProvider
|
||||||
import app.termora.findeverywhere.FindEverywhereResult
|
import app.termora.findeverywhere.FindEverywhereResult
|
||||||
import app.termora.terminal.DataKey
|
import app.termora.terminal.DataKey
|
||||||
@@ -164,12 +163,23 @@ class WelcomePanel(private val windowScope: WindowScope) : JPanel(BorderLayout()
|
|||||||
|
|
||||||
|
|
||||||
FindEverywhereProvider.getFindEverywhereProviders(windowScope)
|
FindEverywhereProvider.getFindEverywhereProviders(windowScope)
|
||||||
.add(BasicFilterFindEverywhereProvider(object : FindEverywhereProvider {
|
.add(object : FindEverywhereProvider {
|
||||||
override fun find(pattern: String): List<FindEverywhereResult> {
|
override fun find(pattern: String): List<FindEverywhereResult> {
|
||||||
return TreeUtils.children(hostTree.model, hostTree.model.root)
|
var filter = TreeUtils.children(hostTree.model, hostTree.model.root)
|
||||||
.filterIsInstance<Host>()
|
.filterIsInstance<Host>()
|
||||||
.filter { it.protocol != Protocol.Folder }
|
.filter { it.protocol != Protocol.Folder }
|
||||||
.map { HostFindEverywhereResult(it) }
|
|
||||||
|
if (pattern.isNotBlank()) {
|
||||||
|
filter = filter.filter {
|
||||||
|
if (it.protocol == Protocol.SSH) {
|
||||||
|
it.name.contains(pattern, true) || it.host.contains(pattern, true)
|
||||||
|
} else {
|
||||||
|
it.name.contains(pattern, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return filter.map { HostFindEverywhereResult(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun group(): String {
|
override fun group(): String {
|
||||||
@@ -179,7 +189,7 @@ class WelcomePanel(private val windowScope: WindowScope) : JPanel(BorderLayout()
|
|||||||
override fun order(): Int {
|
override fun order(): Int {
|
||||||
return Integer.MIN_VALUE + 2
|
return Integer.MIN_VALUE + 2
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
searchTextField.document.addDocumentListener(object : DocumentAdaptor() {
|
searchTextField.document.addDocumentListener(object : DocumentAdaptor() {
|
||||||
private var state = StringUtils.EMPTY
|
private var state = StringUtils.EMPTY
|
||||||
@@ -245,7 +255,9 @@ class WelcomePanel(private val windowScope: WindowScope) : JPanel(BorderLayout()
|
|||||||
properties.putString("WelcomeFullContent", fullContent.toString())
|
properties.putString("WelcomeFullContent", fullContent.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
private class HostFindEverywhereResult(val host: Host) : FindEverywhereResult {
|
private inner class HostFindEverywhereResult(val host: Host) : FindEverywhereResult {
|
||||||
|
private val showMoreInfo get() = properties.getString("HostTree.showMoreInfo", "false").toBoolean()
|
||||||
|
|
||||||
override fun actionPerformed(e: ActionEvent) {
|
override fun actionPerformed(e: ActionEvent) {
|
||||||
ActionManager.getInstance()
|
ActionManager.getInstance()
|
||||||
.getAction(OpenHostAction.OPEN_HOST)
|
.getAction(OpenHostAction.OPEN_HOST)
|
||||||
@@ -261,7 +273,20 @@ class WelcomePanel(private val windowScope: WindowScope) : JPanel(BorderLayout()
|
|||||||
return Icons.terminal
|
return Icons.terminal
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun getText(isSelected: Boolean): String {
|
||||||
|
if (showMoreInfo) {
|
||||||
|
val color = UIManager.getColor(if (isSelected) "textHighlightText" else "textInactiveText")
|
||||||
|
val moreInfo = if (host.protocol == Protocol.SSH) {
|
||||||
|
"${host.username}@${host.host}"
|
||||||
|
} else if (host.protocol == Protocol.Serial) {
|
||||||
|
host.options.serialComm.port
|
||||||
|
} else {
|
||||||
|
StringUtils.EMPTY
|
||||||
|
}
|
||||||
|
if (moreInfo.isNotBlank()) {
|
||||||
|
return "<html>${host.name} <font color=rgb(${color.red},${color.green},${color.blue})>${moreInfo}</font></html>"
|
||||||
|
}
|
||||||
|
}
|
||||||
return host.name
|
return host.name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,5 +8,6 @@ interface FindEverywhereResult : ActionListener {
|
|||||||
|
|
||||||
fun getIcon(isSelected: Boolean): Icon = Icons.empty
|
fun getIcon(isSelected: Boolean): Icon = Icons.empty
|
||||||
|
|
||||||
|
fun getText(isSelected: Boolean) = toString()
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -94,16 +94,16 @@ class FindEverywhereXList(private val model: DefaultListModel<FindEverywhereResu
|
|||||||
label.font = font.deriveFont(font.size - 2f)
|
label.font = font.deriveFont(font.size - 2f)
|
||||||
val box = Box.createHorizontalBox()
|
val box = Box.createHorizontalBox()
|
||||||
box.add(label)
|
box.add(label)
|
||||||
/*box.add(object : JComponent() {
|
|
||||||
override fun paintComponent(g: Graphics) {
|
|
||||||
g.color = DynamicColor.BorderColor
|
|
||||||
g.drawLine(10, height / 2, width, height / 2)
|
|
||||||
}
|
|
||||||
})*/
|
|
||||||
return box
|
return box
|
||||||
}
|
}
|
||||||
|
|
||||||
val c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus)
|
val c = super.getListCellRendererComponent(
|
||||||
|
list,
|
||||||
|
if (value is FindEverywhereResult) value.getText(isSelected) else value,
|
||||||
|
index,
|
||||||
|
isSelected,
|
||||||
|
cellHasFocus
|
||||||
|
)
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
background = UIManager.getColor("List.selectionBackground")
|
background = UIManager.getColor("List.selectionBackground")
|
||||||
foreground = UIManager.getColor("List.selectionForeground")
|
foreground = UIManager.getColor("List.selectionForeground")
|
||||||
|
|||||||
Reference in New Issue
Block a user