Preventing NSDocument's "The document has been moved" alert
Preventing NSDocument's "The document has been moved" alert
- Subject: Preventing NSDocument's "The document has been moved" alert
- From: Andrew Madsen <email@hidden>
- Date: Tue, 3 Nov 2009 22:20:19 -0700
I've got an NS(Persistent)Document based application that has the
ability to import files saved in a standard (non CoreData) interchange
file format. I do this by overriding readFromURL:ofType:error:,
checking to see if the file to be opened is the format that has to be
imported, then doing the import. In the import routine, I add a new
persistent store to the persistent store coordinator and use the
setFileURL: method to set the URL of my document to the same URL as
the imported file except for the extension, which I change to the
extension of my native file format. I then perform a save operation
by calling saveDocument:. This is all fine, except that I get a "The
document foo.bar has been moved" alert upon calling saveDocument:. To
prevent this, I had been calling a private method,
_resetMoveAndRenameSensing just before saving the document. This
works fine under Tiger and Leopard, however in Snow Leopard, this no
longer works. Of course I know that this is the big problem with
using private methods. I'd like to figure out how to prevent this
alert without using a private method.
Without knowing exactly how NSDocument's rename/move/modification
sensing works, it's difficult to figure out how to keep it from being
triggered. I first thought that perhaps NSDocument was keeping track
of changes in fileURL. Since setFileURL: is called with the original
to-be-imported file's URL in the initWithContentsOfURL:ofType:error:
method, then again with the new to-be-saved document's URL in my
import method, I tried overriding initWithContentsOfURL:ofType:error:,
checking to see if the contents of the URL are a file that needs to be
imported, and if so, not calling setFileURL the first time. That way,
the fileURL of the NSDocument instance never changes between
initialization and save except for the change from null to the to-be-
saved doc's URL. This change by itself didn't suppress the alert.
Next, based on the documentation for NSDocument's fileModificationDate
method, I thought perhaps the NSDocument instance's file modification
date was being compared against the file to be saved to's modification
date and if the file had been modified later than the NSDocument's
modification date, NSDocument thought the file had been modified by
another application and thus presented the alert. To get around this,
I tried calling setFileModificationDate: with the current date, right
after adding the new persistent store to the persistent store
coordinator (and thus creating the file to be saved to). This also
didn't cause the alert to stop showing up.
I'm not sure how else NSDocument might be tracking renaming/moving/
modification of files. Any pointers?
Thanks,
Andrew Madsen
_______________________________________________
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