AW: difference between closing with the red cross or sending close?

Mark Schonewille m.schonewille at economy-x-talk.com
Tue Oct 14 11:02:09 CDT 2008


Hi Hugh and Tiemo,

That's a nice explanation, Hugh. Usually, I do it slightly  
differently, though. I don't pass the closeStackRequest message but  
lock messages instead.

on menuPick theItem
   if theItem is "Close" then
     answer "Really?" with "OK" or No"
     if it is "OK" then
       close this stack
     end if
   end if
   -- rest of script
end menuPick

-- only triggered by close stack command
on closeStack
   doStuffBeforeClosing
end closeStack

-- click closebox
on closeStackRequest
    answer "Really?" with "OK" or No"
    if it is "OK" then
      doStuffBeforeClosing
      lock messages
      close this stack
      unlock messages
    end if
end closeStackRequest

on doStuffBeforeClosing
   -- blabla
end doStuffBeforeClosing

This way, I don't need to keep states in boolean variables and avoid  
confusion when the cancel button is clicked.

There is nothing wrong with Hugh's approach and my aproach is hardly  
different, but I like to keep things as simple as possible. To make it  
even simpler, I could have put the doStuffBeforeClosing handler into  
the menuPick handler and get rid of the closeStack handler, but that  
would force me to add the doStuffBeforeClosing handler in all scripts  
that close the stack. Locking messages is particularly useful if  
closing the stack implies quitting the application and you want to  
call a script like the one at <http://runrev.info/Save%20Way%20to%20a%20Quit.htm 
 >.

--
Best regards,

Mark Schonewille

Economy-x-Talk Consulting and Software Engineering
http://economy-x-talk.com
http://www.salery.biz
Dutch forum: http://runrev.info/rrforum/

Benefit from our inexpensive hosting services. See http://economy-x-talk.com/server.html 
  for more info.

On 14 okt 2008, at 17:32, Hugh Senior wrote:

> Hi Tiemo,
>
> 'closeStackRequest' and 'closeStack' are messages, not commands.  
> This means
> you cannot send a 'closeStackRequest' any more than you can send a
> 'closeStack'. You can only 'close' a stack.
>
> A stack will always get a 'closeStack' message, but if the user  
> clicks the
> red closebox the stack will also get a 'closeStackRequest' message  
> first.
> This means that when the user clicks the red closeBox, a  
> closeStackRequest
> message is sent followed by a closeStack message.
>
> Lastly, you have to 'pass closeStackRequest' to continue with the  
> close.
> This is so you can optionally change your mind. This means you can  
> stop a
> closeStackRequest, but you cannot stop a closeStack.
>
> To handle both a scripted close and a red-cross close, place your  
> closing
> routine into a shared handler and trap wheter the routine has  
> already been
> run (otherwise you will get it twice when the user clicks the red
> closebox)...
>
> on mouseUp
>  close this stack
> end mouseUp
>
> local isClosing
> on closeStackRequest
>  answer "Are you sure?" with "Yes" or "No"
>  if it <> "yes" then exit closeStackRequest
>  put "true" into isClosing
>  doMyCloseStackStuff
>  pass closeStackRequest
> end closeStackRequest
>
> on closeStack
>  if isClosing <> "true" then doMyCloseStackStuff
> end closeStack
>
> on doMyCloseStackStuff
>  [../..]
> end doMyCloseStackStuff
>
>
> I have scripted the above so you can see what happens. Personally, I  
> would
> put the trap in the doMyCloseStuff handler thus...
>
> on doMyCloseStackStuff
>  if isClosing = "TRUE" then exit doMyCloseStuff
>  else put "TRUE" into isClosing
>  [../..]
> end doMyCloseStackStuff
>
> Hope this helps.
>
> /H
>




More information about the use-livecode mailing list