Mac Developer Library

Developer

AppKit Framework Reference NSOpenSavePanelDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

NSOpenSavePanelDelegate

Inheritance


Not Applicable

Conforms To


Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.6 and later.

The NSOpenSavePanelDelegate protocol defines the methods that a delegate of NSOpenPanel or NSSavePanel should implement.

  • For NSOpenPanel delegates, asks the delegate whether the specified URL should be enabled in the panel. This method is not called for NSSavePanel delegates; all URLs are always disabled.

    Declaration

    Swift

    optional func panel(_ sender: AnyObject, shouldEnableURL url: NSURL) -> Bool

    Objective-C

    - (BOOL)panel:(id)sender shouldEnableURL:(NSURL *)url

    Parameters

    sender

    The panel asking whether the URL should be enabled.

    url

    The URL to be checked.

    Return Value

    YEStrue to allow the URL to be enabled in the panel; otherwise, NOfalse.

    Discussion

    Implementations of this method should be fast to avoid stalling the user interface. Use panel:validateURL:error: instead if processing will take a long time.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • For NSSavePanel delegates, asks the delegate for file URL validation when the user chooses the Save button. For NSOpenPanel delegates, asks the delegate for file URL validation once for each selected filename (or directory) when the user chooses the Open button.

    Declaration

    Swift

    optional func panel(_ sender: AnyObject, validateURL url: NSURL, error outError: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)panel:(id)sender validateURL:(NSURL *)url error:(NSError **)outError

    Parameters

    sender

    The panel requesting URL validation.

    url

    The URL to be validated.

    outError

    If an error occurred during validation, the error that occurred.

    Return Value

    YEStrue if the URL is an acceptable URL to save to or to open; otherwise, NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Informs the delegate that the user changed the selected directory to the directory located at the specified URL. The URL may be nil if the current URL can’t be represented by an NSURL object.

    Declaration

    Swift

    optional func panel(_ sender: AnyObject!, didChangeToDirectoryURL url: NSURL?)

    Objective-C

    - (void)panel:(id)sender didChangeToDirectoryURL:(NSURL *)url

    Parameters

    sender

    The panel whose directory changed.

    url

    The URL of the new directory, or nil if it can’t be represented by an NSURL object.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Tells the delegate that the user confirmed a filename choice by clicking Save in a Save panel.

    Declaration

    Swift

    optional func panel(_ sender: AnyObject, userEnteredFilename filename: String, confirmed okFlag: Bool) -> String?

    Objective-C

    - (NSString *)panel:(id)sender userEnteredFilename:(NSString *)filename confirmed:(BOOL)okFlag

    Parameters

    sender

    The panel reporting the user’s confirmation of a filename choice.

    filename

    The user’s filename choice.

    okFlag

    If YEStrue, the user clicked the Save button; if NOfalse, the user did not.

    Return Value

    You can either leave the filename alone, or return nil to cancel the save and leave the Save panel as is. (If your app is not running in a sandbox, you can also sanitize the filename to remove undesirable characters, limit its length, and so on.)

    This method is called before any required extension is appended to the filename and before the Save panel asks the user to replace an existing file, if applicable.

    This method may be called multiple times in the sessions as the user types. In those cases, okFlag will be NOfalse until the user confirms the choice, in which case okFlag will become YEStrue. If the delegate does extensive validation or puts up alerts, it should do so only when okFlag is YEStrue.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Tells the delegate that the Save panel is about to expand or collapse because the user clicked the disclosure triangle that displays or hides the file browser.

    Declaration

    Swift

    optional func panel(_ sender: AnyObject, willExpand expanding: Bool)

    Objective-C

    - (void)panel:(id)sender willExpand:(BOOL)expanding

    Parameters

    sender

    The panel that is about to expand or collapse.

    expanding

    YEStrue specifies that the panel is expanding; NOfalse specifies that it is collapsing.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Tells the delegate that the user changed the selection in the specified Save panel.

    Declaration

    Swift

    optional func panelSelectionDidChange(_ sender: AnyObject?)

    Objective-C

    - (void)panelSelectionDidChange:(id)sender

    Parameters

    sender

    The panel whose selection changed.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

    Available as part of an informal protocol prior to OS X v10.6.