With NSSavePanel, how can the user choose a specific file type to save?
Asked Answered
V

1

8

I am writing an application in Cocoa which allows the user to export data in 3 different formats: CSV, JSON, and XML. I have added the allowed extensions to an NSSavePanel:

NSSavePanel* saveFile = [NSSavePanel savePanel];
NSArray* extensions = [[NSArray alloc] initWithObjects:@"csv", @"json" @"xml", nil];
[saveFile setAllowedFileTypes:extensions];

However, how can I set up the NSSavePanel to allow the user to select which format to save in, such as in TextEdit where a "File format" list box is offered? If this is possible, how would I then determine which format had been selected?

Vender answered 10/5, 2012 at 12:0 Comment(0)
S
9

You can add a user-defined NSView to the NSSavePanel using setAccessoryView:, see Apple's docs. There is also an Apple sample Custom Save. You add your format selection controls to this accessory view.

Schadenfreude answered 11/5, 2012 at 10:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.