Page 1 of 1
Quit menu item
Posted: Fri Sep 25, 2015 2:51 pm
by Mag
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?
Re: Quit menu item
Posted: Sun Oct 04, 2015 9:59 pm
by Mark
Hi,
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
Use the closeStackRequest message to ask the user to save a document without closing all documents and quitting the app.
Kind regards,
Mark
Re: Quit menu item
Posted: Fri Oct 14, 2016 2:14 pm
by Mag
Thank you so much Mark.
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
I have a group "MainMenubar" in the main application window, with three buttons containing the menu handlers, which I install with the statement:
Code: Select all
set the menubar of this stack to "MainMenubar"
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.

Re: Quit menu item
Posted: Fri Oct 14, 2016 2:39 pm
by Klaus
Hi Mag,
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.

so you got everything you need!
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
Posted: Fri Oct 14, 2016 4:12 pm
by Mag
Thank you Klaus.
