mirror of
https://github.com/TermoraDev/termora.git
synced 2026-01-16 02:12:58 +08:00
chore: FindEverywhere using extension
This commit is contained in:
@@ -2,7 +2,6 @@ package app.termora
|
||||
|
||||
import org.apache.commons.codec.digest.MurmurHash3
|
||||
import java.awt.Color
|
||||
import kotlin.math.absoluteValue
|
||||
|
||||
object ColorHash {
|
||||
fun hash(text: String): Color {
|
||||
|
||||
@@ -6,7 +6,9 @@ import app.termora.database.DatabaseChangedExtension
|
||||
import app.termora.database.DatabaseManager
|
||||
import app.termora.findeverywhere.BasicFilterFindEverywhereProvider
|
||||
import app.termora.findeverywhere.FindEverywhereProvider
|
||||
import app.termora.findeverywhere.FindEverywhereProviderExtension
|
||||
import app.termora.findeverywhere.FindEverywhereResult
|
||||
import app.termora.plugin.internal.extension.DynamicExtensionHandler
|
||||
import app.termora.plugin.internal.sftppty.SFTPPtyProtocolProvider
|
||||
import app.termora.plugin.internal.sftppty.SFTPPtyTerminalTab
|
||||
import app.termora.plugin.internal.ssh.SSHProtocolProvider
|
||||
@@ -71,6 +73,8 @@ class TerminalTabbed(
|
||||
|
||||
|
||||
private fun initEvents() {
|
||||
Disposer.register(this, customizeToolBarAWTEventListener)
|
||||
|
||||
// 关闭 tab
|
||||
tabbedPane.setTabCloseCallback { _, i -> removeTabAt(i, true) }
|
||||
|
||||
@@ -119,10 +123,13 @@ class TerminalTabbed(
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
// 注册全局搜索
|
||||
FindEverywhereProvider.getFindEverywhereProviders(windowScope)
|
||||
.add(BasicFilterFindEverywhereProvider(object : FindEverywhereProvider {
|
||||
override fun find(pattern: String): List<FindEverywhereResult> {
|
||||
DynamicExtensionHandler.getInstance()
|
||||
.register(FindEverywhereProviderExtension::class.java, object : FindEverywhereProviderExtension {
|
||||
val provider = BasicFilterFindEverywhereProvider(object : FindEverywhereProvider {
|
||||
override fun find(pattern: String, scope: Scope): List<FindEverywhereResult> {
|
||||
if (scope != windowScope) return emptyList()
|
||||
val results = mutableListOf<FindEverywhereResult>()
|
||||
for (i in 0 until tabbedPane.tabCount) {
|
||||
val c = tabbedPane.getComponentAt(i)
|
||||
@@ -147,8 +154,12 @@ class TerminalTabbed(
|
||||
override fun order(): Int {
|
||||
return Integer.MIN_VALUE + 1
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
override fun getFindEverywhereProvider(): FindEverywhereProvider {
|
||||
return provider
|
||||
}
|
||||
}).let { Disposer.register(this, it) }
|
||||
|
||||
// 监听全局事件
|
||||
toolkit.addAWTEventListener(customizeToolBarAWTEventListener, AWTEvent.MOUSE_EVENT_MASK)
|
||||
@@ -411,10 +422,6 @@ class TerminalTabbed(
|
||||
* 对着 ToolBar 右键
|
||||
*/
|
||||
private inner class CustomizeToolBarAWTEventListener : AWTEventListener, Disposable {
|
||||
init {
|
||||
Disposer.register(this@TerminalTabbed, this)
|
||||
}
|
||||
|
||||
override fun eventDispatched(event: AWTEvent) {
|
||||
if (event !is MouseEvent || event.id != MouseEvent.MOUSE_CLICKED || !SwingUtilities.isRightMouseButton(event)) return
|
||||
// 如果 ToolBar 没有显示
|
||||
|
||||
@@ -4,7 +4,9 @@ package app.termora
|
||||
import app.termora.actions.*
|
||||
import app.termora.database.DatabaseManager
|
||||
import app.termora.findeverywhere.FindEverywhereProvider
|
||||
import app.termora.findeverywhere.FindEverywhereProviderExtension
|
||||
import app.termora.findeverywhere.FindEverywhereResult
|
||||
import app.termora.plugin.internal.extension.DynamicExtensionHandler
|
||||
import app.termora.plugin.internal.ssh.SSHProtocolProvider
|
||||
import app.termora.terminal.DataKey
|
||||
import app.termora.tree.*
|
||||
@@ -183,9 +185,32 @@ class WelcomePanel(private val windowScope: WindowScope) : JPanel(BorderLayout()
|
||||
|
||||
})
|
||||
|
||||
searchTextField.addKeyListener(object : KeyAdapter() {
|
||||
private val event = ActionEvent(hostTree, ActionEvent.ACTION_PERFORMED, StringUtils.EMPTY)
|
||||
private val openHostAction get() = ActionManager.getInstance().getAction(OpenHostAction.OPEN_HOST)
|
||||
|
||||
override fun keyPressed(e: KeyEvent) {
|
||||
if (e.keyCode == KeyEvent.VK_DOWN || e.keyCode == KeyEvent.VK_ENTER || e.keyCode == KeyEvent.VK_UP) {
|
||||
when (e.keyCode) {
|
||||
KeyEvent.VK_UP -> hostTree.actionMap.get("selectPrevious")?.actionPerformed(event)
|
||||
KeyEvent.VK_DOWN -> hostTree.actionMap.get("selectNext")?.actionPerformed(event)
|
||||
else -> {
|
||||
for (node in hostTree.getSelectionSimpleTreeNodes(true)) {
|
||||
openHostAction?.actionPerformed(OpenHostActionEvent(hostTree, node.host, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
e.consume()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
DynamicExtensionHandler.getInstance()
|
||||
.register(FindEverywhereProviderExtension::class.java, object : FindEverywhereProviderExtension {
|
||||
private val provider = object : FindEverywhereProvider {
|
||||
override fun find(pattern: String, scope: Scope): List<FindEverywhereResult> {
|
||||
if (scope != windowScope) return emptyList()
|
||||
|
||||
FindEverywhereProvider.getFindEverywhereProviders(windowScope).add(object : FindEverywhereProvider {
|
||||
override fun find(pattern: String): List<FindEverywhereResult> {
|
||||
var filter = hostTreeModel.root.getAllChildren()
|
||||
.map { it.host }
|
||||
.filter { it.isFolder.not() }
|
||||
@@ -210,27 +235,14 @@ class WelcomePanel(private val windowScope: WindowScope) : JPanel(BorderLayout()
|
||||
override fun order(): Int {
|
||||
return Integer.MIN_VALUE + 2
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
searchTextField.addKeyListener(object : KeyAdapter() {
|
||||
private val event = ActionEvent(hostTree, ActionEvent.ACTION_PERFORMED, StringUtils.EMPTY)
|
||||
private val openHostAction get() = ActionManager.getInstance().getAction(OpenHostAction.OPEN_HOST)
|
||||
override fun getFindEverywhereProvider(): FindEverywhereProvider {
|
||||
return provider
|
||||
}
|
||||
|
||||
}).let { Disposer.register(this, it) }
|
||||
|
||||
override fun keyPressed(e: KeyEvent) {
|
||||
if (e.keyCode == KeyEvent.VK_DOWN || e.keyCode == KeyEvent.VK_ENTER || e.keyCode == KeyEvent.VK_UP) {
|
||||
when (e.keyCode) {
|
||||
KeyEvent.VK_UP -> hostTree.actionMap.get("selectPrevious")?.actionPerformed(event)
|
||||
KeyEvent.VK_DOWN -> hostTree.actionMap.get("selectNext")?.actionPerformed(event)
|
||||
else -> {
|
||||
for (node in hostTree.getSelectionSimpleTreeNodes(true)) {
|
||||
openHostAction?.actionPerformed(OpenHostActionEvent(hostTree, node.host, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
e.consume()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun perform() {
|
||||
|
||||
@@ -17,7 +17,6 @@ import okhttp3.Response
|
||||
import okio.withLock
|
||||
import org.apache.commons.codec.binary.Base64
|
||||
import org.apache.commons.io.IOUtils
|
||||
import org.apache.commons.lang3.SystemUtils
|
||||
import org.apache.commons.lang3.time.DateUtils
|
||||
import org.apache.commons.net.util.SubnetUtils
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package app.termora.findeverywhere
|
||||
|
||||
import app.termora.Scope
|
||||
|
||||
class BasicFilterFindEverywhereProvider(private val provider: FindEverywhereProvider) : FindEverywhereProvider {
|
||||
override fun find(pattern: String): List<FindEverywhereResult> {
|
||||
val results = provider.find(pattern)
|
||||
override fun find(pattern: String, scope: Scope): List<FindEverywhereResult> {
|
||||
val results = provider.find(pattern, scope)
|
||||
if (pattern.isBlank()) {
|
||||
return results
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import javax.swing.*
|
||||
import javax.swing.event.DocumentEvent
|
||||
import javax.swing.event.DocumentListener
|
||||
|
||||
class FindEverywhere(owner: Window, windowScope: WindowScope) : DialogWrapper(owner) {
|
||||
class FindEverywhere(owner: Window, private val windowScope: WindowScope) : DialogWrapper(owner) {
|
||||
private val searchTextField = FlatTextField()
|
||||
private val model = DefaultListModel<FindEverywhereResult>()
|
||||
private val resultList = FindEverywhereXList(model)
|
||||
@@ -82,7 +82,7 @@ class FindEverywhere(owner: Window, windowScope: WindowScope) : DialogWrapper(ow
|
||||
val map = linkedMapOf<String, MutableList<FindEverywhereResult>>()
|
||||
|
||||
for (provider in providers) {
|
||||
val results = provider.find(text)
|
||||
val results = provider.find(text, windowScope)
|
||||
if (results.isEmpty()) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ class FindEverywhereAction : AnAction(StringUtils.EMPTY, Icons.find) {
|
||||
}
|
||||
|
||||
val dialog = FindEverywhere(owner, scope)
|
||||
for (provider in FindEverywhereProvider.getFindEverywhereProviders(scope)) {
|
||||
for (provider in FindEverywhereProvider.getFindEverywhereProviders()) {
|
||||
dialog.registerProvider(provider)
|
||||
}
|
||||
dialog.setLocationRelativeTo(owner)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package app.termora.findeverywhere
|
||||
|
||||
import app.termora.Scope
|
||||
import app.termora.plugin.ExtensionManager
|
||||
|
||||
interface FindEverywhereProvider {
|
||||
|
||||
@@ -8,21 +9,16 @@ interface FindEverywhereProvider {
|
||||
|
||||
const val SKIP_FIND_EVERYWHERE = "SKIP_FIND_EVERYWHERE"
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun getFindEverywhereProviders(scope: Scope): MutableList<FindEverywhereProvider> {
|
||||
var list = scope.getAnyOrNull("FindEverywhereProviders")
|
||||
if (list == null) {
|
||||
list = mutableListOf<FindEverywhereProvider>()
|
||||
scope.putAny("FindEverywhereProviders", list)
|
||||
}
|
||||
return list as MutableList<FindEverywhereProvider>
|
||||
fun getFindEverywhereProviders(): List<FindEverywhereProvider> {
|
||||
return ExtensionManager.getInstance().getExtensions(FindEverywhereProviderExtension::class.java)
|
||||
.map { it.getFindEverywhereProvider() }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索
|
||||
*/
|
||||
fun find(pattern: String): List<FindEverywhereResult>
|
||||
fun find(pattern: String, scope: Scope): List<FindEverywhereResult>
|
||||
|
||||
/**
|
||||
* 如果返回非空,表示单独分组
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package app.termora.findeverywhere
|
||||
|
||||
import app.termora.plugin.Extension
|
||||
|
||||
interface FindEverywhereProviderExtension : Extension {
|
||||
fun getFindEverywhereProvider(): FindEverywhereProvider
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package app.termora.findeverywhere
|
||||
|
||||
import app.termora.Actions
|
||||
import app.termora.I18n
|
||||
import app.termora.Scope
|
||||
import app.termora.WindowScope
|
||||
import app.termora.actions.MultipleAction
|
||||
|
||||
@@ -14,7 +15,8 @@ class QuickActionsFindEverywhereProvider(private val windowScope: WindowScope) :
|
||||
MultipleAction.MULTIPLE,
|
||||
)
|
||||
|
||||
override fun find(pattern: String): List<FindEverywhereResult> {
|
||||
override fun find(pattern: String, scope: Scope): List<FindEverywhereResult> {
|
||||
if (scope != windowScope) return emptyList()
|
||||
val actionManager = ActionManager.getInstance()
|
||||
val results = ArrayList<FindEverywhereResult>()
|
||||
for (action in actions) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package app.termora.findeverywhere
|
||||
import app.termora.Actions
|
||||
import app.termora.I18n
|
||||
import app.termora.Icons
|
||||
import app.termora.Scope
|
||||
import app.termora.actions.NewHostAction
|
||||
import app.termora.actions.OpenLocalTerminalAction
|
||||
import app.termora.snippet.SnippetAction
|
||||
@@ -13,7 +14,7 @@ import javax.swing.Icon
|
||||
class QuickCommandFindEverywhereProvider : FindEverywhereProvider {
|
||||
private val actionManager get() = ActionManager.getInstance()
|
||||
|
||||
override fun find(pattern: String): List<FindEverywhereResult> {
|
||||
override fun find(pattern: String, scope: Scope): List<FindEverywhereResult> {
|
||||
val list = mutableListOf<FindEverywhereResult>()
|
||||
actionManager.let { list.add(CreateHostFindEverywhereResult()) }
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package app.termora.findeverywhere
|
||||
|
||||
import app.termora.I18n
|
||||
import app.termora.Scope
|
||||
|
||||
class SettingsFindEverywhereProvider : FindEverywhereProvider {
|
||||
|
||||
|
||||
override fun find(pattern: String): List<FindEverywhereResult> {
|
||||
override fun find(pattern: String, scope: Scope): List<FindEverywhereResult> {
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package app.termora.macro
|
||||
import app.termora.Actions
|
||||
import app.termora.ApplicationScope
|
||||
import app.termora.I18n
|
||||
import app.termora.Scope
|
||||
import app.termora.actions.AnAction
|
||||
import app.termora.findeverywhere.ActionFindEverywhereResult
|
||||
import app.termora.findeverywhere.FindEverywhereProvider
|
||||
@@ -16,7 +17,7 @@ import kotlin.math.min
|
||||
class MacroFindEverywhereProvider : FindEverywhereProvider {
|
||||
private val macroManager get() = MacroManager.getInstance()
|
||||
|
||||
override fun find(pattern: String): List<FindEverywhereResult> {
|
||||
override fun find(pattern: String, scope: Scope): List<FindEverywhereResult> {
|
||||
val macroAction = ActionManager.getInstance().getAction(Actions.MACRO) ?: return emptyList()
|
||||
if (macroAction !is MacroAction) return emptyList()
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ import java.io.File
|
||||
import java.net.URL
|
||||
import java.net.URLClassLoader
|
||||
import java.util.*
|
||||
import kotlin.math.cos
|
||||
|
||||
internal class PluginManager private constructor() {
|
||||
companion object {
|
||||
|
||||
@@ -11,7 +11,6 @@ import org.apache.commons.lang3.StringUtils
|
||||
import java.awt.BorderLayout
|
||||
import java.awt.Component
|
||||
import java.awt.KeyboardFocusManager
|
||||
import java.awt.SystemColor.desktop
|
||||
import java.awt.Window
|
||||
import java.awt.event.ComponentAdapter
|
||||
import java.awt.event.ComponentEvent
|
||||
|
||||
Reference in New Issue
Block a user