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

pub fn filename(&self) -> PathBuf

Returns the chosen file name

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