Re: NSDocument: Read-only types and autosavesInPlace
Re: NSDocument: Read-only types and autosavesInPlace
- Subject: Re: NSDocument: Read-only types and autosavesInPlace
- From: Daniel Vollmer <email@hidden>
- Date: Fri, 22 Jul 2011 20:35:02 +0200
On 22 Jul 2011, at 19:25, Kevin Perry wrote:
>
> On Jul 22, 2011, at 9:16 AM, Daniel Vollmer wrote:
>
>> Hello,
>>
>> I'm trying to add autosavesInPlace support to my NSDocument-based Application. It supports a read-only type that is internally converted (as suggested in https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Documents/Tasks/FAQ.html#//apple_ref/doc/uid/20000954-1081265-BAJFDEGD) to my writable type.
>>
>> The viewer- and editor-roles are set correctly in the application's plist, +writableTypes also returns only what I can write. For reference, I can read .txt and read/write .wowplot.
>>
>> Now, this seems to interact badly with autosavesInPlace: YES. The following happens:
>> 1) I open a document of the read-only type (.txt)
>> 2) I convert this as suggested above to my writable type, using setFileType and setFileURL
>> 3) I modify the document
>> 4) I attempt to close the document
>> 5) Now the autosave-Machinery jumps into action and I get the following error:
>> [ERROR] genstore_storage.c:GSAddPathAsGeneration:980 copyfile "/Volumes/Seerose/Users/maven/Desktop/110720 225338.wowplot" to "/Volumes/Seerose/Users/maven/Library/Autosave Information/2521980F-37BC-4E21-AF6A-001BE638AEFC.genstore.noindex/.genstore_staging/OUyU4Xi/staged" failed with error 2 (No such file or directory)
>>
>> The errors make sense, as the file under that name never existed.
>>
>> Now I'm stuck in-between a rock in a hard place:
>> If I change the type, autosavesInPlace tries to duplicate a non-existent file (because I modified the fileURL); if I don't change the type, NSDocument will ask me to write a file of a type I cannot support.
>>
>> Any ideas?
>
>
> There's a tidbit in the AppKit release notes regarding this (Look for "File Type Fixing in -[NSDocument saveToURL:ofType:forSaveOperation:completionHandler:]").
>
> While it doesn't say it right out, it suggests that you should give responsibility for changing to file URL to NSDocument. All you need to do is change the file type and NSDocument will take care of the file URL and avoid this error. (Note: you won't get this behavior if you're overriding the old -saveToURL:ofType:forSaveOperation:error: method.)
I've given this a go, but it does not seem to work for me. I set the new fileType after [super readFromURL:...] is done. Then, when
- (void)saveToURL:(NSURL *)url ofType:(NSString *)typeName forSaveOperation:(NSSaveOperationType)saveOperation completionHandler:(void (^)(NSError *errorOrNil))completionHandler
gets called, the arguments are as expected (i.e. the URL is still the original file with the "incorrect" extension and the type is the writable type I set myself), nevertheless, the URL is never changed and it ends up overwriting my original file in the wrong format. :(
Could this be due to me using a NSFileWrapper-based directory package (whereas the read-only type is a simple flat-file)?
Thanks,
Daniel._______________________________________________
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