> On 3 Feb 2015, at 10:02 am, Quincey Morris 
> <[email protected]> wrote:
> 
> On Feb 2, 2015, at 14:06 , Graham Cox <[email protected]> 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
> 
> 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.)


I think I may have got my UTIs slightly wrong - no surprise, they're really 
annoying, hard to understand and fragile.

The app supports 4 document types. It imports all 4 UTIs corresponding to these 
types, but it exports only two. One of the document types' role was set to 
"editor", but I did not have this as a corresponding exported UTI. My Save 
dialog is not showing the format pop-up (I'm also adding my own accessory view, 
but that should be in addition to any format pop-up I believe). I do not have a 
NSExportableTypes entry - in fact I don't think I've heard of that before, I 
thought it was figured out from the UTIs and/or the document types (who knows, 
it's a rabbit warren of interconnected dependencies with no clear canonical 
source of information that I can see).

Changing the role to "viewer", it allows the file to be opened, and then when 
it's saved its type is changed and it gets saved in the new format - I don't 
have to mess about with extensions in the Save dialog. So I probably should 
have had that set as "viewer" all along. Alternatively, adding that type as an 
exported UTI and keeping its role as "editor", I expected to see the format 
pop-up, but I don't. Why? Don't know.

> 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.

Yup, it's become fiendishly complex.

> 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.

It might come to that. At the moment I override NSDocument at the file wrapper 
level. I could try one step up at the URL level, which may be enough, without 
having to go as high as the document controller level. But it says something 
about how complicated NSDocument has become that what used to be simple is now 
easier to do by completely avoiding it altogether.

--Graham




_______________________________________________

Cocoa-dev mailing list ([email protected])

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

This email sent to [email protected]

Reply via email to