Struct FileDialog

Source
pub struct FileDialog { /* private fields */ }
Expand description

FLTK’s NativeFileChooser

Implementations§

Source§

impl FileDialog

Source

pub fn new(op: FileDialogType) -> FileDialog

Creates an new file dialog

Examples found in repository?
examples/editor.rs (line 90)
89fn nfc_get_file(mode: dialog::NativeFileChooserType) -> Option<PathBuf> {
90    let mut nfc = dialog::NativeFileChooser::new(mode);
91    if mode == dialog::NativeFileChooserType::BrowseSaveFile {
92        nfc.set_option(dialog::NativeFileChooserOptions::SaveAsConfirm);
93    } else if mode == dialog::NativeFileChooserType::BrowseFile {
94        nfc.set_option(dialog::NativeFileChooserOptions::NoOptions);
95        nfc.set_filter("*.{txt,rs,toml}");
96    }
97    match nfc.try_show() {
98        Err(e) => {
99            eprintln!("{}", e);
100            None
101        }
102        Ok(a) => match a {
103            dialog::NativeFileChooserAction::Success => {
104                let name = nfc.filename();
105                if name.as_os_str().is_empty() {
106                    dialog::alert(center().0 - 200, center().1 - 100, "Please specify a file!");
107                    None
108                } else {
109                    Some(name)
110                }
111            }
112            dialog::NativeFileChooserAction::Cancelled => None,
113        },
114    }
115}
More examples
Hide additional examples
examples/editor2.rs (line 38)
37fn nfc_get_file(mode: dialog::NativeFileChooserType) -> Option<PathBuf> {
38    let mut nfc = dialog::NativeFileChooser::new(mode);
39    if mode == dialog::NativeFileChooserType::BrowseSaveFile {
40        nfc.set_option(dialog::NativeFileChooserOptions::SaveAsConfirm);
41    } else if mode == dialog::NativeFileChooserType::BrowseFile {
42        nfc.set_option(dialog::NativeFileChooserOptions::NoOptions);
43        nfc.set_filter("*.{txt,rs,toml}");
44    }
45    match nfc.try_show() {
46        Err(e) => {
47            eprintln!("{}", e);
48            None
49        }
50        Ok(a) => match a {
51            dialog::NativeFileChooserAction::Success => {
52                let name = nfc.filename();
53                if name.as_os_str().is_empty() {
54                    dialog::alert(center().0 - 200, center().1 - 100, "Please specify a file!");
55                    None
56                } else {
57                    Some(name)
58                }
59            }
60            dialog::NativeFileChooserAction::Cancelled => None,
61        },
62    }
63}
Source

pub fn filename(&self) -> PathBuf

Returns the chosen file name

Examples found in repository?
examples/editor.rs (line 104)
89fn nfc_get_file(mode: dialog::NativeFileChooserType) -> Option<PathBuf> {
90    let mut nfc = dialog::NativeFileChooser::new(mode);
91    if mode == dialog::NativeFileChooserType::BrowseSaveFile {
92        nfc.set_option(dialog::NativeFileChooserOptions::SaveAsConfirm);
93    } else if mode == dialog::NativeFileChooserType::BrowseFile {
94        nfc.set_option(dialog::NativeFileChooserOptions::NoOptions);
95        nfc.set_filter("*.{txt,rs,toml}");
96    }
97    match nfc.try_show() {
98        Err(e) => {
99            eprintln!("{}", e);
100            None
101        }
102        Ok(a) => match a {
103            dialog::NativeFileChooserAction::Success => {
104                let name = nfc.filename();
105                if name.as_os_str().is_empty() {
106                    dialog::alert(center().0 - 200, center().1 - 100, "Please specify a file!");
107                    None
108                } else {
109                    Some(name)
110                }
111            }
112            dialog::NativeFileChooserAction::Cancelled => None,
113        },
114    }
115}
More examples
Hide additional examples
examples/editor2.rs (line 52)
37fn nfc_get_file(mode: dialog::NativeFileChooserType) -> Option<PathBuf> {
38    let mut nfc = dialog::NativeFileChooser::new(mode);
39    if mode == dialog::NativeFileChooserType::BrowseSaveFile {
40        nfc.set_option(dialog::NativeFileChooserOptions::SaveAsConfirm);
41    } else if mode == dialog::NativeFileChooserType::BrowseFile {
42        nfc.set_option(dialog::NativeFileChooserOptions::NoOptions);
43        nfc.set_filter("*.{txt,rs,toml}");
44    }
45    match nfc.try_show() {
46        Err(e) => {
47            eprintln!("{}", e);
48            None
49        }
50        Ok(a) => match a {
51            dialog::NativeFileChooserAction::Success => {
52                let name = nfc.filename();
53                if name.as_os_str().is_empty() {
54                    dialog::alert(center().0 - 200, center().1 - 100, "Please specify a file!");
55                    None
56                } else {
57                    Some(name)
58                }
59            }
60            dialog::NativeFileChooserAction::Cancelled => None,
61        },
62    }
63}
Source

