Cocoa Internals/Dialogs: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | ## Common Considerations | |
| 2 | 2 | ||
| 3 | 3 | ### Modality | |
| 4 | 4 | ||
| 5 | 5 | None of the Cocoa dialogs (OpenFile, SaveFile, Font or Color) are modal! | |
| 6 | 6 | ||
| 7 | 7 | This means that one can open a dialog and keep using the other application windows and the application menu. | |
| 8 | 8 | ||
| 9 | 9 | This doesn't work well with the LCL design, where each dialog is opened by an **Execute** method which doesn't return until the modal dialog is closed. | |
| 10 | 10 | ||
| 11 | 11 | For this particular reason, Cocoa WS does the following: | |
| 12 | 12 | ||
| 13 | 13 | - every dialog is called as the application modal window (preventing other windows of the application from getting any user input); | |
| 14 | 14 | - the application menu is disabled, until the dialog is closed; | |
| 15 | 15 | - where applicable, "Ok" and "Cancel" buttons are added to dialogs to indicate to a user that the dialog can be closed to make the selection. | |
| 16 | 16 | ||
| 17 | 17 | ### No restoration | |
| 18 | 18 | ||
| 19 | 19 | Starting with macOS 10.7 Cocoa will attempt to restore the Application windows between Launches. | |
| 20 | 20 | ||
| 21 | 21 | 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. | |
| 22 | 22 | ||
| 23 | 23 | Instead of restoring dialogs, CocoaWS explicitly forbids the restoration of them. | |
| 24 | 24 | ||
| 25 | 25 | ### Class Override | |
| 26 | 26 | ||
| 27 | 27 | Unlike NSApplication, dialog classes cannot be overwritten in the following manner: | |
| 28 | 28 | ||
| 29 | 29 | ` TCocoaColorPanel.sharedPanel` | |
| 30 | 30 | ||
| 31 | 31 | Doing that will cause problems using class methods of the sharedPanel (and likely something else) | |
| 32 | 32 | ||
| 33 | 33 | ### No Tags | |
| 34 | 34 | ||
| 35 | 35 | macOS system is using "tags" on files. It seems to be a file system feature that's used commonly in macOS. | |
| 36 | 36 | ||
| 37 | 37 | LCL doesn't have a concept of tags. | |
| 38 | 38 | ||
| 39 | 39 | By default Save dialog is showing a user an ability to select a tag. Since LCL cannot handle it properly (it cannot return the value, nor it has APIs to save the value), the dialog hides the tag selection, by default. | |
| 40 | 40 | ||
| 41 | 41 | ### File Type Selection | |
| 42 | 42 | ||
| 43 | 43 | There's no "native" file type selection in macOS dialogs. Instead, there's an opportunity to add "custom options" to an open/save dialog, known as **accessory view**. | |
| 44 | 44 | ||
| 45 | 45 | The accessory view is used to place the run-time file type selection into the open/save dialog. | |
| 46 | 46 | ||
| 47 | 47 | ### File Type Filters | |
| 48 | 48 | ||
| 49 | 49 | There are two ways of filtering out files that can be opened. (Note that "filtering types" is not used when using Save dialog.) | |
| 50 | 50 | ||
| 51 | 51 | 1\) Assign the list of file extensions or file types (UTI's) via the **setAllowedFileTypes:** method. Allowing "any" file can be achieved by using the **setAllowsOtherFileTypes:** method. Considerations: | |
| 52 | 52 | ||
| 53 | 53 | :* a filter is assigned by "generic type" rather than extension. And thus specifying "txt" as a filter, will assign "public.plain-text" type. Which might correspond to other file extensions other than "txt" file. (i.e. ".pas" files might also be allowed, as they are part of "public.plain-text" group). | |
| 54 | 54 | ||
| 55 | 55 | :* setAllowedFileTypes - is unable to verify compound extensions, such as "tar.gz". In which case the filter configured for ".tag.gz" and a filter configured for ".gz" will provide the exactly the same set of files for selection. | |
| 56 | 56 | ||
| 57 | 57 | ||
| 58 | 58 | As a result of you should not rely on FilterIndex returned. Instead, you should verify the actual contents of the file selected. | |
| 59 | 59 | ||
| 60 | 60 | 2\) Perform the file check manually through the **panel:shouldEnableURL:** method. Considerations: | |
| 61 | 61 | ||
| 62 | 62 | :* starting with macOS 10.15, there's a security change done in macOS. Save/Open file dialogs are executed in a separate process. Passing the information between the main process and the dialog process introduces a certain lag. If a great number of files, it becomes noticeable for the user. Thus it's possible that not all files might be "available" for the selection as the check runs slowly. (see [issue \#38399](https://bugs.freepascal.org/view.php?id=38399)) | |
| 63 | 63 | ||
| 64 | 64 | A developer can control what method is used in the application by changing the global variable **CocoaUseUTIFilter** at CocoaWSDialogs unit. | |
| 65 | 65 | ||
| 66 | 66 | - CocoaUseUTIFilter = false (default) - "panel:shouldEnableURL" is used | |
| 67 | 67 | - CocoaUseUTIFilter = true - macOS UTI method is used | |
| 68 | 68 | ||
| 69 | 69 | ```Delphi | |
| 70 | 70 | uses | |
| 71 | 71 | .. | |
| 72 | 72 | {$ifdef LCLCOCOA} | |
| 73 | 73 | ,CocoaWSDialogs | |
| 74 | 74 | {$endif} | |
| 75 | 75 | ... | |
| 76 | 76 | ||
| 77 | 77 | initialization | |
| 78 | 78 | {$ifdef LCLCOCOA} | |
| 79 | 79 | CocoaUseUTIFilter := true; | |
| 80 | 80 | {$endif} | |
| 81 | 81 | ``` | |
| 82 | 82 | ||
| 83 | 83 | ## File Dialog Options | |
| 84 | 84 | ||
| 85 | 85 | Some of the options are not supported, please refer to the table below for the implementation details | |
| 86 | 86 | ||
| 87 | - | ||
| 88 | - | ||
| 89 | - | ||
| 90 | - | ||
| 91 | - | ||
| 92 | - | ||
| 93 | - | ||
| 94 | - | ||
| 95 | - | ||
| 96 | - | ||
| 97 | - | ||
| 98 | - | ||
| 99 | - | ||
| 100 | - | ||
| 101 | - | ||
| 102 | - | ||
| 103 | - | ||
| 104 | - | ||
| 105 | - | ||
| 106 | - | ||
| 107 | - | ||
| 108 | - | ||
| 109 | - | ||
| 110 | - | ||
| 111 | - | ||
| 112 | - | ||
| 113 | - | ||
| 114 | - | ||
| 115 | - | ||
| 116 | - | ||
| 117 | - | ||
| 118 | - | ||
| 119 | - | ||
| 120 | - | ||
| 121 | - | ||
| 122 | - | ||
| 123 | - | ||
| 124 | - | ||
| 125 | - | ||
| 126 | - | ||
| 127 | - | ||
| 128 | - | ||
| 129 | - | ||
| 130 | - | ||
| 131 | - | ||
| 132 | - | ||
| 133 | - | ||
| 134 | - | ||
| 135 | - | ||
| 136 | - | ||
| 137 | - | ||
| 138 | - | ||
| 139 | - | ||
| 140 | - | ||
| 141 | - | ||
| 142 | - | ||
| 143 | - | ||
| 144 | - | ||
| 145 | - | ||
| 146 | - | ||
| 147 | - | ||
| 148 | - | ||
| 149 | - | ||
| 150 | - | ||
| 151 | - | ||
| 152 | - | ||
| 153 | - | ||
| 154 | - | ||
| 155 | - | ||
| 156 | - | ||
| 157 | - | ||
| 158 | - | ||
| 159 | - | ||
| 160 | - | ||
| 161 | - | ||
| 162 | - | ||
| 163 | - | ||
| 164 | - | ||
| 165 | - | ||
| 166 | - | ||
| 167 | - | ||
| 168 | - | ||
| 169 | - | ||
| 170 | - | ||
| 171 | - | ||
| 172 | - | ||
| 173 | - | ||
| 174 | - | ||
| 175 | - | ||
| 176 | - | ||
| 177 | - | ||
| 178 | - | ||
| 179 | - | ||
| 180 | - | ||
| 181 | - | ||
| 182 | - | ||
| 183 | - | ||
| 184 | - | ||
| 185 | - | ||
| 186 | - | ||
| 187 | - | ||
| 188 | - | ||
| 189 | - | ||
| 190 | - | ||
| 191 | - | ||
| 192 | - | ||
| 193 | - | ||
| 194 | - | ||
| 195 | - | ||
| 196 | - | ||
| 197 | - | ||
| 198 | - | ||
| 199 | - | ||
| 200 | - | ||
| 201 | - | ||
| 202 | - | ||
| 203 | - | ||
| 204 | - | ||
| 205 | - | ||
| 206 | - | ||
| 207 | - | ||
| 208 | - | ||
| 209 | - | ||
| 210 | - | ||
| 211 | - | ||
| 212 | - | ||
| 213 | - | ||
| 214 | - | ||
| 215 | - | ||
| 216 | - | ||
| 217 | - | ||
| 218 | - | ||
| 219 | - | ||
| 220 | - | ||
| 221 | - | ||
| 222 | - | ||
| 223 | - | ||
| 224 | - | ||
| 225 | - | ||
| 226 | - | ||
| 227 | - | ||
| 228 | - | ||
| 229 | - | ||
| 230 | - | ||
| 231 | - | ||
| 232 | - | ||
| 233 | - | ||
| 234 | - | ||
| 235 | - | ||
| 236 | - | ||
| 237 | - | ||
| 238 | - | ||
| 239 | - | ||
| 240 | - | ||
| 241 | - | ||
| 242 | - | ||
| 243 | - | ||
| 244 | - | ||
| 245 | - | ||
| 246 | - | ||
| 247 | - | ||
| 87 | + | **Options** | |
| 88 | + | ||
| 89 | + | **Supported** | |
| 90 | + | ||
| 91 | + | **Description** | |
| 92 | + | ||
| 93 | + | ofReadOnly | |
| 94 | + | ||
| 95 | + | No | |
| 96 | + | ||
| 97 | + | ofOverwritePrompt | |
| 98 | + | ||
| 99 | + | No | |
| 100 | + | ||
| 101 | + | In macOS prior to 10.15 it was possible to implement the feature by tricking the NSSaveDialog when selecting the name. | |
| 102 | + | ||
| 103 | + | However, this ability was removed in 10.15 (due to security considerations?) | |
| 104 | + | ||
| 105 | + | So now, overwrite prompt will always show up | |
| 106 | + | ||
| 107 | + | ofHideReadOnly | |
| 108 | + | ||
| 109 | + | No | |
| 110 | + | ||
| 111 | + | There's no concept of "readOnly" files in macOS filesystems. | |
| 112 | + | ||
| 113 | + | There's also no configuration in the dialog, to hide files | |
| 114 | + | ||
| 115 | + | ofNoChangeDir | |
| 116 | + | ||
| 117 | + | No | |
| 118 | + | ||
| 119 | + | ofShowHelp | |
| 120 | + | ||
| 121 | + | No | |
| 122 | + | ||
| 123 | + | ofNoValidate | |
| 124 | + | ||
| 125 | + | No | |
| 126 | + | ||
| 127 | + | ofAllowMultiSelect | |
| 128 | + | ||
| 129 | + | Yes | |
| 130 | + | ||
| 131 | + | NSOpenPanel.setAllowsMultipleSelection() | |
| 132 | + | ||
| 133 | + | ofExtensionDifferent, | |
| 134 | + | ||
| 135 | + | No | |
| 136 | + | ||
| 137 | + | ofPathMustExist | |
| 138 | + | ||
| 139 | + | No | |
| 140 | + | ||
| 141 | + | ofFileMustExist | |
| 142 | + | ||
| 143 | + | No | |
| 144 | + | ||
| 145 | + | ofCreatePrompt | |
| 146 | + | ||
| 147 | + | No | |
| 148 | + | ||
| 149 | + | ofShareAware | |
| 150 | + | ||
| 151 | + | No | |
| 152 | + | ||
| 153 | + | System native dialogs are always share aware OR act within sandbox allowances | |
| 154 | + | ||
| 155 | + | ofNoReadOnlyReturn | |
| 156 | + | ||
| 157 | + | No | |
| 158 | + | ||
| 159 | + | No concept of "readonly" file | |
| 160 | + | ||
| 161 | + | ofNoTestFileCreate | |
| 162 | + | ||
| 163 | + | No | |
| 164 | + | ||
| 165 | + | ofNoNetworkButton | |
| 166 | + | ||
| 167 | + | No | |
| 168 | + | ||
| 169 | + | All shares and networks are available or restricted by SandBox limitations | |
| 170 | + | ||
| 171 | + | ofNoLongNames | |
| 172 | + | ||
| 173 | + | No | |
| 174 | + | ||
| 175 | + | Any file can have long name. OSX never suffered from 8.3 limitation | |
| 176 | + | ||
| 177 | + | ofOldStyleDialog | |
| 178 | + | ||
| 179 | + | No | |
| 180 | + | ||
| 181 | + | There's no old style on macOS ...but, there's an opportunity to use in order to allow some emulation | |
| 182 | + | ||
| 183 | + | ofNoDereferenceLinks | |
| 184 | + | ||
| 185 | + | No | |
| 186 | + | ||
| 187 | + | Links are treated by the system. | |
| 188 | + | ||
| 189 | + | ofNoResolveLinks | |
| 190 | + | ||
| 191 | + | No | |
| 192 | + | ||
| 193 | + | Links are treated by the system | |
| 194 | + | ||
| 195 | + | ofEnableIncludeNotify | |
| 196 | + | ||
| 197 | + | No | |
| 198 | + | ||
| 199 | + | ofEnableSizing | |
| 200 | + | ||
| 201 | + | No | |
| 202 | + | ||
| 203 | + | Dialogs are always sizable to the macOS rules | |
| 204 | + | ||
| 205 | + | ofDontAddToRecent | |
| 206 | + | ||
| 207 | + | No | |
| 208 | + | ||
| 209 | + | ofForceShowHidden | |
| 210 | + | ||
| 211 | + | Yes | |
| 212 | + | ||
| 213 | + | NSSaveDialog.setShowsHiddenFiles() | |
| 214 | + | ||
| 215 | + | ofViewDetail | |
| 216 | + | ||
| 217 | + | No | |
| 218 | + | ||
| 219 | + | ofAutoPreview | |
| 220 | + | ||
| 221 | + | No | |
| 222 | + | ||
| 223 | + | \- | |
| 224 | + | ||
| 225 | + | (default) | |
| 226 | + | ||
| 227 | + | canCreateDirectries | |
| 228 | + | ||
| 229 | + | The feature controls, if a user can create directories within the dialog. | |
| 230 | + | ||
| 231 | + | Since Windows dialogs allows creation of folders, macOS LCL dialogs also allows the creation at all times. | |
| 232 | + | ||
| 233 | + | \- | |
| 234 | + | ||
| 235 | + | (default) | |
| 236 | + | ||
| 237 | + | extensionHidden | |
| 238 | + | ||
| 239 | + | The name of the file, selected by the user hides the extension. | |
| 240 | + | ||
| 241 | + | Since on Windows there's no control over how the file is displayed. | |
| 242 | + | ||
| 243 | + | The property is left to its system default. | |
| 244 | + | ||
| 245 | + | \- | |
| 246 | + | ||
| 247 | + | (default) | |
| 248 | + | ||
| 249 | + | treatsFilePackagesAsDirectories | |
| 250 | + | ||
| 251 | + | If set to true, a user can treat (Application) bundles as directories and navigate into the bundle. | |
| 252 | + | ||
| 253 | + | There's no such concept in LCL, the value is at system default | |
| 248 | 254 | ||
| 249 | 255 | ## See Also | |
| 250 | 256 | ||
| 251 | 257 | - [[Cocoa Internals]] | |
| 252 | 258 | ||
| 253 | 259 | --- | |
| 254 | 260 | *From the Free Pascal wiki, page "Cocoa Internals/Dialogs", as it stood on 2021-01-30 after a change by Skalogryz, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* | |
| 255 | 261 | Category: Cocoa | |
| 256 | 262 | Category: macOS |
