makepad_platform/
file_dialogs.rs1use std::path::{PathBuf};
3
4
5#[derive(Debug, PartialEq)]
7pub struct Filter {
8 pub description: String,
9 pub extensions: Vec<String>,
10}
11
12#[derive(Debug, PartialEq)]
15pub struct FileDialog {
16 pub filename: Option<String>,
17 pub location: Option<PathBuf>,
18 pub filters: Vec<Filter>,
19 pub title: Option<String>,
20}
21
22impl FileDialog {
23 pub fn new() -> Self {
25 FileDialog {
26 filename: None,
27 location: None,
28 filters: vec![],
29 title: None,
30 }
31 }
32
33 pub fn set_title(mut self, title: String) -> Self {
35 self.title = Some(title);
36 self
37 }
38
39 pub fn set_filename(mut self, filename: String) -> Self {
42 self.filename = Some(filename);
43 self
44 }
45
46 pub fn reset_filename(mut self) -> Self {
48 self.filename = None;
49 self
50 }
51
52 pub fn set_location(mut self, path: PathBuf) -> Self {
54 self.location = Some(path);
55 self
56 }
57
58 pub fn reset_location(mut self) -> Self {
61 self.location = None;
62 self
63 }
64
65 pub fn add_filter(mut self, description: String, extensions: Vec<String>) -> Self {
68 if extensions.is_empty() {
69 panic!("The file extensions of a filter must be specified.")
70 }
71 self.filters.push(Filter {
72 description,
73 extensions,
74 });
75 self
76 }
77
78 pub fn remove_all_filters(mut self) -> Self {
80 self.filters = vec![];
81 self
82 }
83
84
85
86}
87
88
89
90impl Default for FileDialog {
91 fn default() -> Self {
92 Self::new()
93 }
94}
95