My Mac app (written in Objective-C) can save a document in two file formats: one with an exported type identifier (extension "gop"), and another with an imported file identifier (extension "sgf"). I want the user to be able to choose in the app’s preferences the default file save format they prefer.
My prepareSavePanel: method (see below) reads the user’s preference in this regard, lists the two formats in the correct order — chosen default first. The popup menu in the save panel I get conforms to my expectations (formats in the correct order), BUT the file extension I get in the file name field after the defaultDraftName is always "gop"!
Is there any way to get the app to select the extension "sgf" in the save panel popup menu when the user prefers "sgf"?
- (BOOL)prepareSavePanel:(NSSavePanel *)savePanel
{
if (@available(macOS 11.0, *)) {
NSArray<UTType *> *UTTypes = nil;
UTType * const myTypeGOP = [UTType typeWithFilenameExtension:@"gop"];
UTType * const myTypeSGF = [UTType typeWithFilenameExtension:@"sgf"];
NSInteger const i = [FLPreferenceControler defaultDocumentType];
if (i <= 0) {
UTTypes = [NSArray arrayWithObjects:myTypeGOP, myTypeSGF, nil];
}
else { /* i > 0. */
UTTypes = [NSArray arrayWithObjects:myTypeSGF, myTypeGOP, nil];
}
[savePanel setAllowedContentTypes:aUTTypes];
}
else { /* macOS < 11.0. */
NSArray <NSString *> * const UTIs = [self writableTypesForSaveOperation:0];
/* This method does the same as above, but for UTIs instead of UTType’s. */
[savePanel setAllowedFileTypes:UTIs];
}
return YES;
}