Struct NativeFileChooser

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

FLTK’s NativeFileChooser

Implementations§

Source§

impl NativeFileChooser

Source

pub fn new(op: NativeFileChooserType) -> NativeFileChooser

Creates an new file dialog

Examples found in repository?
examples/editor.rs (line 84)
83fn nfc_get_file(mode: dialog::NativeFileChooserType) -> Option<PathBuf> {
84    let mut nfc = dialog::NativeFileChooser::new(mode);
85    if mode == dialog::NativeFileChooserType::BrowseSaveFile {
86        nfc.set_option(dialog::NativeFileChooserOptions::SaveAsConfirm);
87    } else if mode == dialog::NativeFileChooserType::BrowseFile {
88        nfc.set_option(dialog::NativeFileChooserOptions::NoOptions);
89        nfc.set_filter("*.{txt,rs,toml}");
90    }
91    match nfc.show() {
92        Err(e) => {
93            eprintln!("{}", e);
94            None
95        }
96        Ok(a) => match a {
97            dialog::NativeFileChooserAction::Success => {
98                let name = nfc.filename();
99                if name.as_os_str().is_empty() {
100                    dialog::alert("Please specify a file!");
101                    None
102                } else {
103                    Some(name)
104                }
105            }
106            dialog::NativeFileChooserAction::Cancelled => None,
107        },
108    }
109}
More examples
Hide additional examples
examples/editor2.rs (line 31)
30fn nfc_get_file(mode: dialog::NativeFileChooserType) -> Option<PathBuf> {
31    let mut nfc = dialog::NativeFileChooser::new(mode);
32    if mode == dialog::NativeFileChooserType::BrowseSaveFile {
33        nfc.set_option(dialog::NativeFileChooserOptions::SaveAsConfirm);
34    } else if mode == dialog::NativeFileChooserType::BrowseFile {
35        nfc.set_option(dialog::NativeFileChooserOptions::NoOptions);
36        nfc.set_filter("*.{txt,rs,toml}");
37    }
38    match nfc.show() {
39        Err(e) => {
40            eprintln!("{}", e);
41            None
42        }
43        Ok(a) => match a {
44            dialog::NativeFileChooserAction::Success => {
45                let name = nfc.filename();
46                if name.as_os_str().is_empty() {
47                    dialog::alert("Please specify a file!");
48                    None
49                } else {
50                    Some(name)
51                }
52            }
53            dialog::NativeFileChooserAction::Cancelled => None,
54        },
55    }
56}
Source

pub fn filename(&self) -> PathBuf

Returns the chosen file name

Examples found in repository?
examples/editor.rs (line 98)
83fn nfc_get_file(mode: dialog::NativeFileChooserType) -> Option<PathBuf> {
84    let mut nfc = dialog::NativeFileChooser::new(mode);
85    if mode == dialog::NativeFileChooserType::BrowseSaveFile {
86        nfc.set_option(dialog::NativeFileChooserOptions::SaveAsConfirm);
87    } else if mode == dialog::NativeFileChooserType::BrowseFile {
88        nfc.set_option(dialog::NativeFileChooserOptions::NoOptions);
89        nfc.set_filter("*.{txt,rs,toml}");
90    }
91    match nfc.show() {
92        Err(e) => {
93            eprintln!("{}", e);
94            None
95        }
96        Ok(a) => match a {
97            dialog::NativeFileChooserAction::Success => {
98                let name = nfc.filename();
99                if name.as_os_str().is_empty() {
100                    dialog::alert("Please specify a file!");
101                    None
102                } else {
103                    Some(name)
104                }
105            }
106            dialog::NativeFileChooserAction::Cancelled => None,
107        },
108    }
109}
More examples
Hide additional examples
examples/editor2.rs (line 45)
30fn nfc_get_file(mode: dialog::NativeFileChooserType) -> Option<PathBuf> {
31    let mut nfc = dialog::NativeFileChooser::new(mode);
32    if mode == dialog::NativeFileChooserType::BrowseSaveFile {
33        nfc.set_option(dialog::NativeFileChooserOptions::SaveAsConfirm);
34    } else if mode == dialog::NativeFileChooserType::BrowseFile {
35        nfc.set_option(dialog::NativeFileChooserOptions::NoOptions);
36        nfc.set_filter("*.{txt,rs,toml}");
37    }
38    match nfc.show() {
39        Err(e) => {
40            eprintln!("{}", e);
41            None
42        }
43        Ok(a) => match a {
44            dialog::NativeFileChooserAction::Success => {
45                let name = nfc.filename();
46                if name.as_os_str().is_empty() {
47                    dialog::alert("Please specify a file!");
48                    None
49                } else {
50                    Some(name)
51                }
52            }
53            dialog::NativeFileChooserAction::Cancelled => None,
54        },
55    }
56}
Source

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

