fix: prevent some more issues
This commit is contained in:
parent
9f1d36f2b1
commit
b356aa89cd
@ -1,12 +1,9 @@
|
||||
package io.gitlab.jfronny.globalmenu
|
||||
|
||||
import com.canonical.appmenu.Registrar
|
||||
import com.intellij.ide.IdeEventQueue
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.actionSystem.impl.ActionMenu
|
||||
import com.intellij.openapi.application.Application
|
||||
import com.intellij.openapi.application.ApplicationActivationListener
|
||||
import com.intellij.openapi.progress.runBlockingCancellable
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.wm.IdeFrame
|
||||
import com.intellij.openapi.wm.impl.IdeFrameImpl
|
||||
@ -14,16 +11,11 @@ import com.intellij.openapi.wm.impl.ProjectFrameHelper
|
||||
import com.intellij.platform.ide.menu.IdeJMenuBar
|
||||
import io.gitlab.jfronny.globalmenu.proxy.DbusmenuImpl
|
||||
import io.gitlab.jfronny.globalmenu.proxy.SwingMenuHolder
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.freedesktop.dbus.DBusPath
|
||||
import org.freedesktop.dbus.connections.impl.DBusConnection
|
||||
import org.freedesktop.dbus.connections.impl.DBusConnectionBuilder
|
||||
import org.freedesktop.dbus.types.UInt32
|
||||
import java.awt.Window
|
||||
import java.awt.event.KeyEvent
|
||||
import javax.swing.JMenuBar
|
||||
import javax.swing.SwingUtilities
|
||||
|
||||
class GlobalMenuService(private val app: Application) : ApplicationActivationListener {
|
||||
override fun applicationActivated(ideFrame: IdeFrame) {
|
||||
@ -55,7 +47,7 @@ class GlobalMenuService(private val app: Application) : ApplicationActivationLis
|
||||
menu.addUpdateGlobalMenuRootsListener {
|
||||
menuHolder.update(menu.rootMenuItems)
|
||||
}
|
||||
menu.updateMenuActions(true)
|
||||
// menu.updateMenuActions(true)
|
||||
}
|
||||
// IdeEventQueue.getInstance().addDispatcher({ e ->
|
||||
// if (e !is KeyEvent) false
|
||||
|
@ -17,10 +17,15 @@ class DbusmenuImpl(windowId: Long, private val menuHolder: MenuHolder) : Dbusmen
|
||||
// object : Dbusmenu.PropertyIconThemePathType, List<String> by listOf() {}
|
||||
|
||||
override fun GetLayout(parentId: Int, recursionDepth: Int, propertyNames: MutableList<String>?): DPair<UInt32, GetLayoutStruct> {
|
||||
return DPair(
|
||||
UInt32(parentId.toLong()),
|
||||
getLayout(parentId, recursionDepth, propertyNames, menuHolder.find(parentId)!!)
|
||||
)
|
||||
try {
|
||||
return DPair(
|
||||
UInt32(parentId.toUInt().toLong()),
|
||||
getLayout(parentId, recursionDepth, propertyNames, menuHolder.find(parentId)!!)
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
GlobalMenu.Log.error("Failed to get layout for menu $parentId", e)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
private fun getLayout(parentId: Int, recursionDepth: Int, propertyNames: MutableList<String>?, menu: Menu): GetLayoutStruct {
|
||||
@ -80,6 +85,16 @@ class DbusmenuImpl(windowId: Long, private val menuHolder: MenuHolder) : Dbusmen
|
||||
}
|
||||
|
||||
override fun EventGroup(events: MutableList<EventGroupStruct>?): MutableList<Int>? = null // not needed?
|
||||
override fun AboutToShow(id: Int): Boolean = true // not needed?
|
||||
override fun AboutToShow(id: Int): Boolean {
|
||||
GlobalMenu.Log.warn("About to show menu $id")
|
||||
try {
|
||||
menuHolder.find(id)?.update()
|
||||
return true
|
||||
} catch (e: Exception) {
|
||||
GlobalMenu.Log.error("Failed to update menu $id", e)
|
||||
throw e
|
||||
}
|
||||
|
||||
}
|
||||
override fun AboutToShowGroup(ids: MutableList<Int>?): DPair<MutableList<Int>, MutableList<Int>>? = null // not needed?
|
||||
}
|
||||
|
@ -84,14 +84,11 @@ class SwingMenu(private val menuItem: JMenuItem?, private val holder: SwingMenuH
|
||||
override val children: List<Menu>? get() = _children
|
||||
|
||||
override fun onEvent() {
|
||||
val event = ActionEvent(menuItem, ActionEvent.ACTION_PERFORMED, menuItem!!.actionCommand)
|
||||
ApplicationManager.getApplication().invokeLater {
|
||||
for (it in menuItem.actionListeners) it.actionPerformed(event)
|
||||
}
|
||||
if (menuItem == null) return
|
||||
ApplicationManager.getApplication().invokeLater(menuItem::doClick)
|
||||
GlobalMenu.Log.warn("Event $event for menu $id (${menuItem.javaClass})")
|
||||
when (menuItem) {
|
||||
is ActionMenuItem -> {}
|
||||
is ActionMenu -> {}
|
||||
is JCheckBoxMenuItem -> menuItem.isSelected = !menuItem.isSelected
|
||||
is JRadioButtonMenuItem -> menuItem.isSelected = true
|
||||
}
|
||||
@ -116,7 +113,7 @@ class SwingMenu(private val menuItem: JMenuItem?, private val holder: SwingMenuH
|
||||
}
|
||||
|
||||
fun syncChildren(deepness: Int) {
|
||||
GlobalMenu.Log.warn("Syncing children for $label")
|
||||
// GlobalMenu.Log.warn("Syncing children for $label")
|
||||
_children = when (menuItem) {
|
||||
is ActionMenu -> {
|
||||
val ch = mutableListOf<Menu>()
|
||||
|
Loading…
Reference in New Issue
Block a user