doMenu not finding the menu

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

rumplestiltskin
Posts: 222
Joined: Wed Jun 21, 2006 7:33 pm
Location: West of the Pecos
Contact:

doMenu not finding the menu

Post by rumplestiltskin » Tue Mar 27, 2018 8:48 pm

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:
Screen Shot 2018-03-27 at 1.43.48 PM.jpg
Everything is happening from the stack that contains the menubar.

Ideas welcomed. Thanks,
Barry

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: doMenu not finding the menu

Post by dunbarx » Tue Mar 27, 2018 9:21 pm

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

rumplestiltskin
Posts: 222
Joined: Wed Jun 21, 2006 7:33 pm
Location: West of the Pecos
Contact:

Re: doMenu not finding the menu

Post by rumplestiltskin » Tue Mar 27, 2018 9:27 pm

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!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: doMenu not finding the menu

Post by dunbarx » Tue Mar 27, 2018 9:42 pm

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

rumplestiltskin
Posts: 222
Joined: Wed Jun 21, 2006 7:33 pm
Location: West of the Pecos
Contact:

Re: doMenu not finding the menu

Post by rumplestiltskin » Tue Mar 27, 2018 10:18 pm

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.

rumplestiltskin
Posts: 222
Joined: Wed Jun 21, 2006 7:33 pm
Location: West of the Pecos
Contact:

Re: doMenu not finding the menu

Post by rumplestiltskin » Tue Mar 27, 2018 10:52 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: doMenu not finding the menu

Post by dunbarx » Wed Mar 28, 2018 1:11 am

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

rumplestiltskin
Posts: 222
Joined: Wed Jun 21, 2006 7:33 pm
Location: West of the Pecos
Contact:

Re: doMenu not finding the menu

Post by rumplestiltskin » Wed Mar 28, 2018 1:18 am

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.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: doMenu not finding the menu

Post by FourthWorld » Wed Mar 28, 2018 1:40 am

How do they differ?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: doMenu not finding the menu

Post by dunbarx » Wed Mar 28, 2018 1:58 am

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

rumplestiltskin
Posts: 222
Joined: Wed Jun 21, 2006 7:33 pm
Location: West of the Pecos
Contact:

Re: doMenu not finding the menu

Post by rumplestiltskin » 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.
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. :(

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: doMenu not finding the menu

Post by bogs » Wed Mar 28, 2018 4:34 am

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
Selection_003.png
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.
Image

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: doMenu not finding the menu

Post by Klaus » Wed Mar 28, 2018 11:54 am

Hi friends,

"doMenu" is SOOOOO 90s and should not be used anymore in favour of a modern programming concept! :D

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. :D


Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: doMenu not finding the menu

Post by dunbarx » Wed Mar 28, 2018 3:29 pm

Klaus.

Get with it, man.

"doMenu" is soooo 80's.

Craig

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: doMenu not finding the menu

Post by Klaus » Wed Mar 28, 2018 5:02 pm

Ah, uh, oh, OK, sorry, got my first computer (Mac LC I) in 1993! 8)

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”