Popup menus with several layers of sub-choices
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Popup menus with several layers of sub-choices
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 Back in the hyperCard days I used to use the seemeingly allpowerfull HPopUpMenu for that.
Best wishes,
Daniel
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 Back in the hyperCard days I used to use the seemeingly allpowerfull HPopUpMenu for that.
Best wishes,
Daniel
-
- 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
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
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
Re: Popup menus with several layers of sub-choices
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
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.
Re: Popup menus with several layers of sub-choices
I was great it was cool it was… never mind, it was one century ago and now it's the time of LiveCode.dunbarx wrote:HC?
Never heard of it.
DunbarX... where did I heard this name…
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.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
thanks a lot!
-
- 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
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
Hmmm.
Nope. Never heard of it.
Craig Newman
Re: Popup menus with several layers of sub-choices
This way to build hierarchical menus seem great
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"?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
Re: Popup menus with several layers of sub-choices
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.
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.
-
- 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
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.
-
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.
-
Re: Popup menus with several layers of sub-choices
Hi Daniel,
So do this in the menupick handler:
You get the picture
Best
Klaus
the SUBitems are "delimited" with a pipe: |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"?
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
...
Best
Klaus
Re: Popup menus with several layers of sub-choices
NOW it's all clear. Thank you folks for your patience and clarity!
Re: Popup menus with several layers of sub-choices
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.
Thx for the detailed info, will be useful.
Re: Popup menus with several layers of sub-choices
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
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
Re: Popup menus with several layers of sub-choices
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:
the user can only select:
sub-subchoice A1a
Subchoice A2
Choice B
Best
Klaus
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
sub-subchoice A1a
Subchoice A2
Choice B
Best
Klaus
Re: Popup menus with several layers of sub-choices
ugh, I was afraid to hear that! Oh these times of over-specialization! well, thanks again Klaus
-
- 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
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
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev