Cocoa Internals/Dialogs
Common Considerations
Modality
Neither of the Cocoa dialogs (OpenFile, SaveFile, Font or Color) are modal!
Meaning that one can open a dialog and keep using the other application windows and the application menu.
This doesn't work well, if the LCL design, where each dialog is opened by Execute method, which doesn't return until the modal dialog is closed.
For this particular reason, Cocoa WS does the following:
- every dialog is called as the application modal window (preventing other windows of the application from getting any user input)
- the application menu is disabled, until the dialog is closed
- where applicable add "Ok" and "Cancel" buttons are added to dialogs. Indicating a user that the dialog can be closed in order to make the selection.
No restoration
Starting with macOS 10.7 Cocoa will attempt to restore the Application windows between Launches.
It's a nice user feature, which conflicts with LCL. Since LCL adds custom controls to a dialog, and the restoration requires a special "restorationClass" to be provided.
Instead of restoring dialogs, CocoaWS explicitly forbids the restoration of them.
Class Override
Unlike NSApplication, dialog classes cannot be overwritten in the following manner:
TCocoaColorPanel.sharedPanel
Doing that will cause problems using class methods of the sharedPanel (and likely something else)
File Name Completion
The file name returned should be as following:
- the returned path should be the full path
- the file name extension should be set according to the following rules:
- if file type is selected
- if the type extension of the filter is not a wild card - use the file extension. If multiple extensions are provided in the filter, use the first extension
- if the type extension is a wild card, use DefaultExt property
- if file type is not selected used DefaultExt property
File Dialog Options
Some of the options are not supported, please refer to the table below for the implementation details
Options | Supported | Description |
---|---|---|
ofReadOnly | No | |
ofOverwritePrompt | No | In macOS prior to 10.15 it was possible to implement the feature by tricking the NSSaveDialog when selecting the name.
However, this ability was removed in 10.15 (due to security considerations?) So now, overwrite prompt will always show up |
ofHideReadOnly | No | There's no concept of "readOnly" files in macOS filesystems.
There's also no configuration in the dialog, to hide files |
ofNoChangeDir | No | |
ofShowHelp | No | |
ofNoValidate | No | |
ofAllowMultiSelect | Yes | NSOpenPanel.setAllowsMultipleSelection() |
ofExtensionDifferent, | No | |
ofPathMustExist | No | |
ofFileMustExist | No | |
ofCreatePrompt | No | |
ofShareAware | No | System native dialogs are always share aware OR act within sandbox allowances |
ofNoReadOnlyReturn | No | No concept of "readonly" file |
ofNoTestFileCreate | No | |
ofNoNetworkButton | No | All shares and networks are available or restricted by SandBox limitations |
ofNoLongNames | No | Any file can have long name. OSX never suffered from 8.3 limitation |
ofOldStyleDialog | No | There's no old style on macOS
...but, there's an opportunity to use in order to allow some emulation |
ofNoDereferenceLinks | No | Links are treated by the system. |
ofNoResolveLinks | No | Links are treated by the system |
ofEnableIncludeNotify | No | |
ofEnableSizing | No | Dialogs are always sizable to the macOS rules |
ofDontAddToRecent | No | |
ofForceShowHidden | Yes | NSSaveDialog.setShowsHiddenFiles() |
ofViewDetail | No | |
ofAutoPreview | No |