NSDocument save customisation and -fileModificationDate
NSDocument save customisation and -fileModificationDate
- Subject: NSDocument save customisation and -fileModificationDate
- From: "email@hidden" <email@hidden>
- Date: Tue, 22 Oct 2013 10:41:27 +0100
In my document app I prompt users to save when switching views via:
NSDocument -canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo
I can call this once successfully after which I receive a sheet saying:
This document’s file has been changed by another application since you opened or saved it.
I figure this is related to -fileModificationDate, but I do update this (without effect) when saving (see below).
I also note that in -saveToURL:etc I don't actually need or want to create the file indicated by the url argument.
So perhaps that triggers the file modification warning?
And so it turns out; the following NSDocument override prevents the display of the warning sheet:
- (NSDate *)fileModificationDate
{
return nil;
}
This question is whether the above is just a rotten hack or is actually consistent with the internal operation of NSDocument.
I have customised NSDocument saving like so:
- (void)saveDocument:(id)sender
{
[self saveDocumentModel:self];
}
- (void)saveToURL:(NSURL *)url ofType:(NSString *)typeName forSaveOperation:(NSSaveOperationType)saveOperation completionHandler:(void (^)(NSError *errorOrNil))completionHandler
{
// this method will be called when attempting to close an edited document
[self saveDocumentModel:self];
// the completion handler will close the window if required
completionHandler(nil);
}
- (void)saveDocumentModel:(id)sender
{
// persist changes in the managed data store.
[self.entities saveChanges];
// clear the document edited status
[self updateChangeCount:NSChangeCleared];
[self setFileModificationDate:[NSDate date]]; // likely pointless in this case
}
Jonathan
_______________________________________________
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