pub fn filenames(&self) -> Vec<PathBuf>

Returns the chosen file names

Source

pub fn directory(&self) -> PathBuf

Returns the preset directory

Source

pub fn set_directory<P: AsRef<Path>>( &mut self, dir: &P, ) -> Result<(), FltkError>

Sets the starting directory

§Errors

Errors on non-existent path

Source

pub fn try_show(&mut self) -> Result<FileDialogAction, FltkError>

Shows the file dialog

Examples found in repository?
examples/editor.rs (line 97)
89fn nfc_get_file(mode: dialog::NativeFileChooserType) -> Option<PathBuf> {
90    let mut nfc = dialog::NativeFileChooser::new(mode);
91    if mode == dialog::NativeFileChooserType::BrowseSaveFile {
92        nfc.set_option(dialog::NativeFileChooserOptions::SaveAsConfirm);
93    } else if mode == dialog::NativeFileChooserType::BrowseFile {
94        nfc.set_option(dialog::NativeFileChooserOptions::NoOptions);
95        nfc.set_filter("*.{txt,rs,toml}");
96    }
97    match nfc.try_show() {
98        Err(e) => {
99            eprintln!("{}", e);
100            None
101        }
102        Ok(a) => match a {
103            dialog::NativeFileChooserAction::Success => {
104                let name = nfc.filename();
105                if name.as_os_str().is_empty() {
106                    dialog::alert(center().0 - 200, center().1 - 100, "Please specify a file!");
107                    None
108                } else {
109                    Some(name)
110                }
111            }
112            dialog::NativeFileChooserAction::Cancelled => None,
113        },
114    }
115}
More examples
Hide additional examples
examples/editor2.rs (line 45)
37fn nfc_get_file(mode: dialog::NativeFileChooserType) -> Option<PathBuf> {
38    let mut nfc = dialog::NativeFileChooser::new(mode);
39    if mode == dialog::NativeFileChooserType::BrowseSaveFile {
40        nfc.set_option(dialog::NativeFileChooserOptions::SaveAsConfirm);
41    } else if mode == dialog::NativeFileChooserType::BrowseFile {
42        nfc.set_option(dialog::NativeFileChooserOptions::NoOptions);
43        nfc.set_filter("*.{txt,rs,toml}");
44    }
45    match nfc.try_show() {
46        Err(e) => {
47            eprintln!("{}", e);
48            None
49        }
50        Ok(a) => match a {
51            dialog::NativeFileChooserAction::Success => {
52                let name = nfc.filename();
53                if name.as_os_str().is_empty() {
54                    dialog::alert(center().0 - 200, center().1 - 100, "Please specify a file!");
55                    None
56                } else {
57                    Some(name)
58                }
59            }
60            dialog::NativeFileChooserAction::Cancelled => None,
61        },
62    }
63}
Source

pub fn show(&mut self)

Shows the file dialog

Source

pub fn set_option(&mut self, opt: FileDialogOptions)

Sets the option for the dialog

Examples found in repository?
examples/editor.rs (line 92)
89fn nfc_get_file(mode: dialog::NativeFileChooserType) -> Option<PathBuf> {
90    let mut nfc = dialog::NativeFileChooser::new(mode);
91    if mode == dialog::NativeFileChooserType::BrowseSaveFile {
92        nfc.set_option(dialog::NativeFileChooserOptions::SaveAsConfirm);
93    } else if mode == dialog::NativeFileChooserType::BrowseFile {
94        nfc.set_option(dialog::NativeFileChooserOptions::NoOptions);
95        nfc.set_filter("*.{txt,rs,toml}");
96    }
97    match nfc.try_show() {
98        Err(e) => {
99            eprintln!("{}", e);
100            None
101        }
102        Ok(a) => match a {
103            dialog::NativeFileChooserAction::Success => {
104                let name = nfc.filename();
105                if name.as_os_str().is_empty() {
106                    dialog::alert(center().0 - 200, center().1 - 100, "Please specify a file!");
107                    None
108                } else {
109                    Some(name)
110                }
111            }
112            dialog::NativeFileChooserAction::Cancelled => None,
113        },
114    }
115}
More examples
Hide additional examples
examples/editor2.rs (line 40)
37fn nfc_get_file(mode: dialog::NativeFileChooserType) -> Option<PathBuf> {
38    let mut nfc = dialog::NativeFileChooser::new(mode);
39    if mode == dialog::NativeFileChooserType::BrowseSaveFile {
40        nfc.set_option(dialog::NativeFileChooserOptions::SaveAsConfirm);
41    } else if mode == dialog::NativeFileChooserType::BrowseFile {
42        nfc.set_option(dialog::NativeFileChooserOptions::NoOptions);
43        nfc.set_filter("*.{txt,rs,toml}");
44    }
45    match nfc.try_show() {
46        Err(e) => {
47            eprintln!("{}", e);
48            None
49        }
50        Ok(a) => match a {
51            dialog::NativeFileChooserAction::Success => {
52                let name = nfc.filename();
53                if name.as_os_str().is_empty() {
54                    dialog::alert(center().0 - 200, center().1 - 100, "Please specify a file!");
55                    None
56                } else {
57                    Some(name)
58                }
59            }
60            dialog::NativeFileChooserAction::Cancelled => None,
61        },
62    }
63}
Source

