Page 1 of 2
doMenu not finding the menu
Posted: Tue Mar 27, 2018 8:48 pm
by rumplestiltskin
This is confusing.
I have a menu named "Maintenance" with an item named "Backup". When I select that item from the menu, the handler does what it should.
However, when I call that menu item using
Code: Select all
doMenu "Backup" of menu "Maintenance"
from menuitem "Quit" of menu "File", I get this error:
button "File": execution error at line 18 (Handler: can't find handler) near "of", char 17
Here's a screenshot of the menubuilder:
Everything is happening from the stack that contains the menubar.
Ideas welcomed. Thanks,
Barry
Re: doMenu not finding the menu
Posted: Tue Mar 27, 2018 9:21 pm
by dunbarx
Hi,
There are threads that speak to this. "DoMenu" was really maintained to try to keep older HC stacks from breaking. But the command is not fully supported. Sometimes it works, and sometimes it does not.
I will find a recent thread on this very subject and post it.
Bottom line, you cannot trust it unless you know it will work. I never use it, and I am an old HC'er.
Craig Newman
Re: doMenu not finding the menu
Posted: Tue Mar 27, 2018 9:27 pm
by rumplestiltskin
So how would one call a menu item?
Or should I take that menu item's handler and put it into the stack? Then wherever that handler is called (from any other menu item or a button or whatever in that stack) it should work?
Thanks!
Re: doMenu not finding the menu
Posted: Tue Mar 27, 2018 9:42 pm
by dunbarx
Hi.
http://forums.livecode.com/viewtopic.ph ... rge+domenu
Read this thread. It has a happy ending, in that one may invoke a menuItem without using the "doMenu" command. It all stems from my favorite attribute of LC; everything is a stack in the IDE.
Craig
Re: doMenu not finding the menu
Posted: Tue Mar 27, 2018 10:18 pm
by rumplestiltskin
Tried this:
Code: Select all
send "menuPick" && "Backup" to btn "Maintenance" of stack "List Management"
...but nothing happened. No errors and, when I called it from the multi-line message box along with "put the result", there was no result.
I checked using this:
Code: Select all
put there is an item "Backup" of btn "Maintenance" of stack "List Management"
...and that returned 'true' so, while the objects exist, my syntax isn't correct in some manner.
Re: doMenu not finding the menu
Posted: Tue Mar 27, 2018 10:52 pm
by rumplestiltskin
I've moved the Backup handler to be a stack script so the menu item "Backup" simply calls that handler. From the File menu item (Quit) that needs to call the Backup procedure before quitting, I just used the handler name rather than calling the Backup menu item (with the process failing) and it worked fine. Well, that's a simple solution and I think I'll implement that for the rest of the menu items (make stack handlers of them).
Barry
Re: doMenu not finding the menu
Posted: Wed Mar 28, 2018 1:11 am
by dunbarx
The menus are essentially pulldown style buttons in a group. It needs to take the same form as you would in any standard menu button in a stack. Try this, assuming the card inspector is not already open, in a button somewhere:
Code: Select all
on mouseUp
send "menuPick" && "Card inspector" to btn "Object" of stack "revMenubar"
end mouseUp
You could make a general purpose plugin called "newDoMenu", where you create a command by parsing the essential pieces:
newDoMenu "Card Inspector"
HC would find, all by itself, the appropriate menu that contained the menuItem of interest. In LC, you have to know, or at least loop through all buttons until you find the right one, and go from there.
Craig
Re: doMenu not finding the menu
Posted: Wed Mar 28, 2018 1:18 am
by rumplestiltskin
Craig,
I am wondering whether we are referring to slightly different things. Your example (which I tested and works as expected) is calling a menu item in the Livecode IDE. My example (which I tested and does not work) is calling a menu item in a menubar I created for my stack using the menu builder. You might think they are the same (and, indeed, I was thinking that) but, in the real world, they exhibit different behavior.
Re: doMenu not finding the menu
Posted: Wed Mar 28, 2018 1:40 am
by FourthWorld
How do they differ?
Re: doMenu not finding the menu
Posted: Wed Mar 28, 2018 1:58 am
by dunbarx
I would not think they could be different at all. All are built in the same way.
In fact, I miss HC, where a menuBar was its own object class, and was far simpler to create and manage.
But in LC, I think, there is only one way to make a menubar, and since the IDE is composed entirely of stacks, no way to it could be a fundamentally different one.
I could be wrong, of course.
Craig
Re: doMenu not finding the menu
Posted: Wed Mar 28, 2018 3:52 am
by rumplestiltskin
FourthWorld wrote: ↑Wed Mar 28, 2018 1:40 am
How do they differ?
Well, I was talking about the results. Calling the LC IDE menu seems to work. Calling my menu does not.
Tried this:
Code: Select all
send "menuPick" && "Backup" to btn "Maintenance" of stack "List Management"
...but nothing happened. No errors and, when I called it from the multi-line message box along with "put the result", there was no result.
I checked using this:
Code: Select all
put there is an item "Backup" of btn "Maintenance" of stack "List Management"
...and that returned 'true' so, while the objects exist, my syntax isn't correct in some manner.
I'm using the suggested syntax so something is still awry.

Re: doMenu not finding the menu
Posted: Wed Mar 28, 2018 4:34 am
by bogs
rumplestiltskin wrote: ↑Wed Mar 28, 2018 3:52 am
FourthWorld wrote: ↑Wed Mar 28, 2018 1:40 am
How do they differ?
Well, I was talking about the results. Calling the LC IDE menu seems to work. Calling my menu does not.
...I'm using the suggested syntax so something is still awry.
Something indeed is strange there, I popped open Lc, made a simple card and a single button. I made a menu using the menu builder, which I even had auto-script the file menu. Then I literally copied the script from Craig's post, changing only the names in the target path. It worked here, see for yourself.
Code: Select all
// code in button...
on mouseUp
send "menuPick" && "Open" to btn "File" of stack "testMenuButton"
end mouseUp
// code in menu "open" item, removed blank entries...
--The following menuPick handler was generated by the Menu Builder.
on menuPick pWhich
switch pWhich
case "Open"
--Insert script for Open menu item here
answer "open sent"
break
end switch
end menuPick
Clicked the button and presto -0
All I can suggest is try a simple easy thing like this. If it works on something like this, then the mistake is in your code, somewhere.
Re: doMenu not finding the menu
Posted: Wed Mar 28, 2018 11:54 am
by Klaus
Hi friends,
"doMenu" is SOOOOO 90s and should not be used anymore in favour of a modern programming concept!
Instead of having something like this in your menu(s):
Code: Select all
on meupick tPickedItem
switch tItem
case "Backup"
do this...
do that...
get that...
set that one over there...
etc.
etc...
break
case "wahtever"...
...
Put this into the stack script:
Code: Select all
command mybackuphandler
do this...
do that...
get that...
set that one over there...
etc.
etc...
end mybackuphandler
Then you have a clean and easily manageable menu like:
Code: Select all
on meupick tPickedItem
switch tItem
case "Backup"
mybackuphandler
break
case "wahtever"...
...
And you can use it hasslefree in any button:
Code: Select all
on mouseup
mybackuphandler
end mouseup
You get the picture.
Best
Klaus
Re: doMenu not finding the menu
Posted: Wed Mar 28, 2018 3:29 pm
by dunbarx
Klaus.
Get with it, man.
"doMenu" is soooo 80's.
Craig
Re: doMenu not finding the menu
Posted: Wed Mar 28, 2018 5:02 pm
by Klaus
Ah, uh, oh, OK, sorry, got my first computer (Mac LC I) in 1993!
