Struct fltk::dialog::FileDialog
source · 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)
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
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,
},
}
}
sourcepub fn filename(&self) -> PathBuf
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
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,
},
}
}
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)
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
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,
},
}
}
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)
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
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,
},
}
}
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)
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
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,
},
}
}
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