Re: stop and wait
Re: stop and wait
- Subject: Re: stop and wait
- From: "M. Uli Kusterer" <email@hidden>
- Date: Sun, 5 Oct 2003 16:14:56 +0200
At 9:44 Uhr -0300 05.10.2003, Mark Davis wrote:
When you go to "File: New" in my application it will do this:
[mainWindow performClose:self];
[self resetVariables];
Disregarding why you would want to restrict your application to only
one window (which IMHO is needlessly restricting your users), you're
trying to tackle this from the wrong end: Instead of doing all of
this in your "new" method, change your window/document class. The
document is sent a windowDidClose message. Or, you could even do this
from your window's or document's dealloc method. Those are only sent
when the window actually closes. So just have "new" close the current
window, and have the window or document take care of cleaning up
behind itself.
Of course, you'd still have to find a way of creating a new window
after closing the old one. At worst, you could create your own
performClose:andDoAction: method that saves a constant or a SEL to
the action to be performed on dealloc in a member variable of the
window. Then, on dealloc, it would look at this variable to find out
what action to perform, and call your application's
resetVariables:andDoAction: method.
This will get messier and messier though, as you'd have to make sure
this member variable is cleared when the user cancels, so a "close"
command or click in the window's close box will not suddenly dispatch
a cancelled action.
It may be easier to replace the entire code that asks for "save
changes" with your own code that shows a sheet of your own doing, and
having the sheet's message be different for creating files than for
regular closing. You could even customize the message to say "save
the file before opening a new one?" instead of the default text.
I want to know how to wait until this performClose method is done so
I can check if the user hit Cancel (in which case they would be
canceling the "newFile" method.
But why do you think you need to close the previous document before
opening the next one anyway? It is very likely that with a little
more careful design, you could support multiple open documents at a
time, which restricts your users much less, conforms with the
behavior of other applications on the computer, and saves you from
having to work out elaborate ways of fighting AppKit's default
behavior.
Why do you need to force a single open document? Are you using the
document-based style of application? That will easily take care of
switching in/out documents, and if you need to keep some "inspector"
window or hardware device synced up with the frontmost document, you
can easily do so by sending messages to the application (or better, a
dedicated delegate for this) when your window comes to the front.
I tried doing a while with the returncode of the "Would you like to
save your changes" sheet but while seems to halt everything up so
you can't click anything in the sheet.
You're not processing any events in your "while" loop, which is what
you need to have the user's actions processed by the application. You
could run your own run loop, but this can get messy quickly and is
much more involved than taking a step back to find a different way of
handling the behavior you need.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.