Re: customizing save behavior in doc based apps
Re: customizing save behavior in doc based apps
- Subject: Re: customizing save behavior in doc based apps
- From: email@hidden
- Date: Mon, 26 Dec 2005 21:17:21 -0500
After a lot of thought and reading , I think that the simplest way to
get the job done is with this:
- (void)canCloseDocumentWithDelegate:(id)delegate shouldCloseSelector:
(SEL)shouldCloseSelector contextInfo:(void *)contextInfo {
if ([self fileURL]) { //make sure document has been saved to
disk already
[[self managedObjectContext] save:NULL];
[self updateChangeCount:NSChangeCleared]; //clear to prevent
super's call from eventually invoking save dialog
}
[super canCloseDocumentWithDelegate:delegate
shouldCloseSelector:shouldCloseSelector contextInfo:contextInfo];
}
This gets called just before the save panel would show when the
window closes and when the app tries to close via something like cmd-
q as well. It turns out that the hanging I'm experiencing with
untitled documents when quitting the app with cmd-q still happens,
but I'm not sure that it's something I can pin down right now -- I'm
working on code that someone else started a while back, so it's
possible there's something funny going on elsewhere that might be
causing the hang. Not a big deal either way.
And for the dirty marker -- I think I'll just go with the flow and
quit trying to suppress its normal behavior. After some thought, it's
still a good reminder to have the user periodically save, even if I'm
trying to do it for them when they quit..and life's easier for me
that way too.
Thanks again for all the help. I was definitely making this all too
hard last night.
M.
On Dec 26, 2005, at 6:19 PM, mmalcolm crawford wrote:
On Dec 26, 2005, at 1:59 PM, email@hidden wrote:
Great point. I definitely don't want the disk churning away with
every single input and this seems like an elegant way to avoid
that. Really, all I want is for changes to automatically get saved
to disk whenever the user closes the window or quits the app. The
only time I want them to get prompted for a save is when they try
to close the window or quit the app with an untitled document --
which is why I was originally trying to override close and
applicationShouldTerminate:
The latter two are handled for you automatically by the document
architecture -- is there any reason why that behaviour is
insufficient?
If you want changes to be saved on close, could you not just
override -close?
mmalc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40mac.com
This email sent to email@hidden
M.
_______________________________________________
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