Re: Telling Auto Save, "No, I'm busy now"
Re: Telling Auto Save, "No, I'm busy now"
- Subject: Re: Telling Auto Save, "No, I'm busy now"
- From: Jerry Krinock <email@hidden>
- Date: Tue, 09 Aug 2011 06:47:04 -0700
On 2011 Aug 08, at 09:29, Kevin Perry wrote:
> You may be able to work around this problem by overriding -autosaveWithImplicitCancellability:completionHandler: instead (also?) and doing the same approach of delaying NSDocument's code until once you've completed the background work.
Thank you, Kevin. That seems to work; at least, it has worked for a day.
As usual when dealing with NSDocument, the answer is to "override as high as possible".
I just submitted Document Feedback suggesting that this document
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Documents/Articles/ObjectInteractions.html
get another excellent diagram like the others in there, showing how Autosave In Place works. We would have gotten here faster!
Jerry
Here's the revised code for anyone else playing with customized autosave. Now simpler and safer, because we're only dealing with autosave…
/*!
@brief Override of new autosave method invoked by Cocoa
when running in Mac OS X 10.7 or later.
*/
- (void)autosaveWithImplicitCancellability:(BOOL)autosavingIsImplicitlyCancellable
completionHandler:(void (^)(NSError *errorOrNil))completionHandler {
if ([self dataModelChangesAreNowInProgressOrWhatever]) {
if (autosavingIsImplicitlyCancellable) {
completionHandler([NSError errorWithDomain:NSCocoaErrorDomain
code:NSUserCancelledError
userInfo:nil]) ;
return ;
}
}
<snip>
Insert code here to queue an operation or block to be run when other
tasks changing the data model are completed. If not a using modern
block-handling method, you may need Block_copy(completionHandler).
</snip>
}
/*!
@brief Real autosaving method, invoked when operation or block is dequeued.
*/
- (void)reallyAutosaveWithCompletionHandler:(void (^)(NSError *errorOrNil))completionHandler {
[super autosaveWithImplicitCancellability:NO
completionHandler:completionHandler] ;
// If you did Block_copy(), …
Block_release(completionHandler) ;
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
References: | |
| >Re: Telling Auto Save, "No, I'm busy now" (From: Kevin Perry <email@hidden>) |
| >Re: Telling Auto Save, "No, I'm busy now" (From: Jerry Krinock <email@hidden>) |
| >Re: Telling Auto Save, "No, I'm busy now" (From: Ken Thomases <email@hidden>) |
| >Re: Telling Auto Save, "No, I'm busy now" (From: Kevin Perry <email@hidden>) |
| >Re: Telling Auto Save, "No, I'm busy now" (From: Jerry Krinock <email@hidden>) |
| >Re: Telling Auto Save, "No, I'm busy now" (From: Kevin Perry <email@hidden>) |