Sign in Join
Wiki copytemporary

Cocoa Internals/Dialogs: what changed

Revision 1 to 2. 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
2929` TCocoaColorPanel.sharedPanel`
3030
3131Doing that will cause problems using class methods of the sharedPanel (and likely something else)
3232
3333### No Tags
3434
3535macOS system is using "tags" on files. It seems to be a file system feature that's used commonly in macOS.
3636
3737LCL doesn't have a concept of tags.
3838
3939By 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.
4040
4141### File Type Selection
4242
4343There'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**.
4444
4545The accessory view is used to place the run-time file type selection into the open/save dialog.
4646
4747### File Type Filters
4848
4949There are two ways of filtering out files that can be opened. (Note that "filtering types" is not used when using Save dialog.)
5050
51511\) 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:
5252
5353:* 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).
5454
5555:* 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.
5656
5757
5858As a result of you should not rely on FilterIndex returned. Instead, you should verify the actual contents of the file selected.
5959
60602\) Perform the file check manually through the **panel:shouldEnableURL:** method. Considerations:
6161
6262:* 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))
6363
6464A developer can control what method is used in the application by changing the global variable **CocoaUseUTIFilter** at CocoaWSDialogs unit.
6565
6666- CocoaUseUTIFilter = false (default) - "panel:shouldEnableURL" is used
6767- CocoaUseUTIFilter = true - macOS UTI method is used
6868
6969```Delphi
7070uses
7171 ..
7272 {$ifdef LCLCOCOA}
7373 ,CocoaWSDialogs
7474 {$endif}
7575 ...
7676
7777initialization
7878 {$ifdef LCLCOCOA}
7979 CocoaUseUTIFilter := true;
8080 {$endif}
8181```
8282
8383## File Dialog Options
8484
8585Some of the options are not supported, please refer to the table below for the implementation details
8686
87-<table>
88-<thead>
89-<tr>
90-<th><p>Options</p></th>
91-<th><p>Supported</p></th>
92-<th><p>Description</p></th>
93-</tr>
94-</thead>
95-<tbody>
96-<tr>
97-<td><p>ofReadOnly</p></td>
98-<td><p>No</p></td>
99-<td></td>
100-</tr>
101-<tr>
102-<td><p>ofOverwritePrompt</p></td>
103-<td><p>No</p></td>
104-<td><p>In macOS prior to 10.15 it was possible to implement the feature by tricking the NSSaveDialog when selecting the name.</p>
105-<p>However, this ability was removed in 10.15 (due to security considerations?)</p>
106-<p>So now, overwrite prompt will always show up</p></td>
107-</tr>
108-<tr>
109-<td><p>ofHideReadOnly</p></td>
110-<td><p>No</p></td>
111-<td><p>There's no concept of "readOnly" files in macOS filesystems.</p>
112-<p>There's also no configuration in the dialog, to hide files</p></td>
113-</tr>
114-<tr>
115-<td><p>ofNoChangeDir</p></td>
116-<td><p>No</p></td>
117-<td></td>
118-</tr>
119-<tr>
120-<td><p>ofShowHelp</p></td>
121-<td><p>No</p></td>
122-<td></td>
123-</tr>
124-<tr>
125-<td><p>ofNoValidate</p></td>
126-<td><p>No</p></td>
127-<td></td>
128-</tr>
129-<tr>
130-<td><p>ofAllowMultiSelect</p></td>
131-<td><p>Yes</p></td>
132-<td><p>NSOpenPanel.setAllowsMultipleSelection()</p></td>
133-</tr>
134-<tr>
135-<td><p>ofExtensionDifferent,</p></td>
136-<td><p>No</p></td>
137-<td></td>
138-</tr>
139-<tr>
140-<td><p>ofPathMustExist</p></td>
141-<td><p>No</p></td>
142-<td></td>
143-</tr>
144-<tr>
145-<td><p>ofFileMustExist</p></td>
146-<td><p>No</p></td>
147-<td></td>
148-</tr>
149-<tr>
150-<td><p>ofCreatePrompt</p></td>
151-<td><p>No</p></td>
152-<td></td>
153-</tr>
154-<tr>
155-<td><p>ofShareAware</p></td>
156-<td><p>No</p></td>
157-<td><p>System native dialogs are always share aware OR act within sandbox allowances</p></td>
158-</tr>
159-<tr>
160-<td><p>ofNoReadOnlyReturn</p></td>
161-<td><p>No</p></td>
162-<td><p>No concept of "readonly" file</p></td>
163-</tr>
164-<tr>
165-<td><p>ofNoTestFileCreate</p></td>
166-<td><p>No</p></td>
167-<td></td>
168-</tr>
169-<tr>
170-<td><p>ofNoNetworkButton</p></td>
171-<td><p>No</p></td>
172-<td><p>All shares and networks are available or restricted by SandBox limitations</p></td>
173-</tr>
174-<tr>
175-<td><p>ofNoLongNames</p></td>
176-<td><p>No</p></td>
177-<td><p>Any file can have long name. OSX never suffered from 8.3 limitation</p></td>
178-</tr>
179-<tr>
180-<td><p>ofOldStyleDialog</p></td>
181-<td><p>No</p></td>
182-<td><p>There's no old style on macOS ...but, there's an opportunity to use in order to allow some emulation</p></td>
183-</tr>
184-<tr>
185-<td><p>ofNoDereferenceLinks</p></td>
186-<td><p>No</p></td>
187-<td><p>Links are treated by the system.</p></td>
188-</tr>
189-<tr>
190-<td><p>ofNoResolveLinks</p></td>
191-<td><p>No</p></td>
192-<td><p>Links are treated by the system</p></td>
193-</tr>
194-<tr>
195-<td><p>ofEnableIncludeNotify</p></td>
196-<td><p>No</p></td>
197-<td></td>
198-</tr>
199-<tr>
200-<td><p>ofEnableSizing</p></td>
201-<td><p>No</p></td>
202-<td><p>Dialogs are always sizable to the macOS rules</p></td>
203-</tr>
204-<tr>
205-<td><p>ofDontAddToRecent</p></td>
206-<td><p>No</p></td>
207-<td></td>
208-</tr>
209-<tr>
210-<td><p>ofForceShowHidden</p></td>
211-<td><p>Yes</p></td>
212-<td><p>NSSaveDialog.setShowsHiddenFiles()</p></td>
213-</tr>
214-<tr>
215-<td><p>ofViewDetail</p></td>
216-<td><p>No</p></td>
217-<td></td>
218-</tr>
219-<tr>
220-<td><p>ofAutoPreview</p></td>
221-<td><p>No</p></td>
222-<td></td>
223-</tr>
224-<tr>
225-<td><p>-</p></td>
226-<td><p>(default)</p></td>
227-<td><p>canCreateDirectries</p>
228-<p>The feature controls, if a user can create directories within the dialog.</p>
229-<p>Since Windows dialogs allows creation of folders, macOS LCL dialogs also allows the creation at all times.</p></td>
230-</tr>
231-<tr>
232-<td><p>-</p></td>
233-<td><p>(default)</p></td>
234-<td><p>extensionHidden</p>
235-<p>The name of the file, selected by the user hides the extension.</p>
236-<p>Since on Windows there's no control over how the file is displayed.</p>
237-<p>The property is left to its system default.</p></td>
238-</tr>
239-<tr>
240-<td><p>-</p></td>
241-<td><p>(default)</p></td>
242-<td><p>treatsFilePackagesAsDirectories</p>
243-<p>If set to true, a user can treat (Application) bundles as directories and navigate into the bundle.</p>
244-<p>There's no such concept in LCL, the value is at system default</p></td>
245-</tr>
246-</tbody>
247-</table>
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
248254
249255## See Also
250256
251257- [[Cocoa Internals]]
252258
253259---
254260*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).*
255261Category: Cocoa
256262Category: macOS

Back to history