windowmenubar
(and filemenubar
and globalmenubar
) are behaving strangely when creating a custom context menu. This works as expected to generate a custom menu when right-clicking on the data sheet:
windowmenubar "",menu("Context")+
menuitem("One","CODE","message '1'")+
menuitem("Two","CODE","message '2'")+
menuitem("Three","CODE","message '3'"),
"DATA_CONTEXTMENU"
but if I put the result of that menu-generating expression into a variable and use that as the second parameter of windowmenubar
it no longer works — no context menu appears when right-clicked:
let ThisMenu=menu("Context")+
menuitem("One","CODE","message '1'")+
menuitem("Two","CODE","message '2'")+
menuitem("Three","CODE","message '3'")
windowmenubar "",ThisMenu,"DATA_CONTEXTMENU"
If I replace the expression with the equivalent LMSL text, in each case the result is unchanged.
However, to create a new menu-bar menu, both of those approaches work:
windowmenubar "basic",menu("New menu")+
menuitem("One","CODE","message '1'")+
menuitem("Two","CODE","message '2'")+
menuitem("Three","CODE","message '3'"),
"DATA_MENUBAR"
and
let ThisMenu=menu("New menu")+
menuitem("One","CODE","message '1'")+
menuitem("Two","CODE","message '2'")+
menuitem("Three","CODE","message '3'")
windowmenubar "basic",ThisMenu,"DATA_MENUBAR"
And both also work with ,"DATA_MENUBAR"
omitted, as they should.
So why does generating as menu-bar menu work, but not a context menu, when the menu is held in a variable?
Incidentally, the help text for menuitem(
states: ‘If the menu is installed in the main menu bar (at the top of the screen), the default action is to call the .CustomMenu
procedure in the current database. . . . If the menu is a context menu (right click) the default is to invoke the ContextMenuAction
statement . . .’ As far as I can see there is no contextmenuaction
statement, and I’m not sure what it would mean in this context to invoke it. I thought it might mean that the default is to call a .ContextMenuAction
procedure instead, but that doesn’t seem to happen either. That is why my menus above include explicit code for each menu option, otherwise I can’t see how a custom context menu can do anything useful. Or am I missing something obvious?