pub fn set_type(&mut self, op: FileDialogType)

Sets the type for the dialog

Source

pub fn set_title(&mut self, title: &str)

Sets the title for the dialog

Source

pub fn set_filter(&mut self, f: &str)

Sets the filter for the dialog, can be: A single wildcard (e.g. "*.txt"). Multiple wildcards (e.g. "*.{cxx,h,H}"). A descriptive name followed by a \t and a wildcard (e.g. "Text Files\t*.txt"). A list of separate wildcards with a \n between each (e.g. "*.{cxx,H}\n*.txt"). A list of descriptive names and wildcards (e.g. "C++ Files\t*.{cxx,H}\nTxt Files\t*.txt")

Examples found in repository?
examples/editor.rs (line 95)
89fn nfc_get_file(mode: dialog::NativeFileChooserType) -> Option<PathBuf> {
90    let mut nfc = dialog::NativeFileChooser::new(mode);
91    if mode == dialog::NativeFileChooserType::BrowseSaveFile {
92        nfc.set_option(dialog::NativeFileChooserOptions::SaveAsConfirm);
93    } else if mode == dialog::NativeFileChooserType::BrowseFile {
94        nfc.set_option(dialog::NativeFileChooserOptions::NoOptions);
95        nfc.set_filter("*.{txt,rs,toml}");
96    }
97    match nfc.try_show() {
98        Err(e) => {
99            eprintln!("{}", e);
100            None
101        }
102        Ok(a) => match a {
103            dialog::NativeFileChooserAction::Success => {
104                let name = nfc.filename();
105                if name.as_os_str().is_empty() {
106                    dialog::alert(center().0 - 200, center().1 - 100, "Please specify a file!");
107                    None
108                } else {
109                    Some(name)
110                }
111            }
112            dialog::NativeFileChooserAction::Cancelled => None,
113        },
114    }
115}
More examples
Hide additional examples
examples/editor2.rs (line 43)
37fn nfc_get_file(mode: dialog::NativeFileChooserType) -> Option<PathBuf> {
38    let mut nfc = dialog::NativeFileChooser::new(mode);
39    if mode == dialog::NativeFileChooserType::BrowseSaveFile {
40        nfc.set_option(dialog::NativeFileChooserOptions::SaveAsConfirm);
41    } else if mode == dialog::NativeFileChooserType::BrowseFile {
42        nfc.set_option(dialog::NativeFileChooserOptions::NoOptions);
43        nfc.set_filter("*.{txt,rs,toml}");
44    }
45    match nfc.try_show() {
46        Err(e) => {
47            eprintln!("{}", e);
48            None
49        }
50        Ok(a) => match a {
51            dialog::NativeFileChooserAction::Success => {
52                let name = nfc.filename();
53                if name.as_os_str().is_empty() {
54                    dialog::alert(center().0 - 200, center().1 - 100, "Please specify a file!");
55                    None
56                } else {
57                    Some(name)
58                }
59            }
60            dialog::NativeFileChooserAction::Cancelled => None,
61        },
62    }
63}
Source

pub fn filter(&self) -> Option<String>

Gets the filter of the FileChooser

Source

pub fn filter_value(&self) -> i32

Gets the current filename filter selection

Source

pub fn set_filter_value(&mut self, f: i32)

Sets the filter value using an index to the ’\t’separated filters

Source

pub fn set_preset_file(&mut self, f: &str)

Sets the default filename for the dialog

Source

pub fn error_message(&self) -> Option<String>

returns the error message from the file dialog

Trait Implementations§

Source§

impl Debug for FileDialog

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for FileDialog

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.