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