Popup menus with several layers of sub-choices

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

danielrr
Posts: 140
Joined: Mon Mar 04, 2013 4:03 pm

Popup menus with several layers of sub-choices

Post by danielrr » Sat Mar 16, 2013 11:03 pm

Hi all!

What's the way in Livecode to build popup butons with lists of choices containing nested subchoices (and sus-subchoices, etc)?

In the image I uploaded you can see a very simple example of what I mean: a menu with several options and sub options
multipleChoices and sub-choices.png
multipleChoices and sub-choices.png (11.16 KiB) Viewed 9194 times
Back in the hyperCard days I used to use the seemeingly allpowerfull HPopUpMenu for that.

Best wishes,

Daniel

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

Re: Popup menus with several layers of sub-choices

Post by dunbarx » Sat Mar 16, 2013 11:11 pm

HC?

Never heard of it.

Try this in the contents of any of the pulldown, popup, etc, buttons:

Choice1/|1
Choice2/|2
choice2a/|3
choice3/|4
Choice4/|5
Choice5/|6
Choice6/|7

Craig Newman

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Popup menus with several layers of sub-choices

Post by sturgis » Sat Mar 16, 2013 11:31 pm

EDIT: Forgot to mention, on the older lc versions this doesn't seem to work unless you select "cascade" as the menu type. 5.5.1 needs cascade, 5.5.4 it seems to work for popup, pulldown etc.
use tab indents to designate submenu locations.
EDITEDIT: Nevermind, works on both so i've no clue what was horked before. *sigh* Still don't know why I can't get the other method to work.

Item 2 will have sub item 6 and sub item 6 will have sub item 3
Item 1
Item 2
[tab here] Item 6
[tab tab here] Item 3
Item 4
Item 5
Last edited by sturgis on Sun Mar 17, 2013 12:25 am, edited 2 times in total.

danielrr
Posts: 140
Joined: Mon Mar 04, 2013 4:03 pm

Re: Popup menus with several layers of sub-choices

Post by danielrr » Sat Mar 16, 2013 11:56 pm

dunbarx wrote:HC?

Never heard of it.
I was great it was cool it was… never mind, it was one century ago and now it's the time of LiveCode.

DunbarX... where did I heard this name…
dunbarx wrote: Try this in the contents of any of the pulldown, popup, etc, buttons:

Choice1/|1
Choice2/|2
choice2a/|3
choice3/|4
Choice4/|5
Choice5/|6
Choice6/|7

Craig Newman
yess! Thats the solution. Is there a stack with examples of simple solutions for simple problems like this one? Reading the manual I wasn't able to find the solution, and the web search didn't return any helpful address.

thanks a lot!

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

Re: Popup menus with several layers of sub-choices

Post by dunbarx » Sun Mar 17, 2013 12:29 am

Is it a program with which I wrote my first HC stack in 1987? One that I still use it extensively today and with which I just wrote a large client/server app for my business?

Hmmm.

Nope. Never heard of it.

Craig Newman

danielrr
Posts: 140
Joined: Mon Mar 04, 2013 4:03 pm

Re: Popup menus with several layers of sub-choices

Post by danielrr » Sun Mar 17, 2013 9:02 am

This way to build hierarchical menus seem great
Choice 1
\t subchoice A
\t \t subchoice A1
\t \t subchoice A2
Choice 2
\t subchoice B
\t \t subchoice B1
\t \t subchoice B2
Choice 13
\t subchoice C
\t \t subchoice C1
but the menuPick message only triggers when you choose the last option of a hierarchy. I mean if you choose "subchoice A1" thats fine with menuPick, but how do you know which item did the user choose if youur choice was "Choice 1" or "subchoiceA"?

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Popup menus with several layers of sub-choices

Post by sturgis » Sun Mar 17, 2013 4:13 pm

Menupick returns the entire list

choice1|subchoice2|subchoice3|subchoice4 so you in effect have the whole path returned. So if you chose C1 it would return choice 13|subchoice c|subchoice C1 Can't pick disclosure entries when done this way. So a choice is either an actual choice, or a container.

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

Re: Popup menus with several layers of sub-choices

Post by dunbarx » Sun Mar 17, 2013 5:40 pm

Hi.

Make sure you have tab chars to separate your subMenus. The list you gave had none, and would not have created a hierarchal set. My very first post had the tabs, but it would not necessarily have been obvious. I should have been more explicit.

The other characters were actually from an early test I made using hierarchal menus, and were based on something Jan Schenkel had written years ago. This is included here for you, but you may not need all this right now:


--Well, rev 3.5 introduced something called menu 'tagging' - here's a copy from the IDE change log included with rev 3.5

--===

--Menu-item tagging
--~~~~~~~~~~~~~~~~~

--The menu item specification has been extended to allow a tag to be specified. It is now of the form:
-- <label> [ '/' [ <accelerator> ] [ '|' <tag> ] ]
--Note that the <tag> is optional as is the <accelerator> however, if you want an item with a tag but without the accelerator you need:
-- <label> '/' '|' <tag>

--The <tag> must only be composed of characters from the ASCII character set.

--If a menu item has a <tag> then it is the tag string that is passed to menuPick rather than the <label>. This is useful for localization of menu items as you don't need to change the menuPick handler for each language supported.

