| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/AppKit.framework |
| Availability | Available in Mac OS X v10.0 and later.
|
| Declared in | NSOpenPanel.h |
| Companion guides |
The NSOpenPanel class provides the Open panel for the Cocoa user interface. Applications use the Open panel as a convenient way to query the user for the name of a file to open. The Open panel can only be run modally.
– canChooseFiles
– setCanChooseFiles:
– canChooseDirectories
– setCanChooseDirectories:
– resolvesAliases
– setResolvesAliases:
– allowsMultipleSelection
– setAllowsMultipleSelection:
– beginForDirectory:file:types:modelessDelegate:didEndSelector:contextInfo:
– beginSheetForDirectory:file:types:modalForWindow:modalDelegate:didEndSelector:contextInfo:
– runModalForDirectory:file:types:
– runModalForTypes:
Creates and returns a NSOpenPanel object.
+ (NSOpenPanel *)openPanel
Initialized Open panel.
The open panel has been initialized with default values.
NSOpenPanel.hReturns whether the receiver’s browser allows the user to open multiple files (and directories) at a time.
- (BOOL)allowsMultipleSelection
If multiple files or directories are allowed, then the filename method—inherited from NSSavePanel—returns a non-nil value only if one and only one file is selected. By contrast, NSOpenPanel’s filenames method always returns the selected files, even if only one file is selected.
– filename (NSSavePanel)– filenames– setAllowsMultipleSelection:NSOpenPanel.hPresents a modeless Open panel.
- (void)beginForDirectory:(NSString *)absoluteDirectoryPath file:(NSString *)filename types:(NSArray *)fileTypes modelessDelegate:(id)modelessDelegate didEndSelector:(SEL)didEndSelector contextInfo:(void *)contextInfo
Directory whose files the panel displays. When nil, the directory is the same directory used in the previous invocation of the panel; this is probably the best choice for most situations.
Specifies a particular file in absoluteDirectoryPath that is selected when the Open panel is presented to the user. When nil, no file is initially selected.
Array of file extensions and/or HFS file types. Specifies the files the panel allows the user to select. nil makes all files in absoluteDirectoryPath selectable by the user.
This is not the same as a delegate assigned to the panel. This delegate is temporary and the relationship only lasts until the panel is dismissed.
Message sent to modelessDelegate when the panel operation ends. The corresponding method should have the signature:
- (void)openPanelDidEnd:(NSOpenPanel *)panel returnCode:(int)returnCode contextInfo:(void *)contextInfo |
The value passed as returnCode will be either NSCancelButton or NSOKButton.
Context information passed to modelessDelegate in the didEndSelector message.
Similar to beginSheetForDirectory:file:types:modalForWindow:modalDelegate:didEndSelector:contextInfo:, but allows for modeless operation of the panel.
NSOpenPanel.hPresents a sheet Open panel on a given window.
- (void)beginSheetForDirectory:(NSString *)absoluteDirectoryPath file:(NSString *)filename types:(NSArray *)fileTypes modalForWindow:(NSWindow *)docWindow modalDelegate:(id)modalDelegate didEndSelector:(SEL)didEndSelector contextInfo:(void *)contextInfo
Directory whose files the panel displays. When nil, the directory is the same directory used in the previous invocation of the panel; this is probably the best choice for most situations.
Specifies a particular file in absoluteDirectoryPath that is selected when the Open panel is presented to the user. When nil, no file is initially selected.
Array of file extensions and/or HFS file types. Specifies the files the panel allows the user to select. nil makes all files in absoluteDirectoryPath selectable by the user.
Window to open the sheet on.
This is not the same as a delegate assigned to the panel. This delegate is temporary and the relationship only lasts until the panel is dismissed..
Message sent to modalDelegate when the panel operation ends. The corresponding method should have the signature:
- (void)openPanelDidEnd:(NSOpenPanel *)panel returnCode:(int)returnCode contextInfo:(void *)contextInfo |
The value passed as returnCode will be either NSCancelButton or NSOKButton.
Context information passed to modalDelegate in the didEndSelector message.
NSOpenPanel.h
Returns whether the receiver allows the user to choose directories to open.
- (BOOL)canChooseDirectories
NSOpenPanel.h
Returns whether the receiver allows the user to choose files to open.
- (BOOL)canChooseFiles
NSOpenPanel.hReturns an array containing the absolute paths (as NSString objects) of the selected files and directories.
- (NSArray *)filenames
If multiple selections aren’t allowed, the array contains a single name. The filenames method is preferable over NSSavePanel’s filename to get the name or names of files and directories that the user has selected.
NSOpenPanel.hReturns whether the receiver resolves aliases.
- (BOOL)resolvesAliases
If YES, the effect is that dropping an alias on the receiver or asking for filenames or URLs returns the resolved aliases. The default is YES.
NSOpenPanel.hDisplays the receiver and begins a modal event loop that is terminated when the user clicks either OK or Cancel.
- (NSInteger)runModalForDirectory:(NSString *)absoluteDirectoryPath file:(NSString *)filename types:(NSArray *)fileTypes
Directory whose files the panel displays. When nil, the directory is the same directory used in the previous invocation of the panel; this is probably the best choice for most situations.
Specifies a particular file in absoluteDirectoryPath that is selected when the Open panel is presented to the user. When nil, no file is initially selected.
Array of file extensions and/or HFS file types. Specifies the files the panel allows the user to select. nil makes all files in absoluteDirectoryPath selectable by the user.
Button clicked to dismiss the dialog: NSOKButton for the OK button and NSCancelButton for the Cancel button.
You can control whether directories and files appear in the browser with the setCanChooseDirectories: and setCanChooseFiles: methods.
NSOpenPanel.h
Displays the receiver and begins a modal event loop that is terminated when the user clicks either OK or Cancel.
- (NSInteger)runModalForTypes:(NSArray *)fileTypes
Array of file extensions and/or HFS file types. Specifies the files the panel allows the user to select. nil makes all files in absoluteDirectoryPath selectable by the user.
Button used to dismiss the dialog: NSOKButton for the OK button and NSCancelButton for the Cancel button.
This convenience method sends runModalForDirectory:nil file:nil types:fileTypes to the receiver. See runModalForDirectory:file:types: for additional details.
NSOpenPanel.hSets whether the user can select multiple files (and directories) at one time for opening to flag.
- (void)setAllowsMultipleSelection:(BOOL)flag
NSOpenPanel.hSets whether the user can select directories in the receiver’s browser.
- (void)setCanChooseDirectories:(BOOL)flag
When a directory is selected, the OK button is enabled only if flag is YES.
NSOpenPanel.hSets whether the user can select files in the receiver’s browser.
- (void)setCanChooseFiles:(BOOL)flag
NSOpenPanel.hSets whether the receiver resolves aliases to resolvesAliases.
- (void)setResolvesAliases:(BOOL)resolvesAliases
If YES, the effect is that dropping an alias on the receiver or asking for filenames or URLs returns the resolved aliases. Set this value to NO to allow selection of aliases without resolving.
NSOpenPanel.hReturns an array containing the absolute paths of the selected files and directories as URLs.
- (NSArray *)URLs
If multiple selections aren’t allowed, the array contains a single name.
NSOpenPanel.h
Last updated: 2007-04-03