Using groups as custom dialogs: a solution for Mac, PC and iOS

Chipp Walters chipp at chipp.com
Fri Jul 8 19:17:11 EDT 2011


Mega PROPS goes to Scott Rossi for this. Turns out his technique "wait with
messages" works quite well, on both Mac and PC. And this should work
especially well on iOS where you cannot have a modal dialog window except
for those standard ask and answer ones. It works for me where I have
projects where I want one code base to work on iPad, Mac and PC.

As mentioned before, I enjoy using dialog stacks as functions. For instance,
if you want to ask the user for a color, then apply it to a rectangle
graphic you would typically script a button (no error checking going on for
readability sake):

on mouseUp
   answer color "Choose a color"
   set the backcolor of grc "test" to it
end mouseUp

In the past, I could do the same using custom designed 'color picker'
substacks and modal dialogs, so the script would look like this:

on mouseUp
   start using stack "altAnswerColor"
   get altAnswerColor()
   set the backcolor of grc "test" to it
   stop using stack "altAnswerColor"
end mouseUp

Sure, two extra lines, but very easy to accomplish and most importantly, I
can access the data from within the original mouseUp script and not have to
script a 'return' handler to manage the dialog and it's data after it is
closed. This all works because windows can be made 'modal' on both Mac and
PC-- but not on iOS.

So, I've created a simple small demo stack, which essentially does the same
thing, using groups instead of modal windows. You can access it by putting
in your message box the following and pressing return:

go URL "http://www.gadgetplugins.com/altplugins/testGrpDialog.livecode"

Here's how it works. You press the Test Dialog button which has the script:

on mouseUp
   put "" into fld "status"
   start using stack "altChooseThing"
   put "You chose button:" && altChooseThing() into fld "status"
   stop using stack "altChooseThing"
end mouseUp

Just like with the previous examples, there is a substack which acts as a
libraryStack and has the function, "altChooseThing()" which copies it's only
group to the topStack, then displays it, then waits for a custom property of
the newly copied group to change. It changes with a mouseUp handler residing
in the group. When altChooseThink() sees the custom prop change, it returns
the appropriate data. Very simple and clean.

Of course I would add a few other modifications, like creating an invisible
(or tinted) disabled btn under the group so no other controls on the card
could be accessed, and I would also like to see the group animate and slide
down like a Mac sheet. But, for those interested, this seems a pretty good
and modular approach.

-- 
Chipp Walters
CEO, Shafer Walters Group, Inc.



More information about the use-livecode mailing list