Skip to main content

ferroui_base/platform/storage/
picker_options.rs

1use super::IStorageFolder;
2use std::rc::Rc;
3
4/// Common options for the picker dialogs.
5#[derive(Clone, Default)]
6pub struct PickerOptions {
7    title: Option<String>,
8    suggested_start_location: Option<Rc<dyn IStorageFolder>>,
9    suggested_file_name: Option<String>,
10}
11
12impl PickerOptions {
13    /// Creates options with nothing set.
14    pub fn new() -> Self {
15        Self::default()
16    }
17
18    /// The text that appears in the title bar of a picker.
19    pub fn title(&self) -> Option<&str> {
20        self.title.as_deref()
21    }
22
23    pub fn set_title(&mut self, value: Option<String>) {
24        self.title = value;
25    }
26
27    /// Sets [`title`](Self::title) and returns the options.
28    pub fn with_title(mut self, value: impl Into<String>) -> Self {
29        self.title = Some(value.into());
30        self
31    }
32
33    /// The initial location where the file open picker looks for files to
34    /// present to the user. Can be obtained from previously picked folder
35    /// or using [`IStorageProvider::try_get_folder_from_path_async`](super::IStorageProvider::try_get_folder_from_path_async)
36    /// or [`IStorageProvider::try_get_well_known_folder_async`](super::IStorageProvider::try_get_well_known_folder_async).
37    pub fn suggested_start_location(&self) -> Option<&Rc<dyn IStorageFolder>> {
38        self.suggested_start_location.as_ref()
39    }
40
41    pub fn set_suggested_start_location(&mut self, value: Option<Rc<dyn IStorageFolder>>) {
42        self.suggested_start_location = value;
43    }
44
45    /// Sets [`suggested_start_location`](Self::suggested_start_location)
46    /// and returns the options.
47    pub fn with_suggested_start_location(mut self, value: Rc<dyn IStorageFolder>) -> Self {
48        self.suggested_start_location = Some(value);
49        self
50    }
51
52    /// The file name that the file picker suggests to the user.
53    pub fn suggested_file_name(&self) -> Option<&str> {
54        self.suggested_file_name.as_deref()
55    }
56
57    pub fn set_suggested_file_name(&mut self, value: Option<String>) {
58        self.suggested_file_name = value;
59    }
60
61    /// Sets [`suggested_file_name`](Self::suggested_file_name) and returns
62    /// the options.
63    pub fn with_suggested_file_name(mut self, value: impl Into<String>) -> Self {
64        self.suggested_file_name = Some(value.into());
65        self
66    }
67}