1

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.

Mark
  • 6,647
  • 1
  • 45
  • 88

1 Answers1

1

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.

jbat100
  • 16,757
  • 4
  • 45
  • 70
  • No, `setNameFieldStringValue:` does not work for me (10.7 SDK). The panel opens in the correct directory (`setDirectoryURL:`) works, but does not select the file. However, the deprecated method works as expected: `[panel runModalForDirectory:dir file:file]`... – Mark Nov 26 '11 at 14:30
  • I tried to use a `NSSavePanel` and here `setNameFieldStringValue:` works. An open panel does not have a name field, only a selection list. Is that the problem? – Mark Nov 26 '11 at 14:35