--The following tags should be used to label the standard edit menu items to enable them to be controlled by the system dialogs on Mac OS X (e.g. answer file, ask file etc.):
-- undo, redo, cut, copy, paste, clear, select all, preferences

--Note: You should not mix the use of tags and no tags in Unicode menus. Doing so will cause empty values for all unicode items without tags.

--===

--Even though it sounds like it's only for "menubar" menus, tagging works for any type of menu. So you can use this knowledge to make the text:

--My Silly Name That I Reuse For Everything/|1
--My Subgroup/|2
--<tab>My Silly Name That I Reuse For Everything/|3
--My Silly Name That I Reuse For Everything/|4

--And then your menupick will automagically get the 'tag' value as the line number; of course with sub-menus, you get a pipe-delimited list of tags, with the entire hierarchy.

--So assuming that you change the text of your menu to the above style, your script could be something like:
--##
--on menuPick pItemTag
-- set the itemDelimiter to "|"
-- put the last item of pItemTag into tLineNumber
-- ...
--end menuPick
--##

--Menu tags also greatly simplify multilingual apps, as we can now just tag the items in our preferred language (or english, for consistency with the MacOSX presets) and work with the tag in our scripts.

-

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

Re: Popup menus with several layers of sub-choices

Post by Klaus » Sun Mar 17, 2013 5:52 pm

Hi Daniel,
danielrr wrote:...but the menuPick message only triggers when you choose the last option of a hierarchy. I mean if you choose "subchoice A1" thats fine with menuPick, but how do you know which item did the user choose if youur choice was "Choice 1" or "subchoiceA"?
the SUBitems are "delimited" with a pipe: |
So do this in the menupick handler:

Code: Select all

on menupick tItem
  set itemdel to "|"
  switch last item of tItem
    case "Choice 1"
   ##...
   break
   case "subdchoice C1"
    ## ...
  break
...
You get the picture :D


Best

Klaus

danielrr
Posts: 140
Joined: Mon Mar 04, 2013 4:03 pm

Re: Popup menus with several layers of sub-choices

Post by danielrr » Wed Mar 20, 2013 3:47 pm

NOW it's all clear. Thank you folks for your patience and clarity! :D

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Popup menus with several layers of sub-choices

Post by sturgis » Wed Mar 20, 2013 7:40 pm

Thx for the clarity too craig. For some reason, not being able to see the tabs my brain decided that there was some new thing I just wasn't understanding! (Of which there are SO many)

Thx for the detailed info, will be useful.

danielrr
Posts: 140
Joined: Mon Mar 04, 2013 4:03 pm

Re: Popup menus with several layers of sub-choices

Post by danielrr » Fri Mar 22, 2013 11:06 am

Sorry to return to this, but it seems like I am missing something completely obvious. Now, using the tab-system to create hierarchies of submenus is cristal clear and works like a charm, no matter how deep you go into submenus.

Choice A
[tab]Subchoice A1
[tab][tab]sub-subchoice A1a
[tab]Subchoice A2
Choice B
...

That's clear. Now my problem is: if you want to allow the user to select any choice or subchoice (and not just the last option of the hierarchy) the menupick doesn't seem to work.
I mean, if you choose (as per the example above) "sub-subchoice A1a" or "Subchoice A2" that's fine and the first parameter of the menupick message returns the whole chain. But if you choose one option which is not the last choice (for instance "Choice A" or "Subchoice A1") you simply dont get the menupick message, and so you can't know which choice the user picked. ¿Hoy can you know which option the user picked, in case it was not the last available subchoice?

Daniel

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

Re: Popup menus with several layers of sub-choices

Post by Klaus » Fri Mar 22, 2013 11:21 am

Hi Daniel,

the user CANNOT select any other item than the last one, that is the meaning of submenus!
You will need to supplay a REAL menutem with e.g. "Subchoice A1".

In your example:

Code: Select all

Choice A
[tab]Subchoice A1
[tab][tab]sub-subchoice A1a
[tab]Subchoice A2
Choice B
the user can only select:
sub-subchoice A1a
Subchoice A2
Choice B


Best

Klaus

danielrr
Posts: 140
Joined: Mon Mar 04, 2013 4:03 pm

Re: Popup menus with several layers of sub-choices

Post by danielrr » Fri Mar 22, 2013 11:53 am

ugh, I was afraid to hear that! Oh these times of over-specialization! :P well, thanks again Klaus

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Popup menus with several layers of sub-choices

Post by mwieder » Fri Mar 22, 2013 6:28 pm

Here you go. The mouseRelease message is sent to the popup menu on selection of a non-selectable menu item.

Code: Select all

local sSelected

on menuPick pChosen
    put "menuPick" && pChosen & cr after msg
end menuPick

on mouseRelease
    local tVPosition
    local tLineNumber
    
    put item 2 of sSelected into tVPosition
    subtract item 2 of the loc of me from tVPosition
    put round(tVPosition / the effective textheight of me) into tLineNumber
    menuPick line tLineNumber of me
end mouseRelease

on mouseMove
    if the mouse is down then
        put the mouseloc into sSelected
    end if
end mouseMove

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”