Sign in Join
Wiki copytemporary

Cocoa Internals/Dialogs: what changed

Revision 2 to 3. 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-` TCocoaColorPanel.sharedPanel`
29+```
30+ TCocoaColorPanel.sharedPanel
31+```
3032
3133Doing that will cause problems using class methods of the sharedPanel (and likely something else)
3234
3335### No Tags
3436
3537macOS system is using "tags" on files. It seems to be a file system feature that's used commonly in macOS.
3638
3739LCL doesn't have a concept of tags.
3840
3941By 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.
4042
4143### File Type Selection
4244
4345There'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**.
4446
4547The accessory view is used to place the run-time file type selection into the open/save dialog.
4648
4749### File Type Filters
4850
4951There are two ways of filtering out files that can be opened. (Note that "filtering types" is not used when using Save dialog.)
5052
51531\) 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:
5254
5355:* 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).
5456
5557:* 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.
5658
5759
5860As a result of you should not rely on FilterIndex returned. Instead, you should verify the actual contents of the file selected.
5961
60622\) Perform the file check manually through the **panel:shouldEnableURL:** method. Considerations:
6163
6264:* 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))
6365
6466A developer can control what method is used in the application by changing the global variable **CocoaUseUTIFilter** at CocoaWSDialogs unit.
6567
6668- CocoaUseUTIFilter = false (default) - "panel:shouldEnableURL" is used
6769- CocoaUseUTIFilter = true - macOS UTI method is used
6870
6971```Delphi
7072uses
7173 ..
7274 {$ifdef LCLCOCOA}
7375 ,CocoaWSDialogs
7476 {$endif}
7577 ...
7678
7779initialization
7880 {$ifdef LCLCOCOA}
7981 CocoaUseUTIFilter := true;
8082 {$endif}
8183```
8284
8385## File Dialog Options
8486
8587Some of the options are not supported, please refer to the table below for the implementation details
8688
8789**Options**
8890
8991**Supported**
9092
9193**Description**
9294
9395ofReadOnly
9496
9597No
9698
9799ofOverwritePrompt
98100
99101No
100102
101103In macOS prior to 10.15 it was possible to implement the feature by tricking the NSSaveDialog when selecting the name.
102104
103105However, this ability was removed in 10.15 (due to security considerations?)
104106
105107So now, overwrite prompt will always show up
106108
107109ofHideReadOnly
108110
109111No
110112
111113There's no concept of "readOnly" files in macOS filesystems.
112114
113115There's also no configuration in the dialog, to hide files
114116
115117ofNoChangeDir
116118
117119No
118120
119121ofShowHelp
120122
121123No
122124
123125ofNoValidate
124126
125127No
126128
127129ofAllowMultiSelect
128130
129131Yes
130132
131133NSOpenPanel.setAllowsMultipleSelection()
132134
133135ofExtensionDifferent,
134136
135137No
136138
137139ofPathMustExist
138140
139141No
140142
141143ofFileMustExist
142144
143145No
144146
145147ofCreatePrompt
146148
147149No
148150
149151ofShareAware
150152
151153No
152154
153155System native dialogs are always share aware OR act within sandbox allowances
154156
155157ofNoReadOnlyReturn
156158
157159No
158160
159161No concept of "readonly" file
160162
161163ofNoTestFileCreate
162164
163165No
164166
165167ofNoNetworkButton
166168
167169No
168170
169171All shares and networks are available or restricted by SandBox limitations
170172
171173ofNoLongNames
172174
173175No
174176
175177Any file can have long name. OSX never suffered from 8.3 limitation
176178
177179ofOldStyleDialog
178180
179181No
180182
181183There's no old style on macOS ...but, there's an opportunity to use in order to allow some emulation
182184
183185ofNoDereferenceLinks
184186
185187No
186188
187189Links are treated by the system.
188190
189191ofNoResolveLinks
190192
191193No
192194
193195Links are treated by the system
194196
195197ofEnableIncludeNotify
196198
197199No
198200
199201ofEnableSizing
200202
201203No
202204
203205Dialogs are always sizable to the macOS rules
204206
205207ofDontAddToRecent
206208
207209No
208210
209211ofForceShowHidden
210212
211213Yes
212214
213215NSSaveDialog.setShowsHiddenFiles()
214216
215217ofViewDetail
216218
217219No
218220
219221ofAutoPreview
220222
221223No
222224
223225\-
224226
225227(default)
226228
227229canCreateDirectries
228230
229231The feature controls, if a user can create directories within the dialog.
230232
231233Since Windows dialogs allows creation of folders, macOS LCL dialogs also allows the creation at all times.
232234
233235\-
234236
235237(default)
236238
237239extensionHidden
238240
239241The name of the file, selected by the user hides the extension.
240242
241243Since on Windows there's no control over how the file is displayed.
242244
243245The property is left to its system default.
244246
245247\-
246248
247249(default)
248250
249251treatsFilePackagesAsDirectories
250252
251253If set to true, a user can treat (Application) bundles as directories and navigate into the bundle.
252254
253255There's no such concept in LCL, the value is at system default
254256
255257## See Also
256258
257259- [[Cocoa Internals]]
258260
259261---
260262*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).*
261263Category: Cocoa
262264Category: macOS

Back to history