This commit is contained in:
downthecrop 2025-10-26 22:33:02 -07:00
parent 440b8d4de1
commit 6adc5135bc
4 changed files with 52 additions and 123 deletions

View file

@ -5,6 +5,7 @@ import KondoKit.components.*
import KondoKit.ViewConstants
import KondoKit.views.ViewLayoutHelpers.createSearchFieldSection
import KondoKit.setFixedSize
import KondoKit.attachPopupMenu
import KondoKit.ReflectiveEditorPlugin
import KondoKit.pluginmanager.GitLabPlugin
import KondoKit.pluginmanager.GitLabPluginFetcher
@ -22,8 +23,6 @@ import plugin.PluginInfo
import plugin.PluginRepository
import rt4.GlobalJsonConfig
import java.awt.*
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import java.io.File
import java.util.*
import javax.swing.*
@ -274,15 +273,7 @@ object ReflectiveEditorView : View {
}
private fun createPluginItemPanel(pluginInfo: PluginInfo, plugin: Plugin): JPanel {
val panel = WidgetPanel(
widgetWidth = ViewConstants.PLUGIN_LIST_ITEM_SIZE.width,
widgetHeight = ViewConstants.PLUGIN_LIST_ITEM_SIZE.height,
paddingLeft = 10,
paddingRight = 10,
paddingTop = 10,
paddingBottom = 10,
addDefaultPadding = false
).apply {
val panel = createPluginWidgetPanel().apply {
layout = BorderLayout()
}
@ -336,22 +327,14 @@ object ReflectiveEditorView : View {
if (!isKondoKit(packageName)) {
val popupMenu = createPluginContextMenu(plugin, pluginInfo, packageName, false)
addContextMenuToPanel(panel, popupMenu)
panel.attachPopupMenu(popupMenu)
}
return panel
}
private fun createDisabledPluginItemPanel(pluginName: String): JPanel {
val panel = WidgetPanel(
widgetWidth = ViewConstants.PLUGIN_LIST_ITEM_SIZE.width,
widgetHeight = ViewConstants.PLUGIN_LIST_ITEM_SIZE.height,
paddingLeft = 10,
paddingRight = 10,
paddingTop = 10,
paddingBottom = 10,
addDefaultPadding = false
).apply {
val panel = createPluginWidgetPanel().apply {
layout = BorderLayout()
}
@ -388,22 +371,14 @@ object ReflectiveEditorView : View {
// Add right-click context menu (except for KondoKit itself)
if (!isKondoKit(pluginName)) {
val popupMenu = createPluginContextMenu(null, null, pluginName, true)
addContextMenuToPanel(panel, popupMenu)
panel.attachPopupMenu(popupMenu)
}
return panel
}
private fun createPluginStatusItemPanel(pluginStatus: PluginInfoWithStatus): JPanel {
val panel = WidgetPanel(
widgetWidth = ViewConstants.PLUGIN_LIST_ITEM_SIZE.width,
widgetHeight = ViewConstants.PLUGIN_LIST_ITEM_SIZE.height,
paddingLeft = 10,
paddingRight = 10,
paddingTop = 10,
paddingBottom = 10,
addDefaultPadding = false
).apply {
val panel = createPluginWidgetPanel().apply {
layout = BorderLayout()
}
@ -557,12 +532,24 @@ object ReflectiveEditorView : View {
if (!isKondoKit(pluginStatus.name) && pluginStatus.isInstalled) {
val popupMenu = createPluginContextMenu(null, null, pluginStatus.name, !pluginStatus.needsUpdate)
addContextMenuToPanel(panel, popupMenu)
panel.attachPopupMenu(popupMenu)
}
return panel
}
private fun createPluginWidgetPanel(): WidgetPanel {
return WidgetPanel(
widgetWidth = ViewConstants.PLUGIN_LIST_ITEM_SIZE.width,
widgetHeight = ViewConstants.PLUGIN_LIST_ITEM_SIZE.height,
addDefaultPadding = false,
paddingTop = 10,
paddingLeft = 10,
paddingBottom = 10,
paddingRight = 10
)
}
private fun buildInstallableTooltip(pluginStatus: PluginInfoWithStatus): String {
val lines = mutableListOf<String>()
pluginStatus.remoteVersion?.takeIf { it.isNotBlank() }?.let {
@ -801,24 +788,6 @@ object ReflectiveEditorView : View {
reflectiveEditorPlugin.startPluginDownload(pluginStatus, mainPanel ?: JPanel())
}
// Helper method to add context menu to a panel
private fun addContextMenuToPanel(panel: JPanel, popupMenu: JPopupMenu) {
val rightClickListener = object : MouseAdapter() {
override fun mousePressed(e: MouseEvent) {
if (e.isPopupTrigger) {
popupMenu.show(e.component, e.x, e.y)
}
}
override fun mouseReleased(e: MouseEvent) {
if (e.isPopupTrigger) {
popupMenu.show(e.component, e.x, e.y)
}
}
}
panel.addMouseListener(rightClickListener)
}
// Helper method to create context menu for plugins
private fun createPluginContextMenu(plugin: Plugin?, pluginInfo: PluginInfo?, pluginName: String, isDisabled: Boolean): JPopupMenu {
val popupMenu = PopupMenuComponent()