Up

# NSOpenPanel

### Authors

Scott Christley (`scottc@net-community.com`)
Daniel Boehringer (`boehring@biomed.ruhr-uni-bochum.de`)
Nicola Pero (`n.pero@mi.flashnet.it`)
Mirko Viviani (`mirko.viviani@rccr.cremona.it`)

> Standard panel for opening files

Copyright: (C) 1996, 1998, 1999, 2000 Free Software Foundation, Inc.

# Software documentation for the NSOpenPanel class

## NSOpenPanel : NSSavePanel

> Declared in:
>   AppKit/NSOpenPanel.h

Availability: OpenStep

Implements a panel that allows the user to select a file or files. NSOpenPanel is based on the NSSavePanel implementation and shares a lot of similarities with it.

There is only one open panel per application and this panel is obtained by calling the +openPanel class method. From here, you should set the characteristics of the file selection mechanism using the -setCanChooseFiles: , -setCanChooseDirectories: and -setAllowsMultipleSelection: methods. The default is `YES` except for allowing multiple selection. When ready to show the panel, use the -runModalForTypes: , or a similar method to show the panel in a modal session. Other methods allow you to set the initial directory and initially selected file. The method will return one of NSOKButton or NSCancelButton depending on which button the user pressed.

Use the [NSSavePanel -filename] or -filenames method to retrieve the name of the file the user selected.

Instance Variables
Method summary

- +openPanel
- -URLs
- -allowsMultipleSelection
- -beginForDirectory:file:types:modelessDelegate:didEndSelector:contextInfo:
- -beginSheetForDirectory:file:types:modalForWindow:modalDelegate:didEndSelector:contextInfo:
- -canChooseDirectories
- -canChooseFiles
- -filenames
- -resolvesAliases
- -runModalForDirectory:file:types:
- -runModalForDirectory:file:types:relativeToWindow:
- -runModalForTypes:
- -setAllowsMultipleSelection:
- -setCanChooseDirectories:
- -setCanChooseFiles:
- -setResolvesAliases:

### openPanel

+ (NSOpenPanel*) openPanel;
Availability: OpenStep

Creates (if needed) and returns the shared NSOpenPanel instance.

### URLs

- (NSArray*) URLs;
Availability: MacOS-X 10.0.0
Returns an array of the selected files as URLs

### allowsMultipleSelection

- (BOOL) allowsMultipleSelection;
Availability: OpenStep

Returns `YES` if the user is allowed to select multiple files. The default behavior is not to allow mutiple selections.

See Also: -setAllowsMultipleSelection: [NSBrowser -allowsMultipleSelection]

### beginForDirectory: file: types: modelessDelegate: didEndSelector: contextInfo:

- (void) beginForDirectory: (NSString*)path file: (NSString*)filename types: (NSArray*)fileTypes modelessDelegate: (id)modelessDelegate didEndSelector: (SEL)didEndSelector contextInfo: (void*)contextInfo;
Availability: MacOS-X 10.3.0
Description forthcoming.

### beginSheetForDirectory: file: types: modalForWindow: modalDelegate: didEndSelector: contextInfo:

- (void) beginSheetForDirectory: (NSString*)path file: (NSString*)name types: (NSArray*)fileTypes modalForWindow: (NSWindow*)docWindow modalDelegate: (id)delegate didEndSelector: (SEL)didEndSelector contextInfo: (void*)contextInfo;
Availability: MacOS-X 10.0.0
Description forthcoming.

### canChooseDirectories

- (BOOL) canChooseDirectories;
Availability: OpenStep

Returns `YES` if the user is allowed to choose directories The default behavior is to allow choosing directories.

See Also: -setCanChooseDirectories:

### canChooseFiles

- (BOOL) canChooseFiles;
Availability: OpenStep

Returns `YES` if the user is allowed to choose files. The default behavior it to allow choosing files.

See Also: -setCanChooseFiles:

### filenames

- (NSArray*) filenames;
Availability: OpenStep

Returns an array containing the absolute paths (as NSString objects) of the selected files and directories. If multiple selections aren't allowed, the array contains a single name.

### resolvesAliases

- (BOOL) resolvesAliases;
Availability: MacOS-X 10.1.0
Description forthcoming.

### runModalForDirectory: file: types:

- (NSInteger) runModalForDirectory: (NSString*)path file: (NSString*)name types: (NSArray*)fileTypes;
Availability: OpenStep

Displays the open panel in a modal session, with the directory path shown and file name (if any) selected. Files are filtered for the specified types. If the directory is `nil`, then the directory shown in the open panel is the last directory selected.

See Also: -runModalForTypes:

### runModalForDirectory: file: types: relativeToWindow:

- (NSInteger) runModalForDirectory: (NSString*)path file: (NSString*)name types: (NSArray*)fileTypes relativeToWindow: (NSWindow*)window;
Availability: MacOS-X 10.0.0
Description forthcoming.

### runModalForTypes:

- (NSInteger) runModalForTypes: (NSArray*)fileTypes;
Availability: OpenStep

Displays the open panel in a modal session, showing the current directory (or last selected), and filtering for files that have the specified types.

See Also: -runModalForDirectory:file:types:

### setAllowsMultipleSelection:

- (void) setAllowsMultipleSelection: (BOOL)flag;
Availability: OpenStep

Allows the user to select multiple files if flag is `YES`. The default behavior is not to allow multiple selections

See Also: -allowsMultipleSelection [NSBrowser -setAllowsMultipleSelection:]

### setCanChooseDirectories:

- (void) setCanChooseDirectories: (BOOL)flag;
Availability: OpenStep

Allows the user to choose directories if flag is `YES`. The default behavior is to allow choosing directories.

See Also: -canChooseDirectories [NSBrowser -setAllowsBranchSelection:]

### setCanChooseFiles:

- (void) setCanChooseFiles: (BOOL)flag;
Availability: OpenStep

Allows the user to choose files if flag is `YES`.The default behavior it to allow choosing files.

See Also: -canChooseFiles

### setResolvesAliases:

- (void) setResolvesAliases: (BOOL)flag;
Availability: MacOS-X 10.1.0
Description forthcoming.

## Instance Variables for NSOpenPanel Class

### _canChooseDirectories

@protected BOOL _canChooseDirectories;
Availability: OpenStep
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

### _canChooseFiles

@protected BOOL _canChooseFiles;
Availability: OpenStep
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

Up