Search bar (not fully working)

This commit is contained in:
downthecrop 2025-09-08 01:59:26 -07:00
parent 7cc56d0e53
commit 529f0c22b0
5 changed files with 428 additions and 12 deletions

View file

@ -2,6 +2,10 @@ package KondoKit
import KondoKit.Helpers.convertValue
import KondoKit.Helpers.showToast
import KondoKit.ReflectiveEditorComponents.CustomSearchField
import KondoKit.ReflectiveEditorComponents.GitLabPlugin
import KondoKit.ReflectiveEditorComponents.GitLabPluginFetcher
import KondoKit.ReflectiveEditorComponents.PluginProperties
import KondoKit.plugin.Companion.TITLE_BAR_COLOR
import KondoKit.plugin.Companion.TOOLTIP_BACKGROUND
import KondoKit.plugin.Companion.VIEW_BACKGROUND_COLOR
@ -12,8 +16,8 @@ import plugin.PluginInfo
import plugin.PluginRepository
import rt4.GlobalJsonConfig
import java.awt.*
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import java.awt.datatransfer.DataFlavor
import java.awt.event.*
import java.awt.image.BufferedImage
import java.io.File
import java.util.*
@ -39,6 +43,14 @@ object ReflectiveEditorView {
const val PLUGIN_DETAIL_VIEW = "PLUGIN_DETAIL"
val pluginsDirectory: File = File(GlobalJsonConfig.instance.pluginsFolder)
// GitLab API configuration
private const val GITLAB_ACCESS_TOKEN = "glpat-dE2Cs2e4b32-H7c9oGuS"
private const val GITLAB_PROJECT_ID = "38297322"
private const val GITLAB_BRANCH = "master"
// Store fetched GitLab plugins
private var gitLabPlugins: List<GitLabPlugin> = listOf()
// Store the cog icon to be reused
private var cogIcon: Icon? = null
@ -61,6 +73,9 @@ object ReflectiveEditorView {
private var currentPluginInfo: PluginInfo? = null
private var currentPlugin: Plugin? = null
// Search text for filtering plugins
private var pluginSearchText: String = ""
fun createReflectiveEditorView() {
// Load the cog icon once
loadCogIcon()
@ -89,6 +104,12 @@ object ReflectiveEditorView {
// Show the plugin list view by default
cardLayout.show(mainPanel, PLUGIN_LIST_VIEW)
// Fetch GitLab plugins in the background
GitLabPluginFetcher.fetchGitLabPlugins { plugins ->
gitLabPlugins = plugins
// We'll update the UI when needed
}
}
private fun createPluginListView(): JPanel {
@ -96,6 +117,29 @@ object ReflectiveEditorView {
panel.layout = BoxLayout(panel, BoxLayout.Y_AXIS)
panel.background = VIEW_BACKGROUND_COLOR
// Add search field at the top
val searchField = CustomSearchField(panel) { searchText ->
pluginSearchText = searchText
// Refresh the plugin list to apply filtering
SwingUtilities.invokeLater {
addPlugins(reflectiveEditorView!!)
}
}
val searchFieldWrapper = JPanel().apply {
layout = BoxLayout(this, BoxLayout.X_AXIS)
background = VIEW_BACKGROUND_COLOR
preferredSize = Dimension(230, 30)
maximumSize = preferredSize
minimumSize = preferredSize
alignmentX = Component.CENTER_ALIGNMENT
add(searchField)
}
panel.add(Box.createVerticalStrut(10)) // Spacer
panel.add(searchFieldWrapper)
panel.add(Box.createVerticalStrut(10)) // Spacer
try {
panel.add(Box.createVerticalStrut(10)) // Spacer
val loadedPluginsField = PluginRepository::class.java.getDeclaredField("loadedPlugins")
@ -113,10 +157,14 @@ object ReflectiveEditorView {
}
}
if (exposedFields.isNotEmpty()) {
pluginsWithExposed.add(pluginInfo as PluginInfo to plugin as Plugin)
} else {
pluginsWithoutExposed.add(pluginInfo as PluginInfo to plugin as Plugin)
// Apply search filter
val pluginName = plugin.javaClass.`package`.name
if (pluginSearchText.isBlank() || pluginName.contains(pluginSearchText, ignoreCase = true)) {
if (exposedFields.isNotEmpty()) {
pluginsWithExposed.add(pluginInfo as PluginInfo to plugin as Plugin)
} else {
pluginsWithoutExposed.add(pluginInfo as PluginInfo to plugin as Plugin)
}
}
}
@ -151,16 +199,56 @@ object ReflectiveEditorView {
e.printStackTrace()
}
// Add disabled plugins to the list
// Add disabled plugins to the list (filtered by search text)
val disabledDir = File(pluginsDirectory, "disabled")
if (disabledDir.exists() && disabledDir.isDirectory) {
val disabledPlugins = disabledDir.listFiles { file -> file.isDirectory } ?: arrayOf()
// Add disabled plugins to the list without exposed attributes
// Add disabled plugins to the list without exposed attributes (filtered by search text)
for (pluginDir in disabledPlugins.sortedBy { it.name }) {
val pluginPanel = createDisabledPluginItemPanel(pluginDir.name)
panel.add(pluginPanel)
// Apply search filter
if (pluginSearchText.isBlank() || pluginDir.name.contains(pluginSearchText, ignoreCase = true)) {
val pluginPanel = createDisabledPluginItemPanel(pluginDir.name)
panel.add(pluginPanel)
panel.add(Box.createVerticalStrut(5))
}
}
}
// Add a section for available plugins from GitLab that are not installed
if (pluginSearchText.isNotBlank()) {
val matchingGitLabPlugins = gitLabPlugins.filter { plugin ->
plugin.pluginProperties != null &&
(plugin.path.contains(pluginSearchText, ignoreCase = true) ||
plugin.pluginProperties!!.description.contains(pluginSearchText, ignoreCase = true))
}
if (matchingGitLabPlugins.isNotEmpty()) {
// Add a separator
val separator = JPanel()
separator.background = VIEW_BACKGROUND_COLOR
separator.preferredSize = Dimension(Int.MAX_VALUE, 1)
separator.maximumSize = Dimension(Int.MAX_VALUE, 1)
panel.add(Box.createVerticalStrut(10))
panel.add(separator)
panel.add(Box.createVerticalStrut(5))
// Add a header for available plugins
val headerPanel = JPanel(FlowLayout(FlowLayout.LEFT))
headerPanel.background = VIEW_BACKGROUND_COLOR
val headerLabel = JLabel("Available Plugins")
headerLabel.foreground = secondaryColor
headerLabel.font = Font("RuneScape Small", Font.BOLD, 16)
headerPanel.add(headerLabel)
panel.add(headerPanel)
panel.add(Box.createVerticalStrut(5))
// Add matching GitLab plugins
for (gitLabPlugin in matchingGitLabPlugins) {
val pluginPanel = createGitLabPluginItemPanel(gitLabPlugin)
panel.add(pluginPanel)
panel.add(Box.createVerticalStrut(5))
}
}
}
@ -280,6 +368,48 @@ object ReflectiveEditorView {
return panel
}
private fun createGitLabPluginItemPanel(gitLabPlugin: GitLabPlugin): JPanel {
val panel = JPanel(BorderLayout())
panel.background = WIDGET_COLOR
panel.border = BorderFactory.createEmptyBorder(10, 10, 10, 10)
panel.maximumSize = Dimension(220, 60)
// Plugin name
val nameLabel = JLabel(gitLabPlugin.path)
nameLabel.foreground = secondaryColor
nameLabel.font = Font("RuneScape Small", Font.PLAIN, 16)
// Download button (placeholder for now)
val downloadButton = JButton("Download")
downloadButton.background = TITLE_BAR_COLOR
downloadButton.foreground = secondaryColor
downloadButton.font = Font("RuneScape Small", Font.PLAIN, 14)
downloadButton.addActionListener {
// TODO: Implement download functionality
showToast(mainPanel, "Download functionality not yet implemented", JOptionPane.INFORMATION_MESSAGE)
}
// Plugin toggle switch (iOS style) - initially off for GitLab plugins
val toggleSwitch = ToggleSwitch()
toggleSwitch.setActivated(false)
toggleSwitch.isEnabled = false // Disable toggle for GitLab plugins until downloaded
// Layout
val infoPanel = JPanel(BorderLayout())
infoPanel.background = WIDGET_COLOR
infoPanel.add(nameLabel, BorderLayout.WEST)
val controlsPanel = JPanel(FlowLayout(FlowLayout.RIGHT, 5, 0))
controlsPanel.background = WIDGET_COLOR
controlsPanel.add(downloadButton)
controlsPanel.add(toggleSwitch)
panel.add(infoPanel, BorderLayout.CENTER)
panel.add(controlsPanel, BorderLayout.EAST)
return panel
}
private fun enablePlugin(pluginName: String) {
try {
// Source and destination directories