Returns the chosen file names

Source

pub fn directory(&self) -> Option<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 show(&mut self) -> Result<NativeFileChooserAction, FltkError>

Shows the file dialog

Examples found in repository?
examples/editor.rs (line 91)
83fn nfc_get_file(mode: dialog::NativeFileChooserType) -> Option<PathBuf> {
84    let mut nfc = dialog::NativeFileChooser::new(mode);
85    if mode == dialog::NativeFileChooserType::BrowseSaveFile {
86        nfc.set_option(dialog::NativeFileChooserOptions::SaveAsConfirm);
87    } else if mode == dialog::NativeFileChooserType::BrowseFile {
88        nfc.set_option(dialog::NativeFileChooserOptions::NoOptions);
89        nfc.set_filter("*.{txt,rs,toml}");
90    }
91    match nfc.show() {
92        Err(e) => {
93            eprintln!("{}", e);
94            None
95        }
96        Ok(a) => match a {
97            dialog::NativeFileChooserAction::Success => {
98                let name = nfc.filename();
99                if name.as_os_str().is_empty() {
100                    dialog::alert("Please specify a file!");
101                    None
102                } else {
103                    Some(name)
104                }
105            }
106            dialog::NativeFileChooserAction::Cancelled => None,
107        },
108    }
109}
More examples
Hide additional examples
examples/editor2.rs (line 38)
30fn nfc_get_file(mode: dialog::NativeFileChooserType) -> Option<PathBuf> {
31    let mut nfc = dialog::NativeFileChooser::new(mode);
32    if mode == dialog::NativeFileChooserType::BrowseSaveFile {
33        nfc.set_option(dialog::NativeFileChooserOptions::SaveAsConfirm);
34    } else if mode == dialog::NativeFileChooserType::BrowseFile {
35        nfc.set_option(dialog::NativeFileChooserOptions::NoOptions);
36        nfc.set_filter("*.{txt,rs,toml}");
37    }
38    match nfc.show() {
39        Err(e) => {
40            eprintln!("{}", e);
41            None
42        }
43        Ok(a) => match a {
44            dialog::NativeFileChooserAction::Success => {
45                let name = nfc.filename();
46                if name.as_os_str().is_empty() {
47                    dialog::alert("Please specify a file!");
48                    None
49                } else {
50                    Some(name)
51                }
52            }
53            dialog::NativeFileChooserAction::Cancelled => None,
54        },
55    }
56}
Source

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

Sets the option for the dialog

