one case for all options in Option Menu

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am

one case for all options in Option Menu

Post by sphere » Thu May 12, 2016 2:38 pm

Hello,
i got 2 questions of which the first i maybe can figure out myself.

I want to fill the options in the Option Menu with a list from a txt file. (1 option per line)
In this txt file extra options can be added. Via a entry field and a button which adds this line to the txt file.

-How do i populate the Option Menu with such a list? (when opening the stack or when saving the list after adding)

Now the most important:
How can i make sure that no matter which option is choosen in the Option Menu,
that always the same 'case' is being executed like: send "mouseUp" to btn"load"
Because now i have to create a case for each option.
But i don't want to reprogram the Option Menu every time a Choice is added, after all it's an exe by then.

Thanks for any help on this.
Sphere

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: one case for all options in Option Menu

Post by Klaus » Thu May 12, 2016 3:01 pm

Dag sphere,
sphere wrote:-How do i populate the Option Menu with such a list? (when opening the stack or when saving the list after adding)
...
set the text of btn "your option button here..." to url("file:" & "path/to/your/textfile.txt")
...
sphere wrote:Now the most important:
How can i make sure that no matter which option is choosen in the Option Menu,
that always the same 'case' is being executed like: send "mouseUp" to btn"load"
Because now i have to create a case for each option.
But i don't want to reprogram the Option Menu every time a Choice is added, after all it's an exe by then.
Sorry, don't get this? :D
Maybe:

Code: Select all

on menupick WhatEver
  do_the_one_thing
end menupick
?

Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10352
Joined: Wed May 06, 2009 2:28 pm

Re: one case for all options in Option Menu

Post by dunbarx » Thu May 12, 2016 3:15 pm

Hi.

The menuItems in an option menu are simply the contents of that button. Did you know that buttons are containers?

Code: Select all

put "x" & return & "y" & return & "z" into btn "yourOption"
answer btn "yourOption"
answer the text of btn "yourOption"
I am not sure what your second question is about. You say you want the same "case" regardless of what option is chosen.

You say you want a "case" for new options that might be added on the fly. Well, that can be done, but it will depend either on the text itself, or its position in the list, or, perhaps, a common action dependent on a choice from that list. So, for example, if you loaded the above three menuItems, and each was a reference to a card name, you could:

Code: Select all

on menuPick pItemName
go cd pItemName
And now it does not matter what new items are added, as long as there is a card with that name. Do you see? The common action (going to a card) will implement what I think is what you want, but am not sure.

Maybe write back with your comments,

Craig Newman

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am

Re: one case for all options in Option Menu

Post by sphere » Thu May 12, 2016 3:40 pm

Gutentag Klaus and Hello Craig,

thank you both for your comments.
Meanwhile the first i figured out how to populate the option menu with a list.

With the second question i mean this:

Code: Select all

on menuPick pItemName
   switch pItemName
     send "mouseUp" to btn"load"
   end switch
end menuPick
but that did not work.
This seems to work ok

Code: Select all

on menuPick
send "mouseUp" to btn"load"
end menuPick
thanks for your superfast help so far!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10352
Joined: Wed May 06, 2009 2:28 pm

Re: one case for all options in Option Menu

Post by dunbarx » Thu May 12, 2016 5:20 pm

Well, if that is what you needed, great. Two things:

1- If you use a switch statement, you must have a case statement:

Code: Select all

on menuPick pItemName
   switch pItemName
     case "anyChoiceAtAllApparently"
       send "mouseUp" to btn"load"
       break
   end switch
end menuPick
Or, if you want, lose the menuPick handler entirely, since it is not used, and:

Code: Select all

on mouseUp
   send "mouseUp" to btn"load"
end mouseUp
Craig

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am

Re: one case for all options in Option Menu

Post by sphere » Thu May 12, 2016 7:42 pm

Thanks Craig!

The first one i knew, the second not.
Great!

Post Reply