There seems to be an issue with menu shortcuts, especially if the menuItems are dynamically created.
Please check out the following example:
Code: Select all
@REQUIRE "RapaGUI", {Link = True}
@APPTITLE "Shortcuts-Test"
Function p_Init()
InstallEventHandler({RapaGUI = p_EventFunc})
moai.DoMethod("menDynamic", "Remove", "menDummy")
moai.FreeObject("menDummy")
moai.CreateObject([[<item id="menE" shortcut="RawCtrl+E">Dynamic Item E</item>]])
moai.CreateObject([[<item id="menF" shortcut="Ctrl+F">Dynamic Item F</item>]])
moai.CreateObject([[<item id="menG" shortcut="Cmd+G">Dynamic Item G</item>]])
moai.CreateObject([[<item id="menH" shortcut="Alt+H">Dynamic Item H</item>]])
moai.DoMethod("menDynamic", "append", "menE")
moai.DoMethod("menDynamic", "append", "menF")
moai.DoMethod("menDynamic", "append", "menG")
moai.DoMethod("menDynamic", "append", "menH")
p_SetInfo("Ctrl")
moai.Set("mainWindow", "activeObject", "btnChangeRawCtrl")
EndFunction
Function p_EventFunc(msg)
; DebugPrint(msg.id)
Switch msg.Class
Case "Menuitem":
moai.Set("ctrlLog", "text", moai.Get("ctrlLog", "text") .. msg.id .. "\n")
Case "Button":
If msg.id = "btnClear"
moai.Set("ctrlLog", "text", "")
ElseIf StartsWith(msg.id, "btnChange")
p_ChangeShortcuts(moai.Get(msg.id, "text"))
EndIf
EndSwitch
EndFunction
Function p_ChangeShortcuts(qualifier)
Local array = { "I", "J", "K", "L" }
For Local i = 0 To ListItems(array)-1
Local id$ = "men" .. array[i]
moai.DoMethod("menSwitch", "Remove", id$)
moai.FreeObject(id$)
moai.CreateObject(FormatStr([[<item id="%s" shortcut="%s+%s">Switchable Item %s</item>]], id$, qualifier, array[i], array[i]))
moai.DoMethod("menSwitch", "append", id$)
Next
p_SetInfo(qualifier)
EndFunction
Function p_SetInfo(qualifier)
Local text$ = ReplaceStr("\27uSwitchable Menu\27n\n%s+I\n%s+J\n%s+K\n%s+L", "%s", qualifier)
moai.Set("ctrlInfo3", "text", text$)
EndFunction
moai.CreateApp([[<?xml version="1.0" encoding="iso-8859-1"?>
<application id="app">
<menubar id="ctrlMenubar">
<menu id="menStatic" title="Static Menu">
<item id="menA" shortcut="RawCtrl+A">Static Item A</item>
<item id="menB" shortcut="Ctrl+B">Static Item B</item>
<item id="menC" shortcut="Cmd+C">Static Item C</item>
<item id="menD" shortcut="Alt+D">Static Item D</item>
</menu>
<menu id="menDynamic" title="Dynamic Menu" >
<item id="menDummy">Dummy</item>
</menu>
<menu id="menSwitch" title="Switchable Menu">
<item id="menI" shortcut="Ctrl+I">Switchable Item I</item>
<item id="menJ" shortcut="Ctrl+J">Switchable Item J</item>
<item id="menK" shortcut="Ctrl+K">Switchable Item K</item>
<item id="menL" shortcut="Ctrl+L">Switchable Item L</item>
</menu>
</menubar>
<window id="mainWindow" menubar="ctrlMenubar" height="500" title="Shortcuts-Test">
<vgroup id="mainGroup">
<hgroup frame="true" frameTitle="Info">
<textview id="ctrlInfo1" styled="true" fixHeight="true" height="120">
\33uStatic Menu\33n\n
RawCtrl+A\n
Ctrl+B\n
Cmd+C\n
Alt+D
</textview>
<textview id="ctrlInfo2" styled="true" fixHeight="true" height="120">
\33uDynamic Menu\33n\n
RawCtrl+E\n
Ctrl+F\n
Cmd+G\n
Alt+H
</textview>
<textview id="ctrlInfo3" styled="true" fixHeight="true" height="120" />
</hgroup>
<hgroup>
<text>Change "Switchable Menu" shortcuts to</text>
<button id="btnChangeRawCtrl">RawCtrl</button>
<button id="btnChangeCtrl">Ctrl</button>
<button id="btnChangeCmd">Cmd</button>
<button id="btnChangeAlt">Alt</button>
</hgroup>
<textview id="ctrlLog" />
<button id="btnClear">Clear</button>
</vgroup>
</window>
</application>]])
p_Init()
Repeat
WaitEvent
Forever
- Static Menu: with items A-D, created statically in the XML, each item has another qualifier key.
- Dynamic Menu: with items E-H, created dynamically at startup, again each item has another qualifier key.
- Switchable Menu: with items I-L, created statically in the XML, but each item has the same qualifier key, which can be changed using the buttons below. Because there's not SETTER for the shortcut (unfortunately), chaning means all items are removed an re-created with the new shortcut.
Playing around with the buttons works fine and the shortcut events are always firing as expected.
On any MUI-based system, though, there are issues:
When trying to do the array from A to L, this is how it looks like. Of course, Ctrl corresponds to the RAmiga key this time (which is a great feature).
- For all items that are generated dynamically, the event double fires.
- There seems to be no key that is mapped to the "Cmd" qualifier. From the docs I would have expected it to be the RAmiga key as well and therefor to be printed as RAmiga shortcut-icon in the menu (it's printed as "Cmd" currently).
- Playing around with the buttons leads to very strange behaviour: sometimes the "old" shortcut is still firing events, sometimes the new shortcut is not only doubling events but firing four times or more. It's even possible to crash Hollywood altogether with a "Software failure" (not just quitting) and that's something that we usually don't see very often (from my experience).
Please have a look into this, for the double firing I already had to implement a workaround in the last release of SonosController, because I wanted different shortcuts for OS 3.x and the other platforms and therefor hat to create the menuItems dynamically.
Cheers,
Michael