Good default directory for UI.savepanel()?

On a Mac, using nil for the directory will cause openpanel and savepanel to use the same folder as the last invocation. If the user navigates to another directory to select something, that directory will be used again when nil is passed, even if the user cancelled the last dialog. This last used directory is saved somewhere in the system (I haven’t checked where as it doesn’t really matter) and it will be used again the next time you run SketchUp. In other words, it does not reset per-session to something like your home directory or other hard-wired default.

There are additional Mac quirks/bugs that are not mentioned in the API documentation. As with many other (ahem) “features” of the Mac SU implementation, these were things done by the SU developers, they are not universal to OS X or required by the Mac GUI style:

UI.openpanel ignores the title argument. There isn’t even a place in the dialog for a title to appear. It also doesn’t support wildcard patterns for the filename and there is no place for a selection list to appear anyway. In fact, the filename argument appears to have no effect at all; it isn’t pre-selected and the user can choose anything. This seems harmless, as the method just returns a path, it doesn’t actually open anything, but lack of filters means you have to verify what file type the user selected.

UI.savepanel does display the title at the top of the dialog. If you pass a filename, it will be seeded as the initial value in the “Save As” field. Wildcards are not accepted, in fact they will cause the dialog to hang without displaying! If a file with that name already exists in the selected directory, you will get a “file already exists, overwrite?” dialog - even though no overwrite will actually happen! And again, for lack of filters you can’t prevent the user from choosing or entering a filetype that you don’t know how to save.

4 Likes