I had this same problem. I was storing some flat-file "slave" documents inside a package-based "master" document. This led to several problems:

Internally NSDocument stores its path as an FSRef, not just a URL. FSRefs allow you to track files as they move around the volume. Convenient. But the problem is that when the outside filewrapper of the master document is re-written, its internal FSRef changes (though the URL will remain the same). Once the master's FSRef is changed, the slave's FSRefs are essentially invalidated.

My solution/workaround was to keep track of the slave document's URL myself, and hijack NSDocument's save facility at a high level by overriding:

- (void)saveDocumentWithDelegate:(id)delegate didSaveSelector: (SEL)didSaveSelector contextInfo:(void *)contextInfo

(note if you do this, you'll have to send the delegate didSaveSuccessfully method yourself)

I ran this problem and the gist of my solution by some Apple engineers at WWDC and surprisingly they weren't horrified. They did suggest that I should try just re-setting the documents fileURL, which should reset the FSRef and help the document find itself again. I haven't had time to try it yet.

Hopefully something in there is useful.

- Andy


On Jun 11, 2008, at 5:01 PM, LAURENS Jérôme wrote:

Hi all,

I have a document based application with 2 kinds of documents:masters and slaves
When saving the master document, all its slaves are also saved.
So I override one of the writeToURL method of the master class document to send the appropriate writeToURL to its slaves. My app also does rather complex tasks that need to save the master document without user interaction.

In some situations, I cannot send a saveDocument: message to the slave document and have a smooth operation: unexpectedly, a dialog box appears saying that the location of the slave document is lost, and that I must save it again. Then the standard save panel appears, and is already filled with the proper name of the slave document.

In the saveDocumentWithDelegate:... description (inside NSDocument.h), it is said that

"it may present a panel asking the user to make a decision for any of the following situations: 1) The document's file or file package was moved or renamed since it was opened or most recently saved. 2) The document's file or file package was deleted or trashed since it was opened or most recently saved."

Since a panel appears, one of the above situation is recognized. But in no way, I am willing to move nor rename the file! The file URL never changes. What puzzles me is that my app perfectly knows the URL of the document because it presents the save panel at the right location with the right name!

Any hint is welcome,

TIA


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/andy.mroczkowski%40gmail.com

This email sent to [EMAIL PROTECTED]

On Jun 11, 2008, at 5:01 PM, LAURENS Jérôme wrote:

Hi all,

I have a document based application with 2 kinds of documents:masters and slaves
When saving the master document, all its slaves are also saved.
So I override one of the writeToURL method of the master class document to send the appropriate writeToURL to its slaves. My app also does rather complex tasks that need to save the master document without user interaction.

In some situations, I cannot send a saveDocument: message to the slave document and have a smooth operation: unexpectedly, a dialog box appears saying that the location of the slave document is lost, and that I must save it again. Then the standard save panel appears, and is already filled with the proper name of the slave document.

In the saveDocumentWithDelegate:... description (inside NSDocument.h), it is said that

"it may present a panel asking the user to make a decision for any of the following situations: 1) The document's file or file package was moved or renamed since it was opened or most recently saved. 2) The document's file or file package was deleted or trashed since it was opened or most recently saved."

Since a panel appears, one of the above situation is recognized. But in no way, I am willing to move nor rename the file! The file URL never changes. What puzzles me is that my app perfectly knows the URL of the document because it presents the save panel at the right location with the right name!

Any hint is welcome,

TIA


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/andy.mroczkowski%40gmail.com

This email sent to [EMAIL PROTECTED]

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to