|
7 | 7 | } |
8 | 8 |
|
9 | 9 | {* |
10 | | - * # CategoryDialog |
11 | | - * |
12 | | - * File dialog support. |
| 10 | +* # CategoryDialog |
| 11 | +* |
| 12 | +* File dialog support. |
| 13 | +* |
| 14 | +* SDL offers file dialogs, to let users select files with native GUI |
| 15 | +* interfaces. There are "open" dialogs, "save" dialogs, and folder selection |
| 16 | +* dialogs. The app can control some details, such as filtering to specific |
| 17 | +* files, or whether multiple files can be selected by the user. |
| 18 | +* |
| 19 | +* Note that launching a file dialog is a non-blocking operation; control |
| 20 | +* returns to the app immediately, and a callback is called later (possibly in |
| 21 | +* another thread) when the user makes a choice. |
13 | 22 | } |
14 | 23 |
|
15 | 24 | {* |
@@ -132,107 +141,177 @@ procedure SDL_ShowOpenFileDialog(callback: TSDL_DialogFileCallback; userdata: Po |
132 | 141 | external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ShowOpenFileDialog' {$ENDIF} {$ENDIF}; |
133 | 142 |
|
134 | 143 | {* |
135 | | - * Displays a dialog that lets the user choose a new or existing file on their |
136 | | - * filesystem. |
137 | | - * |
138 | | - * This function should only be invoked from the main thread. |
139 | | - * |
140 | | - * This is an asynchronous function; it will return immediately, and the |
141 | | - * result will be passed to the callback. |
142 | | - * |
143 | | - * The callback will be invoked with a null-terminated list of files the user |
144 | | - * chose. The list will be empty if the user canceled the dialog, and it will |
145 | | - * be nil if an error occurred. |
146 | | - * |
147 | | - * Note that the callback may be called from a different thread than the one |
148 | | - * the function was invoked on. |
149 | | - * |
150 | | - * The chosen file may or may not already exist. |
151 | | - * |
152 | | - * On Linux, dialogs may require XDG Portals, which requires DBus, which |
153 | | - * requires an event-handling loop. Apps that do not use SDL to handle events |
154 | | - * should add a call to SDL_PumpEvents in their main loop. |
155 | | - * |
156 | | - * \param callback an SDL_DialogFileCallback to be invoked when the user |
157 | | - * selects a file and accepts, or cancels the dialog, or an |
158 | | - * error occurs. The first argument is a null-terminated list |
159 | | - * of C strings, representing the paths chosen by the user. |
160 | | - * The list will be empty if the user canceled the dialog, and |
161 | | - * it will be nil if an error occurred. If an error occurred, |
162 | | - * it can be fetched with SDL_GetError(). The second argument |
163 | | - * is the userdata Pointer passed to the function. The third |
164 | | - * argument is the index of the filter selected by the user, |
165 | | - * or one past the index of the last filter (therefore the |
166 | | - * index of the terminating nil filter) if no filter was |
167 | | - * chosen, or -1 if the platform does not support detecting |
168 | | - * the selected filter. |
169 | | - * \param userdata an optional Pointer to pass extra data to the callback when |
170 | | - * it will be invoked. |
171 | | - * \param window the window that the dialog should be modal for, may be nil. |
172 | | - * Not all platforms support this option. |
173 | | - * \param filters a list of SDL_DialogFileFilter's, may be nil. Not all |
174 | | - * platforms support this option, and platforms that do support |
175 | | - * it may allow the user to ignore the filters. |
176 | | - * \param nfilters the number of filters. Ignored if filters is nil. |
177 | | - * \param default_location the default folder or file to start the dialog at, |
178 | | - * may be nil. Not all platforms support this option. |
179 | | - * |
180 | | - * \since This function is available since SDL 3.1.3. |
181 | | - * |
182 | | - * \sa SDL_DialogFileCallback |
183 | | - * \sa SDL_DialogFileFilter |
184 | | - * \sa SDL_ShowOpenFileDialog |
185 | | - * \sa SDL_ShowOpenFolderDialog |
| 144 | +* Displays a dialog that lets the user choose a new or existing file on their |
| 145 | +* filesystem. |
| 146 | +* |
| 147 | +* This is an asynchronous function; it will return immediately, and the |
| 148 | +* result will be passed to the callback. |
| 149 | +* |
| 150 | +* The callback will be invoked with a null-terminated list of files the user |
| 151 | +* chose. The list will be empty if the user canceled the dialog, and it will |
| 152 | +* be NULL if an error occurred. |
| 153 | +* |
| 154 | +* Note that the callback may be called from a different thread than the one |
| 155 | +* the function was invoked on. |
| 156 | +* |
| 157 | +* The chosen file may or may not already exist. |
| 158 | +* |
| 159 | +* On Linux, dialogs may require XDG Portals, which requires DBus, which |
| 160 | +* requires an event-handling loop. Apps that do not use SDL to handle events |
| 161 | +* should add a call to SDL_PumpEvents in their main loop. |
| 162 | +* |
| 163 | +* \param callback a function pointer to be invoked when the user selects a |
| 164 | +* file and accepts, or cancels the dialog, or an error |
| 165 | +* occurs. |
| 166 | +* \param userdata an optional pointer to pass extra data to the callback when |
| 167 | +* it will be invoked. |
| 168 | +* \param window the window that the dialog should be modal for, may be NULL. |
| 169 | +* Not all platforms support this option. |
| 170 | +* \param filters a list of filters, may be NULL. Not all platforms support |
| 171 | +* this option, and platforms that do support it may allow the |
| 172 | +* user to ignore the filters. If non-NULL, it must remain |
| 173 | +* valid at least until the callback is invoked. |
| 174 | +* \param nfilters the number of filters. Ignored if filters is NULL. |
| 175 | +* \param default_location the default folder or file to start the dialog at, |
| 176 | +* may be NULL. Not all platforms support this option. |
| 177 | +* |
| 178 | +* \threadsafety This function should be called only from the main thread. The |
| 179 | +* callback may be invoked from the same thread or from a |
| 180 | +* different one, depending on the OS's constraints. |
| 181 | +* |
| 182 | +* \since This function is available since SDL 3.2.0. |
| 183 | +* |
| 184 | +* \sa SDL_DialogFileCallback |
| 185 | +* \sa SDL_DialogFileFilter |
| 186 | +* \sa SDL_ShowOpenFileDialog |
| 187 | +* \sa SDL_ShowOpenFolderDialog |
| 188 | +* \sa SDL_ShowFileDialogWithProperties |
186 | 189 | } |
187 | 190 | procedure SDL_ShowSaveFileDialog(callback: TSDL_DialogFileCallback; userdata: Pointer; window: PSDL_Window; filters: PSDL_DialogFileFilter; nfilters: cint; default_location: PAnsiChar); cdecl; |
188 | 191 | external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ShowSaveFileDialog' {$ENDIF} {$ENDIF}; |
189 | 192 |
|
190 | 193 | {* |
191 | | - * Displays a dialog that lets the user select a folder on their filesystem. |
192 | | - * |
193 | | - * This function should only be invoked from the main thread. |
194 | | - * |
195 | | - * This is an asynchronous function; it will return immediately, and the |
196 | | - * result will be passed to the callback. |
197 | | - * |
198 | | - * The callback will be invoked with a null-terminated list of files the user |
199 | | - * chose. The list will be empty if the user canceled the dialog, and it will |
200 | | - * be nil if an error occurred. |
201 | | - * |
202 | | - * Note that the callback may be called from a different thread than the one |
203 | | - * the function was invoked on. |
| 194 | +* Displays a dialog that lets the user select a folder on their filesystem. |
| 195 | +* |
| 196 | +* This is an asynchronous function; it will return immediately, and the |
| 197 | +* result will be passed to the callback. |
| 198 | +* |
| 199 | +* The callback will be invoked with a null-terminated list of files the user |
| 200 | +* chose. The list will be empty if the user canceled the dialog, and it will |
| 201 | +* be NULL if an error occurred. |
| 202 | +* |
| 203 | +* Note that the callback may be called from a different thread than the one |
| 204 | +* the function was invoked on. |
| 205 | +* |
| 206 | +* Depending on the platform, the user may be allowed to input paths that |
| 207 | +* don't yet exist. |
| 208 | +* |
| 209 | +* On Linux, dialogs may require XDG Portals, which requires DBus, which |
| 210 | +* requires an event-handling loop. Apps that do not use SDL to handle events |
| 211 | +* should add a call to SDL_PumpEvents in their main loop. |
| 212 | +* |
| 213 | +* \param callback a function pointer to be invoked when the user selects a |
| 214 | +* file and accepts, or cancels the dialog, or an error |
| 215 | +* occurs. |
| 216 | +* \param userdata an optional pointer to pass extra data to the callback when |
| 217 | +* it will be invoked. |
| 218 | +* \param window the window that the dialog should be modal for, may be NULL. |
| 219 | +* Not all platforms support this option. |
| 220 | +* \param default_location the default folder or file to start the dialog at, |
| 221 | +* may be NULL. Not all platforms support this option. |
| 222 | +* \param allow_many if non-zero, the user will be allowed to select multiple |
| 223 | +* entries. Not all platforms support this option. |
| 224 | +* |
| 225 | +* \threadsafety This function should be called only from the main thread. The |
| 226 | +* callback may be invoked from the same thread or from a |
| 227 | +* different one, depending on the OS's constraints. |
| 228 | +* |
| 229 | +* \since This function is available since SDL 3.2.0. |
| 230 | +* |
| 231 | +* \sa SDL_DialogFileCallback |
| 232 | +* \sa SDL_ShowOpenFileDialog |
| 233 | +* \sa SDL_ShowSaveFileDialog |
| 234 | +* \sa SDL_ShowFileDialogWithProperties |
| 235 | + } |
| 236 | +procedure SDL_ShowOpenFolderDialog(callback: TSDL_DialogFileCallback; userdata: Pointer; window: PSDL_Window; default_location: PAnsiChar; allow_many: cbool); cdecl; |
| 237 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ShowOpenFolderDialog' {$ENDIF} {$ENDIF}; |
| 238 | + |
| 239 | +{* |
| 240 | + * Various types of file dialogs. |
204 | 241 | * |
205 | | - * Depending on the platform, the user may be allowed to input paths that |
206 | | - * don't yet exist. |
| 242 | + * This is used by SDL_ShowFileDialogWithProperties() to decide what kind of |
| 243 | + * dialog to present to the user. |
207 | 244 | * |
208 | | - * On Linux, dialogs may require XDG Portals, which requires DBus, which |
209 | | - * requires an event-handling loop. Apps that do not use SDL to handle events |
210 | | - * should add a call to SDL_PumpEvents in their main loop. |
| 245 | + * \since This enum is available since SDL 3.2.0. |
211 | 246 | * |
212 | | - * \param callback an SDL_DialogFileCallback to be invoked when the user |
213 | | - * selects a file and accepts, or cancels the dialog, or an |
214 | | - * error occurs. The first argument is a null-terminated list |
215 | | - * of C strings, representing the paths chosen by the user. |
216 | | - * The list will be empty if the user canceled the dialog, and |
217 | | - * it will be nil if an error occurred. If an error occurred, |
218 | | - * it can be fetched with SDL_GetError(). The second argument |
219 | | - * is the userdata Pointer passed to the function. The third |
220 | | - * argument is always -1 for SDL_ShowOpenFolderDialog. |
| 247 | + * \sa SDL_ShowFileDialogWithProperties |
| 248 | + } |
| 249 | +type |
| 250 | + PPSDL_FileDialogType = ^PSDL_FileDialogType; |
| 251 | + PSDL_FileDialogType = ^TSDL_FileDialogType; |
| 252 | + TSDL_FileDialogType = type Integer; |
| 253 | +const |
| 254 | + SDL_FILEDIALOG_OPENFILE = TSDL_FileDialogType(0); |
| 255 | + SDL_FILEDIALOG_SAVEFILE = TSDL_FileDialogType(1); |
| 256 | + SDL_FILEDIALOG_OPENFOLDER = TSDL_FileDialogType(2); |
| 257 | + |
| 258 | +{* |
| 259 | + * Create and launch a file dialog with the specified properties. |
| 260 | + * |
| 261 | + * These are the supported properties: |
| 262 | + * |
| 263 | + * - `SDL_PROP_FILE_DIALOG_FILTERS_POINTER`: a Pointer to a list of |
| 264 | + * SDL_DialogFileFilter structs, which will be used as filters for |
| 265 | + * file-based selections. Ignored if the dialog is an "Open Folder" dialog. |
| 266 | + * If non-nil, the array of filters must remain valid at least until the |
| 267 | + * callback is invoked. |
| 268 | + * - `SDL_PROP_FILE_DIALOG_NFILTERS_NUMBER`: the number of filters in the |
| 269 | + * array of filters, if it exists. |
| 270 | + * - `SDL_PROP_FILE_DIALOG_WINDOW_POINTER`: the window that the dialog should |
| 271 | + * be modal for. |
| 272 | + * - `SDL_PROP_FILE_DIALOG_LOCATION_STRING`: the default folder or file to |
| 273 | + * start the dialog at. |
| 274 | + * - `SDL_PROP_FILE_DIALOG_MANY_BOOLEAN`: true to allow the user to select |
| 275 | + * more than one entry. |
| 276 | + * - `SDL_PROP_FILE_DIALOG_TITLE_STRING`: the title for the dialog. |
| 277 | + * - `SDL_PROP_FILE_DIALOG_ACCEPT_STRING`: the label that the accept button |
| 278 | + * should have. |
| 279 | + * - `SDL_PROP_FILE_DIALOG_CANCEL_STRING`: the label that the cancel button |
| 280 | + * should have. |
| 281 | + * |
| 282 | + * Note that each platform may or may not support any of the properties. |
| 283 | + * |
| 284 | + * \param type the type of file dialog. |
| 285 | + * \param callback a function Pointer to be invoked when the user selects a |
| 286 | + * file and accepts, or cancels the dialog, or an error |
| 287 | + * occurs. |
221 | 288 | * \param userdata an optional Pointer to pass extra data to the callback when |
222 | 289 | * it will be invoked. |
223 | | - * \param window the window that the dialog should be modal for, may be nil. |
224 | | - * Not all platforms support this option. |
225 | | - * \param default_location the default folder or file to start the dialog at, |
226 | | - * may be nil. Not all platforms support this option. |
227 | | - * \param allow_many if non-zero, the user will be allowed to select multiple |
228 | | - * entries. Not all platforms support this option. |
| 290 | + * \param props the properties to use. |
229 | 291 | * |
230 | | - * \since This function is available since SDL 3.1.3. |
| 292 | + * \threadsafety This function should be called only from the main thread. The |
| 293 | + * callback may be invoked from the same thread or from a |
| 294 | + * different one, depending on the OS's constraints. |
231 | 295 | * |
| 296 | + * \since This function is available since SDL 3.2.0. |
| 297 | + * |
| 298 | + * \sa SDL_FileDialogType |
232 | 299 | * \sa SDL_DialogFileCallback |
| 300 | + * \sa SDL_DialogFileFilter |
233 | 301 | * \sa SDL_ShowOpenFileDialog |
234 | 302 | * \sa SDL_ShowSaveFileDialog |
| 303 | + * \sa SDL_ShowOpenFolderDialog |
235 | 304 | } |
236 | | -procedure SDL_ShowOpenFolderDialog(callback: TSDL_DialogFileCallback; userdata: Pointer; window: PSDL_Window; default_location: PAnsiChar; allow_many: cbool); cdecl; |
237 | | - external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ShowOpenFolderDialog' {$ENDIF} {$ENDIF}; |
| 305 | +procedure SDL_ShowFileDialogWithProperties(type_: TSDL_FileDialogType; callback: TSDL_DialogFileCallback; userdata: Pointer; props: TSDL_PropertiesID); cdecl; |
| 306 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ShowFileDialogWithProperties' {$ENDIF} {$ENDIF}; |
| 307 | + |
| 308 | +const |
| 309 | + SDL_PROP_FILE_DIALOG_FILTERS_POINTER = 'SDL.filedialog.filters'; |
| 310 | + SDL_PROP_FILE_DIALOG_NFILTERS_NUMBER = 'SDL.filedialog.nfilters'; |
| 311 | + SDL_PROP_FILE_DIALOG_WINDOW_POINTER = 'SDL.filedialog.window'; |
| 312 | + SDL_PROP_FILE_DIALOG_LOCATION_STRING = 'SDL.filedialog.location'; |
| 313 | + SDL_PROP_FILE_DIALOG_MANY_BOOLEAN = 'SDL.filedialog.many'; |
| 314 | + SDL_PROP_FILE_DIALOG_TITLE_STRING = 'SDL.filedialog.title'; |
| 315 | + SDL_PROP_FILE_DIALOG_ACCEPT_STRING = 'SDL.filedialog.accept'; |
| 316 | + SDL_PROP_FILE_DIALOG_CANCEL_STRING = 'SDL.filedialog.cancel'; |
238 | 317 |
|
0 commit comments