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 | |
Related sample code |
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.
– 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.h
Returns 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.h
Presents 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. An array of types passed in here will override one set using setAllowedFileTypes:
.
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 after the panel’s session has ended, but before dismissing the Open panel. didEndSelector may dismiss the Open panel itself; otherwise, it will be dismissed on return from the method. The corresponding method should have the following 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.h
Presents an Open panel as a sheet with the directory specified by absoluteDirectoryPath and optionally the file specified by filename selected.
- (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. An array of types passed in here will override one set using setAllowedFileTypes:
.
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 after the modal session has ended, but before dismissing the Open panel. didEndSelector may dismiss the Open panel itself; otherwise, it will be dismissed on return from the method. The corresponding method should have the following 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.h
Returns 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.h
Returns 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.h
Displays 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. An array of types passed in here will override one set using setAllowedFileTypes:
.
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 selectable by the user. An array of types passed in here will override one set using setAllowedFileTypes:
.
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.h
Sets whether the user can select multiple files (and directories) at one time for opening to flag.
- (void)setAllowsMultipleSelection:(BOOL)flag
NSOpenPanel.h
Sets 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.h
Sets whether the user can select files in the receiver’s browser.
- (void)setCanChooseFiles:(BOOL)flag
NSOpenPanel.h
Sets 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.h
Returns 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
© 2009 Apple Inc. All Rights Reserved. (Last updated: 2009-02-04)