Re: Unwanted presentedItemDidMoveToURL: for old file after using setFileURL: to specify a new file
Re: Unwanted presentedItemDidMoveToURL: for old file after using setFileURL: to specify a new file
- Subject: Re: Unwanted presentedItemDidMoveToURL: for old file after using setFileURL: to specify a new file
- From: Kyle Sluder <email@hidden>
- Date: Mon, 16 Sep 2013 10:14:26 -0700
On Sat, Sep 14, 2013, at 01:14 PM, Brian Clark wrote:
> I'm hoping someone can suggest the correct way to deal with the following
> problem.
>
> For an image viewing app i display a file in the usual way in an
> NSDocument. setFileURL: is properly called by NSDocument's
> _initWithContentsOfURL:ofType:error:.
>
> I now want to display the next file in the folder, and move the old file
> to the Trash. To do this I do the necessary file reading tasks and call
> setFileURL: with the new file URL. I then move the old file to the trash
> (using NSFileManager 's trashItemAtURL:resultingItemURL:error: but using
> different methods gives the same result.)
>
> Prior to 10.7 this worked fine and gave the desired result. Under 10.8,
> shortly after I load the new file and call setFileURL: with the new file
> URL as described above, I see a presentedItemDidMoveToURL: call with the
> old file URL. From that point on, the document has the wrong URL
> associated with it.
Can you post your code for this?
One thing that comes to mind: you need to serialize against the incoming
file presenter notifications (delivered on the queue returned by
-presentedItemOperationQueue). Otherwise there's no guarantee that the
file coordination subsystem will have seen and confirmed your
relinquishing of the old URL by the time you start dealing with the new
one.
Furthermore, the NSFilePresenter protocol doesn't give you a way to
inform the system that the presentedItemURL of the presenter has
changed. You should make sure that NSDocument is calling
+removeFilePresenter: and +addFilePresenter: as part of its -setFIleURL:
action.
To be honest, I'm not even sure it's possible to do what you want to do.
You might need to open up the next file as a new document.
--Kyle Sluder
_______________________________________________
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