Page 1 of 1

How do I use a custom stack as an "ask"-dialog?

Posted: Tue Oct 07, 2008 7:03 am
by morbug
Hi there everyone! I'm horribly new at using Revolution and I need help with a small problem:

In my current application I use a simple ask dialog on a couple of my substacks when I need the user to specify one of several options (what options vary each time). I simply list the options in the prompt and the user writes what options to use in a text field (this sounds like a horrible solution but the answer does not _have_ to be exact and they can come up with their own options if they want to). I want to replace this with a stack with a scrolling list field with the known options and a text field where they can write their own.

Ideally I want it to work like this:
The application notices that the user has to specify an option and calls the "option"-stack with the known options (which I get from a data stack) as a comma-separated string. The stack opens and populates the list field with the known options. The user then chooses one of the known options or writes his own in the text field. After clicking "OK" the stack returns the contents of the text field (if used) or the selection of the list field to the handler from which it was called. The handler will then use this answer.

What is the easiest way to make a stack do something like the above? Alternative solutions to the above scenario is also definitely welcome :)

Thanks!

Edit: I have already created the "options stack" and have written the code to populate the list field. What I don't get is how to call it from the middle of one of several different handlers and then use the result, like you can do with the ask dialog.

Posted: Tue Oct 07, 2008 10:13 am
by Mark
Hi morbug,

You can write a special function that puts information into the dialog, shows the options, and returns the selected options. In this function, you can use the global property dialogData to transfer information from the function to the dialog.

You need the following scripts:

Code: Select all

-- function in script of mainstack
function pickOptions theOptions
  put theOptions into the dialogData
  go stack "Options" as modal
  -- script doesn't run until stack "Options" closes
  if the dialogData is not "Cancel" then
    return the dialogData
  end if
  return empty
end pickOptions

-- stack script
on preOpenStack
  put the dialogData into fld "Options"
end preOpenStack


-- OK button
on mouseUp
   set the dialogData to the selectedText of fld "Options"
   close this stack
end mouseUp

-- Cancel button
on mouseUp
   set the dialogData to "Cancel"
  close this stack
end mouseUp
When you call the function, the modal stack opens with the data passed to the function. The dialog stack puts the dialogData into the Options field. The OK button takes the selected lines and stores them into the dialogData while the Cancel button stores "Cancel" instead of any selected options. If the function receives "Cancel" from the dialog stack, it returns empty.

If one of the options is "Cancel", you might want to change the mouseUp handler of the Cance button to return empty and the function to check whether the dialogData are empty instead of "Cancel".

(I haven't tested this script, it might contain typos or little mistakes).

Best,

Mark

Thanks!

Posted: Tue Oct 07, 2008 11:53 am
by morbug
It looks like this is exactly what I need :)

Thanks!

Edit: After a few adaptations to my code it works perfectly. This will make my life a lot easier. Thanks again!