Mark
Mark

Reputation: 6947

NSOpenPanel/NSSavePanel: How can I preselect a file before the dialog opens?

When I present a NSOpenPanel to the user I'd like it to have a file that the user opened earlier already selected from the start.

There is [NSSavePanel setDirectoryURL:(NSURL*) to preselect a directory, but I can't find an API to select the initial file.

There use to be:

- (NSInteger)runModalForDirectory:(NSString *)path file:(NSString *)filename

This call is exactly what I need. The docs say:

Specifies a particular file in path that is selected when the Save panel is presented to a user. When nil, no file is initially selected.

But unfortunately that method was deprecated in 10.6.

Upvotes: 1

Views: 989

Answers (1)

jbat100
jbat100

Reputation: 16827

Do these NSSavePanel methods

- (void)setDirectoryURL:(NSURL *)url
- (void)setNameFieldStringValue:(NSString *)value

not do what you want?

NSOpenPanel is a subclass of NSSavePanel so it has these methods also.

Upvotes: 1

Related Questions