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:

Re: doMenu not finding the menu

Post by rumplestiltskin » Wed Mar 28, 2018 5:56 pm

Klaus wrote:
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
Klaus.

Get with it, man.

"doMenu" is soooo 80's.

Craig
100% in agreement. I remember buying HyperCard at a local store when it was first released ($79? 1987? - before Apple bundled it with all Macs) and wrote two "apps" for my company - one was an intraoffice messaging system (this was before eMail was common) and the other was a labor estimation app based upon Time-Motion studies in the sewing industry. That's why I dabble in Livecode; I'd like to reproduce my labor estimation app in LC (eventually).

In an earlier post in this thread I wrote:
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).
...so I arrived at Klaus' recommendation after it became obvious that doing so would permit me to call script handlers from the menus -and- make things much easier to code and debug.

Thanks to all,
Barry

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 6:14 pm

In a sense Klaus' suggestion is quite similar to what we used to have to do in HyperCard. HC had no menu objects, so everything related to menus had to be instantiated dynamically from long tedious scripts to make each item, hide the HC menus we didn't want showing, and set the menuMessage of each item.

That last part is similar here: since HC had no menu objects we had no place to put the scripts they triggered. They had to be in the card or stack (or perhaps a library).

LC offers a nice mid-point between HC's complete absence of a true menu object and SuperCard's menubar, menu, and menu item objects. SC had true objects for even items in menus, with persistent properties for things like shortcuts, their own script space, etc. But as distinct objects they were slow to work with.

LC has a menubar object (like SC), a menu object (like SC), but the items within it are a text list (like HC). Having spent many years with all three, I find this middle ground to be a good balance of the flexibility of expressing menu items as text lists with the easy dev workflow of having things expressed persistently in objects.

As an app grows, sooner or later a context menu becomes useful. That's when centralizing menu handling as Klaus suggested becomes especially useful: you can have either a menubar menu or a context menu trigger the same script.

As you get more into that habit you may find that the role of menus as the central place for action triggers within an app lends itself very well to being handled in a library, where all of your application's business logic can reside.

And to keep clarity in your internal API while maintaining readability for the user, you can set the menuMessage of an item to any arbitrary handler name. This was originally implemented to help with localization, but the more you work with menu handling as generic triggers for business logic the more the menuMessage becomes useful as a means of making clearer code flow.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7214
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: doMenu not finding the menu

Post by jacque » Wed Mar 28, 2018 6:23 pm

rumplestiltskin wrote:
Tue Mar 27, 2018 10:18 pm
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.
LC menus are groups. When you send to a stack LC may not always scan every object on the card. Instead, send to the group itself:

send "menu item" to btn "menu name" of group "menu group"

Placing the handler in the card or stack script instead, as you did later, is a cleaner solution I think.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7214
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: doMenu not finding the menu

Post by jacque » Wed Mar 28, 2018 6:24 pm

FourthWorld wrote:
Wed Mar 28, 2018 1:40 am
How do they differ?
On at least two platforms, IDE menus are one-card stacks. On user stacks, menus are groups that can span many cards or stacks.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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 6:33 pm

jacque wrote:
Wed Mar 28, 2018 6:24 pm
FourthWorld wrote:
Wed Mar 28, 2018 1:40 am
How do they differ?
On at least two platforms, IDE menus are one-card stacks. On user stacks, menus are groups that can span many cards or stacks.
Yes, an IDE's design for a system like LiveCode benefits by having a toolbar stack with menus separate from document windows (being an IDE, there is no traditional "document" per se).

But in all cases they're buttons in a group at the top of a card which respond to a menuPick message. So I was curious how they work as expected in one place but not another.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: doMenu not finding the menu

Post by bogs » Wed Mar 28, 2018 6:34 pm

Klaus wrote:
Wed Mar 28, 2018 11:54 am
"doMenu" is SOOOOO 90s ... :D
Best
Klaus
"doMenu" is soooo 80's.
Craig
"doWop" is forever, I vote for that one moving forward :twisted:

@ rumplestiltskin - glad you got it sorted out, but will be curious as to what was goofing up, if you ever find out.

------while posting entries--------
Jacque and Richard both made good points,
Jacque -- the menubar created by Lc is a group, it certainly would make it easier to send to that.
Richard -- If you do a lot of the same type of menu driven programming, ultimately lamping it into a library would be the best way to go.
Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7214
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: doMenu not finding the menu

Post by jacque » Wed Mar 28, 2018 6:55 pm

FourthWorld wrote:
Wed Mar 28, 2018 6:33 pm
But in all cases they're buttons in a group at the top of a card which respond to a menuPick message. So I was curious how they work as expected in one place but not another.
Possibly because a one card stack is scanned for all objects but a shared group needs to be specified because LC won't scan a whole stack looking for a specific control.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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 8:04 pm

jacque wrote:
Wed Mar 28, 2018 6:55 pm
FourthWorld wrote:
Wed Mar 28, 2018 6:33 pm
But in all cases they're buttons in a group at the top of a card which respond to a menuPick message. So I was curious how they work as expected in one place but not another.
Possibly because a one card stack is scanned for all objects but a shared group needs to be specified because LC won't scan a whole stack looking for a specific control.
Well, my stack does has three cards but, when I select any (single-function) menu item from any of the three cards, all the menu items worked. The problem was when trying to call a menu item from another menu item. Select "Quit" from the "File" menu and that would, in turn, call "Backup" from the "Maintenance" menu before returning to the "Quit" menu item which was supposed to execute the quit command. This was the only problem I encountered and resulted in -nothing- happening.

Now that I have stack scripts (doBackup, doQuit, doPrint, etc.) and simply use the menu structure to call them at the proper time, the "chaining" of doBackup>doQuit works as expected.

I also now see the advantage of having a "library stack" of scripts that might be common to many apps. All I need do (if I understand this correctly) is pass the stack-specific information in global variables (like backing up whatever the current stack is). I'm already using such a global var for the "long name of this stack" so I think I'm already part-way there. My assumption (from reading the Dictionary) is that:

Code: Select all

start using "myLibraryStackName"
...called during the openStack handler of the splash screen app would be the appropriate time; the menubar of my app might or might not have any or all of those menus/menu items. Does this sound right?

Thanks,
Barry

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”