Eventually with some difficulty I solved this problem.
To make sure that the accessory panel is loaded from the .xib I do this:
IBOutlet NSView* accessoryView;
if(!accessoryView){ //not loaded yet
NSArray *_Nullable* topLevelObjects = nil; //allocated as nil but doing it explicitly supresses a compiler warning
if([[NSBundle mainBundle] loadNibNamed: @"accessoryView" owner: self topLevelObjects: topLevelObjects] == NO){
myCustomAlert(@"INTERNAL ERROR!", @"Unable to load accessory popup menu xib in Save as dialog.");
return;
}
}
I encountered a strange error. If I provide the NSSavePanel with a list of fileTypes like this:
NSArray * fileTypes = [NSArray arrayWithObjects: @".tiff", @".pdf", @".jpg", @".png", @".jp2", @".bmp", @".insc", nil];
[savePanel setAllowedFileTypes: fileTypes];
The savePanel will encounter an error when I run it with [NSSavePanel runModal];
When the user selects a different file type from the accessoryView popup menu in the NSSavePanel the method that is executed just does this:
[savePanel setAllowedFileTypes: [NSArray arrayWithObject: [[[sender selectedItem] title] lowercaseString]]];
This changes the file extension when the panel is running modal.