Page 1 of 1

Cascading Menu Trouble

Posted: Wed Apr 30, 2014 5:35 pm
by peter.s
Hi there,

I can't figure out how to select items in a cascading menu button. I can get a simple menu button working just fine, and I can build a cascading menu - but writing the code for the extra submenu layer has thrown me.

This is a standard menu button from the dictionary

Code: Select all

on menuPick theMenuItem 
switch theMenuItem
case "Name of First Item" 
-- do stuff here for first item
break 
case "Name of Second Item"
-- do stuff here for second item 
break
case "Name of Third Item" 
-- do stuff here for third item
break 
end switch 
end menuPick
Can someone show me how to incorporate a submenu - lets say "Name of First Item", with "Submenu Item One", and "Submenu Item Two" ?

Cheers

Re: Cascading Menu Trouble

Posted: Wed Apr 30, 2014 6:02 pm
by Klaus
Hi Peter,

the "(sub)menuitems" are returned in this format for "cascading" menus, separated with a pipe |:
Name of First Item|Submenu Item One
Name of First Item|Submenu Item Two|Submenu item Three|etc...

So you could check the number of items and do something like this:
...
set itemdel to "|"
## Answer first submenu e.g. -> Submenu Item One
answer item 2 of theMenuItem
...

Best

Klaus

Re: Cascading Menu Trouble

Posted: Sun May 04, 2014 1:06 pm
by peter.s
Thanks for responding Klaus.

I've been trying a few things but I'm still not getting it... and I realised that perhaps I wasn't very clear in my original post.

I'm having trouble with the MenuPick message. The user guide I have is not very clear about this. My reckoning is that it should look something like this:

Code: Select all

on menuPick theMenuItem
   switch theMenuItem
      case menuitem "First Item|Subitem One" of me
         --do stuff
         break
       case menuitem "First Item|Subitem Two" of me
         --do stuff
         break
But I'm obviously doing something wrong as it isn't working :-) Any advice?

Re: Cascading Menu Trouble

Posted: Sun May 04, 2014 1:41 pm
by Klaus
Hi Peter,

do this:

Code: Select all

on menuPick theMenuItem
   switch theMenuItem
      case "First Item|Subitem One"
         --do stuff
         break
       case "First Item|Subitem Two"
         --do stuff
         break
...
Best

Klaus

Re: Cascading Menu Trouble

Posted: Sun May 04, 2014 8:15 pm
by peter.s
Thanks Klaus - that works!