pub struct FileDialog { /* private fields */ }
Expand description
FLTK’s NativeFileChooser
Implementations§
Source§impl FileDialog
impl FileDialog
Sourcepub fn new(op: FileDialogType) -> FileDialog
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
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}
Sourcepub fn filename(&self) -> PathBuf
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
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}
Sourcepub fn try_show(&mut self) -> Result<FileDialogAction, FltkError>
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
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}
Sourcepub fn set_option(&mut self, opt: FileDialogOptions)
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
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}
Sourcepub fn set_type(&mut self, op: FileDialogType)
pub fn set_type(&mut self, op: FileDialogType)
Sets the type for the dialog
Sourcepub fn set_filter(&mut self, f: &str)
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
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}
Sourcepub fn filter_value(&self) -> i32
pub fn filter_value(&self) -> i32
Gets the current filename filter selection
Sourcepub fn set_filter_value(&mut self, f: i32)
pub fn set_filter_value(&mut self, f: i32)
Sets the filter value using an index to the ’\t’separated filters
Sourcepub fn set_preset_file(&mut self, f: &str)
pub fn set_preset_file(&mut self, f: &str)
Sets the default filename for the dialog
Sourcepub fn error_message(&self) -> Option<String>
pub fn error_message(&self) -> Option<String>
returns the error message from the file dialog
Trait Implementations§
Source§impl Debug for FileDialog
impl Debug for FileDialog
Auto Trait Implementations§
impl Freeze for FileDialog
impl RefUnwindSafe for FileDialog
impl !Send for FileDialog
impl !Sync for FileDialog
impl Unpin for FileDialog
impl UnwindSafe for FileDialog
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more