Re: NSDocument Save As... problem?
Re: NSDocument Save As... problem?
- Subject: Re: NSDocument Save As... problem?
- From: Quincey Morris <email@hidden>
- Date: Mon, 02 Feb 2015 23:02:02 +0000
On Feb 2, 2015, at 14:06 , Graham Cox <email@hidden> wrote:
>
> If my NSDocument subclass opens a file of a certain type, and then I do a Save As (option click the File menu), choose a new name and CHANGE THE EXTENSION, shouldn't the document be given the new typeName in -fileWrapperOfType:error: ?
I don’t think so, but I’m not sure. I think you’re supposed to convince NSDocument to get the right type from the save panel. For example, it says here:
https://developer.apple.com/library/mac/documentation/DataManagement/Conceptual/DocBasedAppProgrammingGuideForOSX/AdvancedTopics/AdvancedTopics.html <https://developer.apple.com/library/mac/documentation/DataManagement/Conceptual/DocBasedAppProgrammingGuideForOSX/AdvancedTopics/AdvancedTopics.html>
this:
> Customizing the Save Dialog
>
> By default, when NSDocument runs the Save dialog and the document has multiple writable document types, NSDocument inserts an accessory view near the bottom of the dialog. This view contains a pop-up menu of the writable types.
and I think you get this pop-up menu when you have multiple document types in the app, or when you have “NSExportableTypes” types. I believe I’ve used this in the past, and IIRC you get the type from the pop-up, even if you force the actual file extension to conflict — which sounds like what’s happening to you, except with an implicit pop-up of only one type. (But it would have been pre-UTI days when I did this, so take a grain of salt with it.)
TBH, your question may be one of those issues it’s no longer possible to adjudicate, because NSDocument has become so layered with obscurity over the years, in the “interests” of preserving backward compatibility.
One possible alternative would be to override the highest-level NSDocumentController save method (which might be ‘saveToURL:ofType:forSaveOperation:completionHandler:’), and pass a different file type to super, using the URL file name to choose the type.
_______________________________________________
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