Skip to content

NSSavePanel

Ken Harris edited this page Jan 26, 2019 · 1 revision

When running inside PowerBox, NSSavePanel runs as a separate service. Most of the time, this doesn't matter, but there's a couple cases to be aware of:

  • First, NSOpenSavePanelDelegate is in many cases useless. You can't look at the file selected by the user, before they've OK'd the panel, so you get selection-change notifications but you can't do much with them.

  • Second, the directoryURL field (as noted in NSSavePanel.h, but not the API documentation) is set asynchronously. This has some interesting consequences. The service seems to share some not-well-defined internal state between callers. If you set this field to one URL, and then another, before showing the panel, the second one will seem to be ignored. (Working hypothesis: it will block the sheet if it's nil but has been set to a non-nil value, but won't block if it's non-nil and changing to another non-nil value!) Or if you open a file NSOpenPanel with one directoryURL, and then later open a new directory NSOpenPanel with a directoryURL = the previous file's parent, it'll start out selecting the file (bizarre). (These both seem like bugs to me, but they're present even in 2019 so you aren't going to be able to ignore them any time soon.)

    Easy workaround: at the end of every NSSavePanel completion handler, do: NSOpenPanel().directoryURL=nil

Clone this wiki locally