Quit vs Close stack

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
snm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 253
Joined: Fri Dec 09, 2011 11:17 am

Quit vs Close stack

Post by snm » Sun Nov 24, 2013 7:48 pm

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Quit vs Close stack

Post by jacque » Sun Nov 24, 2013 8:42 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

snm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 253
Joined: Fri Dec 09, 2011 11:17 am

Re: Quit vs Close stack

Post by snm » Sun Nov 24, 2013 10:39 pm

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.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Quit vs Close stack

Post by Simon » Sun Nov 24, 2013 11:01 pm

Hi Marek,
on Win 7 closeCard is trapped by alt+f4 so is closeStackRequest.
liveCode 6.1.2

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Quit vs Close stack

Post by FourthWorld » Mon Nov 25, 2013 1:08 am

OS X sends a 'quit" Apple event on Cmd-Q. Trap for that in an AppleEvent handler and you'll have your bases covered.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Quit vs Close stack

Post by jacque » Mon Nov 25, 2013 6:25 am

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

snm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 253
Joined: Fri Dec 09, 2011 11:17 am

Re: Quit vs Close stack

Post by snm » Mon Nov 25, 2013 10:51 am

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

Post Reply