Preventing NSSavePanel from alerting file overwrite

  • Is there a way to block NSSavePanel from alerting a file overwrite?  I¹m
    using it simply to establish a URL and later alert about overwrite when a
    record command is issued.  I would prefer to not have the user see this
    twice.
  • On Jun 6, 2012, at 10:04 AM, Gordon Apple wrote:

    > Is there a way to block NSSavePanel from alerting a file overwrite?  I¹m
    > using it simply to establish a URL and later alert about overwrite when a
    > record command is issued.  I would prefer to not have the user see this
    > twice.

    Implement "panel:userEnteredFilename:confirmed:". Mine returns "nil" because I put up my own dialog, but that also causes the panel to stay up so the user has to enter something else.

    I haven't tried but I'd guess returning a placeholder filename that's known not to exist will also prevent the dialog showing and let the panel close. You can save the incoming filename so you know what the real user choice was, or append a magic extension to mark it as a temporary placeholder for an existing file.
  • Use an NSOpenPanel instead?

    On 6 Jun 2012, at 18:04, Gordon Apple wrote:

    > Is there a way to block NSSavePanel from alerting a file overwrite?  I¹m
    > using it simply to establish a URL and later alert about overwrite when a
    > record command is issued.  I would prefer to not have the user see this
    > twice.
  • On 6 Jun 2012, at 1:03 PM, Lee Ann Rucker wrote:

    > Implement "panel:userEnteredFilename:confirmed:". Mine returns "nil" because I put up my own dialog, but that also causes the panel to stay up so the user has to enter something else.
    >
    > I haven't tried but I'd guess returning a placeholder filename that's known not to exist will also prevent the dialog showing and let the panel close. You can save the incoming filename so you know what the real user choice was, or append a magic extension to mark it as a temporary placeholder for an existing file.

    This is a problem for sandboxing:

    > Open and Save Dialog Behavior with App Sandbox
    >
    > Certain NSOpenPanel and NSSavePanel methods behave differently when App Sandbox is enabled for your app:
    >
    > • You cannot invoke the OK button using the ok: method.
    > • You cannot rewrite the user’s selection using the panel:userEnteredFilename:confirmed: method from the NSOpenSavePanelDelegate protocol.

    <http://developer.apple.com/library/mac/documentation/Security/Conceptual/Ap
    pSandboxDesignGuide/AppSandboxInDepth/AppSandboxInDepth.html#//apple_ref/do
    c/uid/TP40011183-CH3-SW8
    >

    — F
  • On Jun 6, 2012, at 10:04 AM, Gordon Apple <ga...> wrote:

    > Is there a way to block NSSavePanel from alerting a file overwrite?  I¹m
    > using it simply to establish a URL and later alert about overwrite when a
    > record command is issued.  I would prefer to not have the user see this
    > twice.

    No, you can't do that. You should use NSOpenPanel (as someone else mentioned). If you really want to do this, please log a feature request asking us to expose a way to do it.

    corbin
  • So far, I haven¹t been able to get what I want with NSOpenPane.  I will file
    an enhancement request.

    I want the user to specify the record file URL, either new or select one
    existing.  Later, if he decides to actually record, it will simply start
    recording if the file does not already exist.  Otherwise, I present a panel
    with the file path and ask if he wants to overwrite it.  This is so he/she
    can do the prep before starting a live recording, but be reminded if a
    second session is about to overwrite the first (and which is displayed) , so
    he has a chance to apply a new file name.  At record time, if the file
    exist, the new alert can give three choices, cancel, overwrite, or specify a
    new file name.  In this scenario, the initial prep file selection overwrite
    alert is redundant, which is why I would like to eliminate it.

    On 6/6/12 1:12 PM, "Mike Abdullah" <cocoadev...> wrote:

    > Use an NSOpenPanel instead?
    >
    > On 6 Jun 2012, at 18:04, Gordon Apple wrote:
    >
    >>> Is there a way to block NSSavePanel from alerting a file overwrite?  I¹m
    >>> using it simply to establish a URL and later alert about overwrite when a
    >>> record command is issued.  I would prefer to not have the user see this
    >>> twice.
    >
previous month june 2012 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  
Go to today