| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/AppKit.framework |
| Availability | Available in Mac OS X v10.0 and later. |
| Declared in | NSSavePanel.h |
| Companion guides | |
| Related sample code |
An NSSavePanel object creates and manages a Save panel and allows you to run the panel in a modal loop. The Save panel provides a simple way for a user to specify a file to use when saving a document or other data. It can restrict the user to files of a certain type, as specified by an extension.
An NSSavePanel object manages a panel that allows users to specify the directory and name under which a file is saved. It supports browsing of the file system, and it accommodates custom accessory views.
An NSSavePanel object may have a delegate. The methods that delegates of NSSavePanel may implement are specified by the NSOpenSavePanelDelegate protocol.
– accessoryView
– setAccessoryView:
– title
– setTitle:
– prompt
– setPrompt:
– nameFieldLabel
– setNameFieldLabel:
– message
– setMessage:
– canCreateDirectories
– setCanCreateDirectories:
– showsHiddenFiles
– setShowsHiddenFiles:
– delegate
– setDelegate:
– isExtensionHidden
– setExtensionHidden:
– canSelectHiddenExtension
– setCanSelectHiddenExtension:
– allowedFileTypes
– setAllowedFileTypes:
– allowsOtherFileTypes
– setAllowsOtherFileTypes:
– treatsFilePackagesAsDirectories
– setTreatsFilePackagesAsDirectories:
– requiredFileType Deprecated in Mac OS X v10.6
– setRequiredFileType: Deprecated in Mac OS X v10.6
– beginSheetModalForWindow:completionHandler:
– beginWithCompletionHandler:
– runModal
– validateVisibleColumns
– beginSheetForDirectory:file:modalForWindow:modalDelegate:didEndSelector:contextInfo: Deprecated in Mac OS X v10.6
– runModalForDirectory:file: Deprecated in Mac OS X v10.6
– panel:compareFilename:with:caseSensitive: delegate method Deprecated in Mac OS X v10.6
– panel:directoryDidChange: delegate method Deprecated in Mac OS X v10.6
– panel:isValidFilename: delegate method Deprecated in Mac OS X v10.6
– panel:shouldShowFilename: delegate method Deprecated in Mac OS X v10.6
– directoryURL
– setDirectoryURL:
– URL
– isExpanded
– nameFieldStringValue
– setNameFieldStringValue:
– selectText: Deprecated in Mac OS X v10.3
– directory Deprecated in Mac OS X v10.6
– filename Deprecated in Mac OS X v10.6
– setDirectory: Deprecated in Mac OS X v10.6
Returns a Save panel that has been initialized with default values.
+ (NSSavePanel *)savePanel
The initialized Save panel.
NSSavePanel.hReturns the custom accessory view for the current application.
- (NSView *)accessoryView
The custom accessory view for the current application.
In order to free up unused memory after closing the panel, the accessory view is released after the panel is closed. If you rely on the panel to hold onto the accessory view until the next time you use it, the accessory view may be deallocated unexpectedly. If you retain the accessory view in your own code, though, this deallocation should not be a problem.
NSSavePanel.hReturns an array of the allowed file types.
- (NSArray *)allowedFileTypes
An array of the allowed file types.
If the user specifies a file whose type is in the array of allowed types, the user is not presented with another dialog (see allowsOtherFileTypes for details about this dialog) when trying to save. Examples of common file types are “rtf”, “tiff”, and “ps”. File type strings encoding HFS file types are not valid values for this attribute. A nil return value, which is the default, indicates that the user can save to any ASCII file.
NSSavePanel.hReturns a Boolean value that indicates whether the panel allows the user to save files with an extension that’s not in the list of allowed types.
- (BOOL)allowsOtherFileTypes
YES if the panel allows the user to save files with an extension that’s not in the list of allowed types; otherwise, NO.
If the user tries to save a filename with a recognized extension that's not in the list of allowed types they are presented with a dialog. If this method returns YES, then the dialog presents the option of using the extension the user specified.
The default setting is NO.
NSSavePanel.hPresents the panel as a sheet modal to the specified window.
- (void)beginSheetModalForWindow:(NSWindow *)window completionHandler:(void (^)(NSInteger result))handler
The window in which the panel will be presented.
The block called after the user has closed the panel. The argument passed in will be NSFileHandlingPanelOKButton if the user chose the OK button or NSFileHandlingPanelCancelButton if the user chose the Cancel button.
Any properties of the panel you wish to set should be set before calling this method.
NSSavePanel.hPresents the panel as a modeless window.
- (void)beginWithCompletionHandler:(void (^)(NSInteger result))handler
The block called after the user has closed the panel. The argument passed in will be NSFileHandlingPanelOKButton if the user chose the OK button or NSFileHandlingPanelCancelButton if the user chose the Cancel button.
Any properties of the panel you wish to set should be set before calling this method.
NSSavePanel.hThis action method is invoked when the user clicks the panel’s Cancel button.
- (IBAction)cancel:(id)sender
The NSSavePanel object whose Cancel button was clicked.
NSSavePanel.hReturns a Boolean value that indicates whether the panel allows the user to create directories.
- (BOOL)canCreateDirectories
YES when the panel allows the user to create directories; otherwise, NO.
The default value is YES.
NSSavePanel.hReturns a Boolean value that indicates whether the panel allows the user to hide or show extensions.
- (BOOL)canSelectHiddenExtension
YES when the panel allows the user to hide or show extensions; otherwise, NO.
NSSavePanel.hReturns the panel’s delegate.
- (id <NSOpenSavePanelDelegate>)delegate
The panel’s delegate.
NSSavePanel.hReturns the directory shown in the panel as a URL.
- (NSURL *)directoryURL
The directory’s URL.
NSSavePanel.hReturns a Boolean value that indicates whether the panel is expanded.
- (BOOL)isExpanded
YES if the panel is expanded; otherwise, NO.
NSSavePanel.hReturns a Boolean value that indicates whether the extension-hiding checkbox is visible and checked.
- (BOOL)isExtensionHidden
YES when the extension-hiding checkbox is visible and checked; otherwise, NO.
NSSavePanel.hReturns the message displayed in the save panel.
- (NSString *)message
The message displayed in the save panel.
This prompt appears on all NSSavePanel objects (or all NSOpenPanel objects if the receiver of this message is an NSOpenPanel instance) in your application. The default message text is an empty string.
NSSavePanel.hReturns the string displayed in front of the filename text field.
- (NSString *)nameFieldLabel
The string displayed in front of the filename text field.
By default the label is “Save As:”.
NSSavePanel.hReturns the user-editable filename currently shown in the name field.
- (NSString *)nameFieldStringValue
The filename currently selected.
NSSavePanel.hThis action method is invoked when the user clicks the panel’s OK button.
- (IBAction)ok:(id)sender
The NSSavePanel object whose OK button was clicked.
NSSavePanel.hReturns the prompt of the default button.
- (NSString *)prompt
The prompt of the default button.
This prompt appears on all NSSavePanel objects (or all NSOpenPanel objects if the receiver of this message is an NSOpenPanel instance) in your application. By default, the text in the default button is “Open” for an open panel and “Save” for a Save panel.
NSSavePanel.hDisplays the panel and begins its event loop with the current working (or last selected) directory as the default starting point.
- (NSInteger)runModal
NSFileHandlingPanelOKButton (if the user clicks the OK button) or NSFileHandlingPanelCancelButton (if the user clicks the Cancel button).
This method invokes NSApplication‘s runModalForWindow: method with self as the argument.
– runModalForWindow: (NSApplication)NSSavePanel.hCustomizes the panel for the application by adding a custom view to the panel.
- (void)setAccessoryView:(NSView *)aView
View to set as the panel’s accessory view.
The custom object that is added appears just above the OK and Cancel buttons at the bottom of the panel. The NSSavePanel object automatically resizes itself to accommodate aView. You can invoke this method repeatedly to change the accessory view as needed. If aView is nil, the Save panel removes the current accessory view.
NSSavePanel.hSpecifies the allowed file types for the panel.
- (void)setAllowedFileTypes:(NSArray *)types
Array to set as the panel’s array of allowed file types.
The parameter must not be empty. A file type is an extension to be appended to any selected files that don’t already have that extension; “nib” and “rtf” are examples. The items in types should not include the period that begins the extension. File type strings encoding HFS file types are not valid values. Pass nil to allow any file type, which is the default.
NSSavePanel.hSets whether the panel allows the user to save files with an extension that’s not in the list of allowed types.
- (void)setAllowsOtherFileTypes:(BOOL)flag
If YES, the panel allows the user to save files with an extension that’s not in the list of allowed types; if NO, it does not.
If the user tries to save a filename with a recognized extension that's not in the list of allowed types they are presented with a dialog. If allowsOtherFileTypes is YES, then the dialog presents the option of using the extension the user specified.
The default setting is NO.
NSSavePanel.hSets whether the panel allows the user to create directories.
- (void)setCanCreateDirectories:(BOOL)flag
If YES, the panel allows the user to create directories; if NO, the panel does not.
NSSavePanel.hSets whether the panel allows the user to hide or show extensions.
- (void)setCanSelectHiddenExtension:(BOOL)flag
If YES, the panel allows the user to hide or show extensions; if NO, it does not.
This method must be called before the panel is displayed. If set to YES, isExtensionHidden and setExtensionHidden:, respectively, can be used to get and set the value of the checkbox that hides or shows extensions.
NSSavePanel.h
Sets an object as the panel’s delegate, after verifying which delegate methods are implemented.
- (void)setDelegate:(id <NSOpenSavePanelDelegate>)anObject
Object to set as the panel’s delegate.
NSSavePanel.hSets the directory shown in the panel to the directory with the specified URL.
- (void)setDirectoryURL:(NSURL *)url
The URL of the directory to set.
NSSavePanel.hSets the value of the extension-hiding checkbox.
- (void)setExtensionHidden:(BOOL)flag
If YES, the extension-hiding checkbox is visible and checked; if NO, it is not.
This method should rarely be used because the state is saved on a per-application basis. Use this method to set whether a file’s extension should be indicated as being shown.
NSSavePanel.hSets the message text displayed in the panel.
- (void)setMessage:(NSString *)message
String to set as the panel’s message.
This prompt appears on all NSSavePanel objects (or all NSOpenPanel objects if the receiver of this message is an NSOpenPanel instance) in your application. The default message text is an empty string.
NSSavePanel.hSets the text displayed in front of the text field.
- (void)setNameFieldLabel:(NSString *)label
String to set as the text displayed in front of the panel’s text field.
By default the label is “Save As:”.
NSSavePanel.hSets the filename in the name field to the specified value.
- (void)setNameFieldStringValue:(NSString *)value
The filename to set. The value must not be nil.
NSSavePanel.h
Sets the prompt of the default button.
- (void)setPrompt:(NSString *)prompt
String to set as the prompt of the panel’s default button.
This prompt appears on all NSSavePanel objects (or all NSOpenPanel objects if the receiver of this message is an NSOpenPanel instance) in your application. By default, the text in the default button is “Open” for an Open panel and “Save” for a Save panel.
It is intended that short words or phrases, such as “Open,” “Save,” “Set,” or “Choose,” be used on the button. The button is not resized to accommodate long prompts.
Since this method previously affected a title field, any colon at the end of prompt is removed.
NSSavePanel.hSpecifies whether the panel displays files that are normally hidden from the user.
- (void)setShowsHiddenFiles:(BOOL)flag
If YES, the panel displays hidden files; if NO, it does not.
NSSavePanel.hSets the title of the panel.
- (void)setTitle:(NSString *)title
String to set as the panel’s title.
By default, “Save” is the title string. If you adapt the NSSavePanel object for other uses, its title should reflect the user action that brings it to the screen.
NSSavePanel.hSets the panel’s behavior for displaying file packages (for example, MyApp.app) to the user.
- (void)setTreatsFilePackagesAsDirectories:(BOOL)flag
If YES, the panel will display file packages as directories; if NO, it will not.
NSSavePanel.hReturns whether the panel displays files that are normally hidden from the user.
- (BOOL)showsHiddenFiles
YES if the panel displays hidden files; otherwise, NO.
The default value is NO.
NSSavePanel.hReturns the title of the panel.
- (NSString *)title
The title of the panel.
NSSavePanel.hReturns a Boolean value that indicates whether the panel displays file packages as directories.
- (BOOL)treatsFilePackagesAsDirectories
YES if the panel displays file packages as directories; otherwise, NO.
NSSavePanel.hReturns the absolute pathname of the file currently shown in the panel as a URL.
- (NSURL *)URL
The absolute pathname of the file currently shown in the panel as a URL.
NSSavePanel.h
Validates and possibly reloads the browser columns visible in the panel by invoking the delegate method panel:shouldShowFilename:.
- (void)validateVisibleColumns
You might use this method if you want the browser to only allow selection of files with certain extensions based on the selection made in an accessory-view pop-up list. When the user changes the selection, you would invoke this method to revalidate the visible columns.
NSSavePanel.hButton tags that refer to items on the panel.
enum {
NSFileHandlingPanelCancelButton = NSCancelButton,
NSFileHandlingPanelOKButton = NSOKButton
};
NSFileHandlingPanelCancelButtonThe Cancel button.
Available in Mac OS X v10.0 and later.
Declared in NSSavePanel.h.
NSFileHandlingPanelOKButtonThe OK button.
Available in Mac OS X v10.0 and later.
Declared in NSSavePanel.h.
NSFileHandlingPanelImageButtonDeleted in Mac OS X v10.3.
Available in Mac OS X v10.0 through Mac OS X v10.2.
Declared in NSSavePanel.h.
NSFileHandlingPanelTitleFieldDeleted in Mac OS X v10.3.
Available in Mac OS X v10.0 through Mac OS X v10.2.
Declared in NSSavePanel.h.
NSFileHandlingPanelBrowserDeleted in Mac OS X v10.3.
Available in Mac OS X v10.0 through Mac OS X v10.2.
Declared in NSSavePanel.h.
NSFileHandlingPanelFormDeleted in Mac OS X v10.3.
Available in Mac OS X v10.0 through Mac OS X v10.2.
Declared in NSSavePanel.h.
NSFileHandlingPanelHomeButtonDeleted in Mac OS X v10.3.
Available in Mac OS X v10.0 through Mac OS X v10.2.
Declared in NSSavePanel.h.
NSFileHandlingPanelDiskButtonDeleted in Mac OS X v10.3.
Available in Mac OS X v10.0 through Mac OS X v10.2.
Declared in NSSavePanel.h.
NSFileHandlingPanelDiskEjectButtonDeleted in Mac OS X v10.3.
Available in Mac OS X v10.0 through Mac OS X v10.2.
Declared in NSSavePanel.h.
NSSavePanel.h
Last updated: 2009-02-19