Communication between modal stack and main stack

Chipp Walters chipp at chipp.com
Fri Nov 4 06:40:57 EST 2005


Jan,

I like to encapsulate the entire dialog capability into a single 
function call. This includes setup and display.

For instance. Let's say you want a dialog box which asks the user to 
select a single line from a list of stuff. And you want also to have a 
custom prompt. Plus you want an OK and Cancel button

I would write the function 'askListItem' and call it from the button 
named "pick your favorite fruit"
(tFruitList is a variable containing a line-delimited list of fruits)

get askListItem(tFruitList,"Please choose a fruit from the list")
if it is "Cancel" then exit mouseUp
put it into tMyFavoriteFruit

So, the question is how to make it this simple?

Easy, you'll want to build a stack "askList" with 2 fields: "theList" 
and "thePrompt"; 2 buttons "Cancel" and "OK"; and in the stack script:

function askListItem pList,pPrompt
   put "" into the dialogData
   put pList into fld "theList" of stack "askList"
   put pPrompt into fld "thePrompt" of stack "askList"
   modal stack "askList"
   return the dialogData
end askListItem

The script of the button "OK" is:

on mouseUp
    put the hilitedlines of fld "theList" into tLineNum
    if tLineNum is "" then
      beep
      exit mouseUp
    end if
    set the dialogData to line tLineNum of fld "theList"
    close this stack
end mouseUp

and the script for the button "Cancel" is:

on mouseUp
    set the dialogData to "Cancel"
    close this stack
end mouseUp

Now the secret to making all this work is that you need to make 
'askList' a library stack. This way, all of it's stack scripts will be 
available to whatever card/stack/button you're on.

To do this, you'll need to insert into the openStack handler of card 1 
of your main stack:

on openStack
   start using stack "askList"
end openStack

That's all there is to it! Now, you've got an encapsulated stack which 
can process list queries from anywhere.

Hope this helps,

Chipp


Jan Sælid wrote:
> Hi
> 
> I use several modal stacks  to communicate with the user.
> My first question is:
> 
> Is there a way to pass informasjon from a modal stack back to the function on the stack that
> opened it? Like "Return"? I use a custom property for now.... 
> 
> When the modal stack closes the function in the main stack that opened it continues. Just what I want. But for the remaining message path in the function
> I have to refer to the main stack - even if the fuction resides in the main stack. Or else I get a background not found error.




More information about the use-livecode mailing list