Re: open docs at quit time
Re: open docs at quit time
- Subject: Re: open docs at quit time
- From: Ken Victor <email@hidden>
- Date: Mon, 22 Aug 2005 15:26:31 -0700
autosaving is not currently supported for NSPersistentDocument. i'm
sorry if i forgot to mention i'm writing a core data app.
i've since solved this issue, but it still seems far more complext
than it should be. i've had to subclass NSApplication (to override
replyToApplicationShouldTerminate) and i had to provide the delegate
methods applicationShouldTerminate and applicationWillTerminate in my
app delegate. and i had to provide a subclass of NSQuitCommand and
specify my subclass in my sdef file. and lastly, i had to provide a
subclass of NSDocumentController (to override
closeAllDocumentsWithDelegate)
basically it works this way:
in applicationShouldTerminate (in my app delegate),
closeAllDocumentsWithDelegate (in my subclass of
NSDocumentController). and in executeCommand (in my subclass of
NSQuitCommand), i build an array of NSDocuments if the array doesn't
already exist. in applicationShouldTerminate i return
NSTerminateNow. in close (in MyDocument class) i either delete the
document object from the array if the document doesn't have a url, or
i replace the document object in the array with the fileURL of the
document. (this covers the situation when the user saves an unsaved
document as part of the quit process). in applicationWillTerminate i
close any documents that haven't yet been closed. i then iterate over
the array, saving in prefs any URLs that are in the array. in my
override of replyToApplicationShouldTerminate. i release any document
array to cover the situation in which the user cancels the quit.
this works.
ken
At 2:39 PM -0700 8/22/05, Scott Anguish wrote:
On Aug 20, 2005, at 2:55 PM, Ken Victor wrote:
i'd like to maintain a list (in preferences) of any documents the
user had open when quitting my app so that i can re-open them the
next time my app is launched. i'd like to include in this list any
docs that were new and saved as part of the quit process. and i'd
like this to work regardless of how my app is quit, ie, whether it
was quit via a menu selection or via an apple event.
i must be missing something simple as i've now spent a couple of
days and haven't been able to get it to work in all cases. i've
been "playing around with" applicationShouldTerminate and
applicationWillTerminate and even with a custom
NSDocumentController (overriding closeAllDocumentsWithDelegate and
reviewUnsavedDocumentsWithAlertTitle). i've read the documentation
about graceful app termination and done a few google searches.
i'd appreciate any pointers and/or sample code.
Is there a reason you can't use the autosave behavior released
in Tiger as part of NSDocument?
It's only really documented in the release notes at the moment I think
http://developer.apple.com/releasenotes/Cocoa/AppKit.html
New NSDocumentController Methods for Autosaving
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden