Page 1 of 1

Quit vs Close stack

Posted: Sun Nov 24, 2013 7:48 pm
by snm
I'd like to be sure that if user close my app, I can save changed data to MySql db. I'd like to display the warning "Your changed data are not saved into the database", co he could cancel the close app procedure, and check why data is not saved (the reason could be broken internet connection).

There is no problem if user quits by:
- pressing close window icon - as I can use closeStackRequest and not pass it
- choosing "Close" from "File" menu - as it doesn't sent "closeStack"

The problem starts when user choose "Quit" from "myAppName" menu or type cmd-Q. Even if I have the handler for "Quit" in my "File" menu button, it sends "closeStack" message which I can't trap and cancel.

Any idea how to make "Quit" behaviour same as "Close" behaviour when build the app menu?

Marek

Re: Quit vs Close stack

Posted: Sun Nov 24, 2013 8:42 pm
by jacque
You can trap either the "shutdown" or "shutdownRequest" message. But is there a reason you can't just trap "closeStack"? That would allow you to use the same handler for both the Close menu item and the Quit item.

Re: Quit vs Close stack

Posted: Sun Nov 24, 2013 10:39 pm
by snm
Jacque,
Unfortunately it's true what is mentioned in dictionary:
The actual closing is not triggered by the closeStack message, so trapping the message and not allowing it to pass does not prevent the stack from closing. To prevent a stack from closing, trap the closeStackRequest message.
The same is with "shutDown" message.

When I quit my app by cmd-Q or choose "myAppName" -> "Quit myAppName" from app menu - there is only "closeStack" message sent, no "closeStackRequest" which could break the quit or shutdown process. So I can't cancel closing the stack to give the user possibility to check internet connection or save his data in some other place.

It's on Mac OS 10.8.5 and any of LC versions. I didn't try it on Windows, but probably it's the same.

Marek.

Re: Quit vs Close stack

Posted: Sun Nov 24, 2013 11:01 pm
by Simon
Hi Marek,
on Win 7 closeCard is trapped by alt+f4 so is closeStackRequest.
liveCode 6.1.2

Simon

Re: Quit vs Close stack

Posted: Mon Nov 25, 2013 1:08 am
by FourthWorld
OS X sends a 'quit" Apple event on Cmd-Q. Trap for that in an AppleEvent handler and you'll have your bases covered.

Re: Quit vs Close stack

Posted: Mon Nov 25, 2013 6:25 am
by jacque
snm wrote:Jacque,
Unfortunately it's true what is mentioned in dictionary:
I misunderstood, I thought you wanted to perform an action before shutdown. I didn't notice you wanted to prevent quitting entirely. It looks like the shutdownRequest message would work though.

Re: Quit vs Close stack

Posted: Mon Nov 25, 2013 10:51 am
by snm
Richard,

I like your applescript hanger idea, but it doesn't work for me. I have the card script:

Code: Select all

on appleEvent pClass, pID
   answer pClass, pId
   --pass appleEvent
end appleEvent
In both IDE and standalone after cmd-Q application quits without answering. The only difference is when opening standalone I receive the answer "aevt,lapp". But no any answer when quitting by cmd-Q or choose from the menu myAppName->Quit myAppName.

Is something wrong in this handler, or it doesn't work because of some bug?

Marek