I have an application that can load in third party code. One of the capabilities that the third party code can do is add formats in which the app can export to. I am using saveDocumentTo: as means for implementing export.
I understand that I can customize the menu of available filetypes to save in via overriding writableTypesForSaveOperation: for my document, but what doesn’t work is that in the save dialog an appropriate file extension isn’t added to the filename when selected from the menu.
I tried overriding fileNameExtensionForType:saveOperation: but that doesn’t even get called.
How can I make the Save dialog find the correct file extension (provided it isn’t known at compile time)?
I’ve done this within a custom export accessory view for the Save Panel. The custom export accessory view just changes the
NSSavePanel‘s allowed file types whenever the user changes the format they want to export to.If you want to set the extension, pass an array with one element containing that extension.
The docs have some important detail for
-[NSSavePanel setAllowedFileTypes:]‘s behavior in this regard, for supporting more complex cases:You may also see dedicated export dialogs in some cases which can reduce the complexity of this if you have several distinct formats. As before, you just update the allowed file types to support this (not necessarily dynamically in this case).