Examples found in repository?
examples/editor.rs (line 86)
83fn nfc_get_file(mode: dialog::NativeFileChooserType) -> Option<PathBuf> {
84    let mut nfc = dialog::NativeFileChooser::new(mode);
85    if mode == dialog::NativeFileChooserType::BrowseSaveFile {
86        nfc.set_option(dialog::NativeFileChooserOptions::SaveAsConfirm);
87    } else if mode == dialog::NativeFileChooserType::BrowseFile {
88        nfc.set_option(dialog::NativeFileChooserOptions::NoOptions);
89        nfc.set_filter("*.{txt,rs,toml}");
90    }
91    match nfc.show() {
92        Err(e) => {
93            eprintln!("{}", e);
94            None
95        }
96        Ok(a) => match a {
97            dialog::NativeFileChooserAction::Success => {
98                let name = nfc.filename();
99                if name.as_os_str().is_empty() {
100                    dialog::alert("Please specify a file!");
101                    None
102                } else {
103                    Some(name)
104                }
105            }
106            dialog::NativeFileChooserAction::Cancelled => None,
107        },
108    }
109}
More examples
Hide additional examples
examples/editor2.rs (line 33)
30fn nfc_get_file(mode: dialog::NativeFileChooserType) -> Option<PathBuf> {
31    let mut nfc = dialog::NativeFileChooser::new(mode);
32    if mode == dialog::NativeFileChooserType::BrowseSaveFile {
33        nfc.set_option(dialog::NativeFileChooserOptions::SaveAsConfirm);
34    } else if mode == dialog::NativeFileChooserType::BrowseFile {
35        nfc.set_option(dialog::NativeFileChooserOptions::NoOptions);
36        nfc.set_filter("*.{txt,rs,toml}");
37    }
38    match nfc.show() {
39        Err(e) => {
40            eprintln!("{}", e);
41            None
42        }
43        Ok(a) => match a {
44            dialog::NativeFileChooserAction::Success => {
45                let name = nfc.filename();
46                if name.as_os_str().is_empty() {
47                    dialog::alert("Please specify a file!");
48                    None
49                } else {
50                    Some(name)
51                }
52            }
53            dialog::NativeFileChooserAction::Cancelled => None,
54        },
55    }
56}
Source

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

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 89)
83fn nfc_get_file(mode: dialog::NativeFileChooserType) -> Option<PathBuf> {
84    let mut nfc = dialog::NativeFileChooser::new(mode);
85    if mode == dialog::NativeFileChooserType::BrowseSaveFile {
86        nfc.set_option(dialog::NativeFileChooserOptions::SaveAsConfirm);
87    } else if mode == dialog::NativeFileChooserType::BrowseFile {
88        nfc.set_option(dialog::NativeFileChooserOptions::NoOptions);
89        nfc.set_filter("*.{txt,rs,toml}");
90    }
91    match nfc.show() {
92        Err(e) => {
93            eprintln!("{}", e);
94            None
95        }
96        Ok(a) => match a {
97            dialog::NativeFileChooserAction::Success => {
98                let name = nfc.filename();
99                if name.as_os_str().is_empty() {
100                    dialog::alert("Please specify a file!");
101                    None
102                } else {
103                    Some(name)
104                }
105            }
106            dialog::NativeFileChooserAction::Cancelled => None,
107        },
108    }
109}
More examples
Hide additional examples
examples/editor2.rs (line 36)
30fn nfc_get_file(mode: dialog::NativeFileChooserType) -> Option<PathBuf> {
31    let mut nfc = dialog::NativeFileChooser::new(mode);
32    if mode == dialog::NativeFileChooserType::BrowseSaveFile {
33        nfc.set_option(dialog::NativeFileChooserOptions::SaveAsConfirm);
34    } else if mode == dialog::NativeFileChooserType::BrowseFile {
35        nfc.set_option(dialog::NativeFileChooserOptions::NoOptions);
36        nfc.set_filter("*.{txt,rs,toml}");
37    }
38    match nfc.show() {
39        Err(e) => {
40            eprintln!("{}", e);
41            None
42        }
43        Ok(a) => match a {
44            dialog::NativeFileChooserAction::Success => {
45                let name = nfc.filename();
46                if name.as_os_str().is_empty() {
47                    dialog::alert("Please specify a file!");
48                    None
49                } else {
50                    Some(name)
51                }
52            }
53            dialog::NativeFileChooserAction::Cancelled => None,
54        },
55    }
56}
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 NativeFileChooser

Source§

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

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

impl Drop for NativeFileChooser

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.