fix: prevent some issues

This commit is contained in:
Johannes Frohnmeyer 2024-07-20 23:16:39 +02:00
parent ab513fb0e9
commit 9f1d36f2b1
Signed by: Johannes
GPG Key ID: E76429612C2929F4
3 changed files with 23 additions and 8 deletions

View File

@ -31,7 +31,7 @@ class DbusmenuImpl(windowId: Long, private val menuHolder: MenuHolder) : Dbusmen
for (sm in it) {
children.add(Variant(getLayout(parentId, recursionDepth, propertyNames, sm)))
}
if (it.isNotEmpty()) properties["children-display"] = Variant("submenu")
properties["children-display"] = Variant("submenu")
}
return GetLayoutStruct(menu.id, properties, children)

View File

@ -88,9 +88,10 @@ class SwingMenu(private val menuItem: JMenuItem?, private val holder: SwingMenuH
ApplicationManager.getApplication().invokeLater {
for (it in menuItem.actionListeners) it.actionPerformed(event)
}
menuItem.doClick()
ApplicationManager.getApplication().invokeLater(menuItem::doClick)
GlobalMenu.Log.warn("Event $event for menu $id (${menuItem.javaClass})")
when (menuItem) {
is ActionMenuItem -> {}
is JCheckBoxMenuItem -> menuItem.isSelected = !menuItem.isSelected
is JRadioButtonMenuItem -> menuItem.isSelected = true
}
@ -127,10 +128,12 @@ class SwingMenu(private val menuItem: JMenuItem?, private val holder: SwingMenuH
}
if (each !is JMenuItem) continue
val cmi = SwingMenu(each, holder)
if (deepness > 1 && each is ActionMenu) {
if (deepness > 1) {
if (each is ActionMenu) {
each.removeAll()
each.isSelected = true
each.fillMenu()
}
cmi.syncChildren(deepness - 1)
}
ch.add(cmi)
@ -142,6 +145,10 @@ class SwingMenu(private val menuItem: JMenuItem?, private val holder: SwingMenuH
}
}
override fun toString(): String {
return "SwingMenu(id=$id, menuItem=$menuItem)"
}
companion object {
val keyEvents: Map<Int, String> = KeyEvent::class.java.fields
.filter { it.modifiers == Modifier.PUBLIC or Modifier.STATIC or Modifier.FINAL && it.name.startsWith("VK_") }

View File

@ -1,6 +1,10 @@
package io.gitlab.jfronny.globalmenu.proxy
import com.intellij.openapi.actionSystem.impl.ActionMenu
import com.intellij.openapi.application.EDT
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import javax.swing.JMenuItem
class SwingRootMenu(private var menuItems: List<JMenuItem>?, private val name: String, private val holder: SwingMenuHolder): Menu {
@ -20,8 +24,12 @@ class SwingRootMenu(private var menuItems: List<JMenuItem>?, private val name: S
}
override fun update() {
runBlocking {
launch(Dispatchers.EDT) {
syncChildren()
}
}
}
fun update(items: List<ActionMenu>) {
menuItems = items
@ -33,6 +41,6 @@ class SwingRootMenu(private var menuItems: List<JMenuItem>?, private val name: S
}
private fun syncChildren() {
_children = menuItems?.map { SwingMenu(it, holder).apply { syncChildren(1) } }
_children = menuItems?.map { SwingMenu(it, holder).apply { syncChildren(2) } }
}
}