1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
//! Dialog system for AppCUI applications.
//!
//! This module provides a set of predefined modal windows that are common when using a UI system:
//! * **Notification dialogs** - Show errors, warnings, messages, or ask for validation
//! * **File dialogs** - Allow users to select files to open or save
//! * **Folder selection dialogs** - Allow users to select folders
//!
//! # Notification Dialogs
//!
//! The module provides several functions for displaying notifications with different severity levels:
//! * [`error`] - Shows an error message with an "Ok" button
//! * [`retry`] - Shows an error message with "Retry" and "Cancel" buttons
//! * [`alert`] - Shows a warning message with an "Ok" button
//! * [`proceed`] - Shows a warning message with "Yes" and "No" buttons
//! * [`message`] - Shows an information message with an "Ok" button
//! * [`validate`] - Shows a question with "Yes" and "No" buttons
//! * [`validate_or_cancel`] - Shows a question with "Yes", "No", and "Cancel" buttons
//!
//! # File Dialogs
//!
//! For file operations, the module offers:
//! * [`open`] - A dialog for selecting a file to open
//! * [`save`] - A dialog for selecting a location to save a file
//!
//! # Folder Selection Dialogs
//!
//! For folder selection:
//! * [`select_folder`] - A dialog for selecting a folder
//!
//! # Examples
//!
//! ```rust,no_run
//! use appcui::dialogs;
//!
//! // Show a simple error message
//! dialogs::error("Error", "An error has occurred");
//!
//! // Ask the user a yes/no question
//! if dialogs::validate("Confirm", "Do you want to proceed?") {
//! // User clicked "Yes"
//! } else {
//! // User clicked "No" or closed the dialog
//! }
//!
//! // Open a file dialog
//! if let Some(file_path) = dialogs::open("Open File",
//! "document.txt",
//! dialogs::Location::Current,
//! Some("Text files = [txt]"),
//! dialogs::OpenFileDialogFlags::Icons)
//! {
//! // User selected a file
//! println!("Selected file: {:?}", file_path);
//! }
//! ```
use ;
use crate::;
use DialogButtons;
use DialogResult;
use FileMask;
use ;
use GenericAlertDialog;
use StringImputDialog;
use ;
use EnumBitFlags;
/// Result of a validation dialog with a cancel option.
///
/// This enum represents the possible outcomes when a dialog with "Yes", "No",
/// and "Cancel" buttons is displayed.
///
/// # Values
/// * `Yes` - The user clicked the "Yes" button.
/// * `No` - The user clicked the "No" button.
/// * `Cancel` - The user clicked the "Cancel" button or closed the dialog.
/// Displays an error dialog with an "Ok" button.
///
/// This function shows a modal error dialog with the specified title and message.
/// The dialog will have a single "Ok" button and will block until the user dismisses it.
///
/// # Arguments
/// * `title` - The title of the dialog.
/// * `caption` - The message to display in the dialog.
///
/// # Example
/// ```rust,no_run
/// use appcui::dialogs;
///
/// dialogs::error("Error", "An error has occurred during the last operation");
/// ```
/// Displays an error dialog with "Retry" and "Cancel" buttons.
///
/// This function shows a modal error dialog with the specified title and message.
/// The dialog will have "Retry" and "Cancel" buttons and will block until the user
/// makes a selection.
///
/// # Arguments
/// * `title` - The title of the dialog.
/// * `caption` - The message to display in the dialog.
///
/// # Returns
/// * `true` - If the user clicked the "Retry" button.
/// * `false` - If the user clicked the "Cancel" button or closed the dialog.
///
/// # Example
/// ```rust,no_run
/// use appcui::dialogs;
///
/// if dialogs::retry("Error", "An error occurred while performing a copy operation.\nRetry again?") {
/// // Retry the operation
/// }
/// ```
/// Displays an alert dialog with an "Ok" button.
///
/// This function shows a modal warning dialog with the specified title and message.
/// The dialog will have a single "Ok" button and will block until the user dismisses it.
///
/// # Arguments
/// * `title` - The title of the dialog.
/// * `caption` - The message to display in the dialog.
///
/// # Example
/// ```rust,no_run
/// use appcui::dialogs;
///
/// dialogs::alert("Warning", "Low disk space detected");
/// ```
/// Displays an alert dialog with "Yes" and "No" buttons.
///
/// This function shows a modal warning dialog with the specified title and message.
/// The dialog will have "Yes" and "No" buttons and will block until the user
/// makes a selection.
///
/// # Arguments
/// * `title` - The title of the dialog.
/// * `caption` - The message to display in the dialog.
///
/// # Returns
/// * `true` - If the user clicked the "Yes" button.
/// * `false` - If the user clicked the "No" button or closed the dialog.
///
/// # Example
/// ```rust,no_run
/// use appcui::dialogs;
///
/// if dialogs::proceed("Warning", "An error occurred while performing a copy operation.\nContinue anyway?") {
/// // Continue with the operation
/// }
/// ```
/// Displays a notification dialog with an "Ok" button.
///
/// This function shows a modal notification dialog with the specified title and message.
/// The dialog will have a single "Ok" button and will block until the user dismisses it.
///
/// # Arguments
/// * `title` - The title of the dialog.
/// * `caption` - The message to display in the dialog.
///
/// # Example
/// ```rust,no_run
/// use appcui::dialogs;
///
/// dialogs::message("Success", "All files have been copied");
/// ```
/// Displays a validation dialog with "Yes" and "No" buttons.
///
/// This function shows a modal notification dialog with the specified title and message.
/// The dialog will have "Yes" and "No" buttons and will block until the user
/// makes a selection.
///
/// # Arguments
/// * `title` - The title of the dialog.
/// * `caption` - The message to display in the dialog.
///
/// # Returns
/// * `true` - If the user clicked the "Yes" button.
/// * `false` - If the user clicked the "No" button or closed the dialog.
///
/// # Example
/// ```rust,no_run
/// use appcui::dialogs;
///
/// if dialogs::validate("Question", "Are you sure you want to proceed?") {
/// // Start the action
/// }
/// ```
/// Displays a validation dialog with "Yes", "No", and "Cancel" buttons.
///
/// This function shows a modal notification dialog with the specified title and message.
/// The dialog will have "Yes", "No", and "Cancel" buttons and will block until the user
/// makes a selection.
///
/// # Arguments
/// * `title` - The title of the dialog.
/// * `caption` - The message to display in the dialog.
///
/// # Returns
/// A `ValidateOrCancelResult` indicating which button was clicked:
/// * `ValidateOrCancelResult::Yes` - If the user clicked the "Yes" button.
/// * `ValidateOrCancelResult::No` - If the user clicked the "No" button.
/// * `ValidateOrCancelResult::Cancel` - If the user clicked the "Cancel" button or closed the dialog.
///
/// # Example
/// ```rust,no_run
/// use appcui::dialogs;
/// use appcui::dialogs::ValidateOrCancelResult;
///
/// let result = dialogs::validate_or_cancel("Exit", "Do you want to save your files?");
/// match result {
/// ValidateOrCancelResult::Yes => { /* save files and then exit application */ },
/// ValidateOrCancelResult::No => { /* exit the application directly */ },
/// ValidateOrCancelResult::Cancel => { /* don't exit the application */ }
/// }
/// ```
/// Specifies the initial location for file and folder selection dialogs.
///
/// This enum represents different ways to specify where file and folder
/// selection dialogs should start browsing.
///
/// # Variants
/// * `Current` - Start in the current working directory.
/// * `Last` - Start in the last location used in a previous dialog. If no previous dialog
/// has been opened, falls back to the current directory.
/// * `Path` - Start in the specified path.
///
/// # Example
/// ```rust,no_run
/// use appcui::dialogs;
/// use std::path::Path;
///
/// // Start in a specific directory
/// let specific_path = Path::new("C:/Users/Documents");
/// let location = dialogs::Location::Path(specific_path);
///
/// // Start in the current directory
/// let current_location = dialogs::Location::Current;
///
/// // Start in the last used location
/// let last_location = dialogs::Location::Last;
/// ```
pub
pub
pub
pub
/// Opens a file dialog for saving a file and returns the path of the file selected by the user or None if the user canceled the operation.
/// # Arguments
/// * `title` - The title of the dialog.
/// * `file_name` - The default file name.
/// * `location` - The initial location of the dialog (one of Current, Last or Path). If Last is used, the dialog will open in the last location used by the user.
/// * `extension_mask` - A string that specifies the file extensions that can be selected by the user. The format is `name1 = [ext1, ext2, ... extn], name2 = [...], ...`. If None is provided, all files will be displayed.
/// * `flags` - Flags that specify the behavior of the dialog.
///
/// # Example
/// ```rust,no_run
/// use appcui::dialogs;
///
/// if let Some(path) = dialogs::save("Save file",
/// "file.txt",
/// dialogs::Location::Current,
/// Some("Text files = [txt]"),
/// dialogs::SaveFileDialogFlags::Icons)
/// {
/// println!("File saved at: {:?}", path);
/// }
/// ```
/// Opens a file dialog for opening a file and returns the path of the file selected by the user or None if the user canceled the operation.
/// # Arguments
/// * `title` - The title of the dialog.
/// * `file_name` - The default file name.
/// * `location` - The initial location of the dialog (one of Current, Last or Path). If Last is used, the dialog will open in the last location used by the user.
/// * `extension_mask` - A string that specifies the file extensions that can be selected by the user. The format is `name1 = [ext1, ext2, ... extn], name2 = [...], ...`. If None is provided, all files will be displayed.
/// * `flags` - Flags that specify the behavior of the dialog.
///
/// # Example
/// ```rust,no_run
/// use appcui::dialogs;
///
/// if let Some(path) = dialogs::open("Open file",
/// "file.txt",
/// dialogs::Location::Current,
/// Some("Text files = [txt]"),
/// dialogs::OpenFileDialogFlags::Icons)
/// {
/// println!("File opened: {:?}", path);
/// }
/// ```
/// Opens a dialog for selecting a folder and returns the path of the folder selected by the user or None if the user canceled the operation.
/// # Arguments
/// * `title` - The title of the dialog.
/// * `location` - The initial location of the dialog (one of Current, Last or Path). If Last is used, the dialog will open in the last location used by the user.
/// * `flags` - Flags that specify the behavior of the dialog (ex: display icons).
///
/// # Example
/// ```rust,no_run
/// use appcui::dialogs;
///
/// if let Some(path) = dialogs::select_folder("Select folder",
/// dialogs::Location::Current,
/// dialogs::SelectFolderDialogFlags::Icons)
/// {
/// println!("Folder selected: {:?}", path);
/// }
/// ```
type InputCallback<T> = fn ;
/// Opens an input dialog for entering a value of type T and returns the value entered by the user or None if the user canceled the operation.
/// # Arguments
/// * `title` - The title of the dialog.
/// * `text` - The text to display in the dialog.
/// * `value` - An optional value to pre-fill the input field with.
/// * `validation` - An optional validation function that can be used to validate the input value.
///
/// # Example
/// ```rust,no_run
/// use appcui::dialogs;
///
/// if let Some(res) = dialogs::input::<i32>("Title", "Enter a value", None, None) {
/// // res value contains the selected value
/// } else {
/// // the user canceled the dialog
/// }
/// ```