Skip to main content

ferroui_dialogs/
managed_file_dialog_options.rs

1use ferroui_base::Ref;
2use ferroui_controls::platform::IMountedVolumeInfoProvider;
3use ferroui_controls::ContentControl;
4use std::rc::Rc;
5
6/// The options of the managed file dialogs.
7///
8/// A record: a copy with a member changed is made with `Clone` and the
9/// setter (the `with` expression of the original).
10#[derive(Clone, Default)]
11pub struct ManagedFileDialogOptions {
12    allow_directory_selection: bool,
13    custom_volume_info_provider: Option<Rc<dyn IMountedVolumeInfoProvider>>,
14    content_root_factory: Option<Rc<dyn Fn() -> Ref<ContentControl>>>,
15}
16
17impl ManagedFileDialogOptions {
18    pub fn new() -> Self {
19        Self::default()
20    }
21
22    pub fn allow_directory_selection(&self) -> bool {
23        self.allow_directory_selection
24    }
25
26    pub fn set_allow_directory_selection(&mut self, value: bool) {
27        self.allow_directory_selection = value;
28    }
29
30    /// Allows to redefine how root volumes are populated in the dialog.
31    pub fn custom_volume_info_provider(&self) -> Option<&Rc<dyn IMountedVolumeInfoProvider>> {
32        self.custom_volume_info_provider.as_ref()
33    }
34
35    pub fn set_custom_volume_info_provider(&mut self, value: Option<Rc<dyn IMountedVolumeInfoProvider>>) {
36        self.custom_volume_info_provider = value;
37    }
38
39    /// Allows to redefine content root.
40    /// Can be a custom Window or any ContentControl (Popup hosted).
41    pub fn content_root_factory(&self) -> Option<&Rc<dyn Fn() -> Ref<ContentControl>>> {
42        self.content_root_factory.as_ref()
43    }
44
45    pub fn set_content_root_factory(&mut self, value: Option<Rc<dyn Fn() -> Ref<ContentControl>>>) {
46        self.content_root_factory = value;
47    }
48}
49
50impl PartialEq for ManagedFileDialogOptions {
51    /// Member-wise, as the equality of a record; the provider and the
52    /// factory compare by reference.
53    fn eq(&self, other: &Self) -> bool {
54        self.allow_directory_selection == other.allow_directory_selection
55            && match (&self.custom_volume_info_provider, &other.custom_volume_info_provider) {
56                (Some(a), Some(b)) => std::ptr::addr_eq(Rc::as_ptr(a), Rc::as_ptr(b)),
57                (None, None) => true,
58                _ => false,
59            }
60            && match (&self.content_root_factory, &other.content_root_factory) {
61                (Some(a), Some(b)) => std::ptr::addr_eq(Rc::as_ptr(a), Rc::as_ptr(b)),
62                (None, None) => true,
63                _ => false,
64            }
65    }
66}