Sign in Join
Wiki copytemporary

Cocoa Internals/Dialogs: what changed

Revision 3 to 4. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11## Common Considerations
22
33### Modality
44
55None of the Cocoa dialogs (OpenFile, SaveFile, Font or Color) are modal!
66
77This means that one can open a dialog and keep using the other application windows and the application menu.
88
99This 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.
1010
1111For this particular reason, Cocoa WS does the following:
1212
1313- every dialog is called as the application modal window (preventing other windows of the application from getting any user input);
1414- the application menu is disabled, until the dialog is closed;
1515- 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.
1616
1717### No restoration
1818
1919Starting with macOS 10.7 Cocoa will attempt to restore the Application windows between Launches.
2020
2121It'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.
2222
2323Instead of restoring dialogs, CocoaWS explicitly forbids the restoration of them.
2424
2525### Class Override
2626
2727Unlike NSApplication, dialog classes cannot be overwritten in the following manner:
2828
29-```
29+```text
3030 TCocoaColorPanel.sharedPanel
3131```
3232
3333Doing that will cause problems using class methods of the sharedPanel (and likely something else)
3434
3535### No Tags
3636
3737macOS system is using "tags" on files. It seems to be a file system feature that's used commonly in macOS.
3838
3939LCL doesn't have a concept of tags.
4040
4141By 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.
4242
4343### File Type Selection
4444
4545There'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**.
4646
4747The accessory view is used to place the run-time file type selection into the open/save dialog.
4848
4949### File Type Filters
5050
5151There are two ways of filtering out files that can be opened. (Note that "filtering types" is not used when using Save dialog.)
5252
53531\) 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:
5454
5555:* 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).
5656
5757:* 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.
5858
5959
6060As a result of you should not rely on FilterIndex returned. Instead, you should verify the actual contents of the file selected.
6161
62622\) Perform the file check manually through the **panel:shouldEnableURL:** method. Considerations:
6363
6464:* 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))
6565
6666A developer can control what method is used in the application by changing the global variable **CocoaUseUTIFilter** at CocoaWSDialogs unit.
6767
6868- CocoaUseUTIFilter = false (default) - "panel:shouldEnableURL" is used
6969- CocoaUseUTIFilter = true - macOS UTI method is used
7070
7171```Delphi
7272uses
7373 ..
7474 {$ifdef LCLCOCOA}
7575 ,CocoaWSDialogs
7676 {$endif}
7777 ...
7878
7979initialization
8080 {$ifdef LCLCOCOA}
8181 CocoaUseUTIFilter := true;
8282 {$endif}
8383```
8484
8585## File Dialog Options
8686
8787Some of the options are not supported, please refer to the table below for the implementation details
8888
8989**Options**
9090
9191**Supported**
9292
9393**Description**
9494
9595ofReadOnly
9696
9797No
9898
9999ofOverwritePrompt
100100
101101No
102102
103103In macOS prior to 10.15 it was possible to implement the feature by tricking the NSSaveDialog when selecting the name.
104104
105105However, this ability was removed in 10.15 (due to security considerations?)
106106
107107So now, overwrite prompt will always show up
108108
109109ofHideReadOnly
110110
111111No
112112
113113There's no concept of "readOnly" files in macOS filesystems.
114114
115115There's also no configuration in the dialog, to hide files
116116
117117ofNoChangeDir
118118
119119No
120120
121121ofShowHelp
122122
123123No
124124
125125ofNoValidate
126126
127127No
128128
129129ofAllowMultiSelect
130130
131131Yes
132132
133133NSOpenPanel.setAllowsMultipleSelection()
134134
135135ofExtensionDifferent,
136136
137137No
138138
139139ofPathMustExist
140140
141141No
142142
143143ofFileMustExist
144144
145145No
146146
147147ofCreatePrompt
148148
149149No
150150
151151ofShareAware
152152
153153No
154154
155155System native dialogs are always share aware OR act within sandbox allowances
156156
157157ofNoReadOnlyReturn
158158
159159No
160160
161161No concept of "readonly" file
162162
163163ofNoTestFileCreate
164164
165165No
166166
167167ofNoNetworkButton
168168
169169No
170170
171171All shares and networks are available or restricted by SandBox limitations
172172
173173ofNoLongNames
174174
175175No
176176
177177Any file can have long name. OSX never suffered from 8.3 limitation
178178
179179ofOldStyleDialog
180180
181181No
182182
183183There's no old style on macOS ...but, there's an opportunity to use in order to allow some emulation
184184
185185ofNoDereferenceLinks
186186
187187No
188188
189189Links are treated by the system.
190190
191191ofNoResolveLinks
192192
193193No
194194
195195Links are treated by the system
196196
197197ofEnableIncludeNotify
198198
199199No
200200
201201ofEnableSizing
202202
203203No
204204
205205Dialogs are always sizable to the macOS rules
206206
207207ofDontAddToRecent
208208
209209No
210210
211211ofForceShowHidden
212212
213213Yes
214214
215215NSSaveDialog.setShowsHiddenFiles()
216216
217217ofViewDetail
218218
219219No
220220
221221ofAutoPreview
222222
223223No
224224
225225\-
226226
227227(default)
228228
229229canCreateDirectries
230230
231231The feature controls, if a user can create directories within the dialog.
232232
233233Since Windows dialogs allows creation of folders, macOS LCL dialogs also allows the creation at all times.
234234
235235\-
236236
237237(default)
238238
239239extensionHidden
240240
241241The name of the file, selected by the user hides the extension.
242242
243243Since on Windows there's no control over how the file is displayed.
244244
245245The property is left to its system default.
246246
247247\-
248248
249249(default)
250250
251251treatsFilePackagesAsDirectories
252252
253253If set to true, a user can treat (Application) bundles as directories and navigate into the bundle.
254254
255255There's no such concept in LCL, the value is at system default
256256
257257## See Also
258258
259259- [[Cocoa Internals]]
260260
261261---
262262*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).*
263263Category: Cocoa
264264Category: macOS

Back to history