What's the better way to handle it in an application that has to close open documents before to quit?
Once the "Quit" menu item is invoked it start the message shutdownRequest and from there it seems impossible to close open documents because you get into a loop (for example, closing the last stack pops back up the message shutdownRequest again).
If someone has already created the standalones that manage multiple documents, some tell me how he did it?
Quit menu item
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: Quit menu item
Hi,
This should give you some idea.
Use the closeStackRequest message to ask the user to save a document without closing all documents and quitting the app.
Kind regards,
Mark
This should give you some idea.
Code: Select all
on menuPick theItem
switch theItem
case "Quit"
beep
answer "Do you really want to quit?" with "Yes" or "No"
if it is "Yes" then
send "quitMyProject" to me in 0 millisecs
end if
break
end switch
end menuPick
on shutDownRequest
send "quitMyProject" to me in 0 millisecs
end shutDownRequest
on quitMyProject
repeat for each line myStack in myOpenStacks
if the "cThisIsADocument" of stack myStack is true then
beep
// you might want to check whether changes were made by the user, I didn´t include this
answer "Do you want to save this stack before closing?" with "Yes" or "No" or "Cancel"
if it is "Cancel" then
exit quitMyProject
else
// handle saving your document here and then close
// saving is not included
close stack myStack
end if
end if
end repeat
// we have now checked, saved and closed all stacks
// the user never clicked "Cancel" so we can quit
lock messages // do not invoke shutDownRequest (again)!!!
// you may have to close the tts engine, close databases, hide the backdrop, etc
// otherwise your app may either crash or stay in memory
// now close all remaining stacks except for the main stack
repeat for each line myStack in the openStacks
if myStack is not "The Name of the Mainstack" then
close stack myStack
end if
end repeat
quit // poof!
end quitMyProject
Kind regards,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Quit menu item
Thank you so much Mark.
Where do I need to put this part of your sample code?
I have a group "MainMenubar" in the main application window, with three buttons containing the menu handlers, which I install with the statement:
One of this buttons if for File, one for Edit and one for Help, but I don't have one for the Application menu and don't know if it possible to have one due to the particular nature of that menu.
Where do I need to put this part of your sample code?
Code: Select all
on menuPick theItem
switch theItem
case "Quit"
beep
answer "Do you really want to quit?" with "Yes" or "No"
if it is "Yes" then
send "quitMyProject" to me in 0 millisecs
end if
break
end switch
end menuPick
Code: Select all
set the menubar of this stack to "MainMenubar"
Re: Quit menu item
Hi Mag,
To solve this mistery, refer to "Special menu items" in the "User Guide" on page 230.
A MUST READ for Mac developers!
Best
Klaus
so you got everything you need!Mag wrote:One of this buttons if for File, one for Edit and one for Help, but I don't have one for the Application menu
and don't know if it possible to have one due to the particular nature of that menu.
To solve this mistery, refer to "Special menu items" in the "User Guide" on page 230.
A MUST READ for Mac developers!
Best
Klaus
Re: Quit menu item
Thank you Klaus.