pub struct FileDialog<'a> {
pub title: &'a str,
pub path: Option<&'a Path>,
pub filter: Option<&'a [FileFilter<'a>]>,
pub owner: Option<&'a dyn HasWindowHandle>,
}Expand description
File dialog.
The file dialog allows the user to select a file or multiple files, or to specify a file name for saving.
Fields§
§title: &'a strThe title of the dialog.
path: Option<&'a Path>The initial path to show in the file dialog.
If the path is relative, it is joined with the current working directory.
If the resulting path exists and is a directory, no default file name is provided.
Otherwise, Path::file_name is used as the default file name.
filter: Option<&'a [FileFilter<'a>]>An optional list of file filters to show in the file dialog.
owner: Option<&'a dyn HasWindowHandle>The owner window of the dialog.
Implementations§
Source§impl<'a> FileDialog<'a>
impl<'a> FileDialog<'a>
Sourcepub fn pick_file(&self) -> Option<PathBuf>
pub fn pick_file(&self) -> Option<PathBuf>
Show open file dialog, allowing the user to select a single file.
Sourcepub fn pick_files(&self) -> Option<Vec<PathBuf>>
pub fn pick_files(&self) -> Option<Vec<PathBuf>>
Show open file dialog, allowing the user to select multiple files.
Examples found in repository?
examples/open_file_dialog.rs (line 26)
3fn main() {
4 let filters = [
5 rustydialogs::FileFilter {
6 desc: "Markdown Files (*.md)",
7 patterns: &["*.md"],
8 },
9 rustydialogs::FileFilter {
10 desc: "Text Files (*.txt)",
11 patterns: &["*.txt"],
12 },
13 rustydialogs::FileFilter {
14 desc: "JSON Files (*.json)",
15 patterns: &["*.json"],
16 },
17 ];
18
19 let dialog = rustydialogs::FileDialog {
20 title: "Open file(s)",
21 path: Some(Path::new("readme.md")),
22 filter: Some(&filters),
23 owner: None,
24 };
25
26 match dialog.pick_files() {
27 Some(paths) => {
28 for path in paths {
29 println!("Open path: {}", path.display());
30 }
31 }
32 None => println!("Open canceled"),
33 }
34}Sourcepub fn save_file(&self) -> Option<PathBuf>
pub fn save_file(&self) -> Option<PathBuf>
Show save file dialog.
Examples found in repository?
examples/save_file_dialog.rs (line 22)
3fn main() {
4 let filters = [
5 rustydialogs::FileFilter {
6 desc: "Text Files (*.txt)",
7 patterns: &["*.txt"],
8 },
9 rustydialogs::FileFilter {
10 desc: "JSON Files (*.json)",
11 patterns: &["*.json"],
12 },
13 ];
14
15 let dialog = rustydialogs::FileDialog {
16 title: "Save a file",
17 path: Some(Path::new("output.txt")),
18 filter: Some(&filters),
19 owner: None,
20 };
21
22 match dialog.save_file() {
23 Some(path) => println!("Save path: {}", path.display()),
24 None => println!("Save canceled"),
25 }
26}Trait Implementations§
Source§impl<'a> Clone for FileDialog<'a>
impl<'a> Clone for FileDialog<'a>
Source§fn clone(&self) -> FileDialog<'a>
fn clone(&self) -> FileDialog<'a>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl<'a> Copy for FileDialog<'a>
Auto Trait Implementations§
impl<'a> Freeze for FileDialog<'a>
impl<'a> !RefUnwindSafe for FileDialog<'a>
impl<'a> !Send for FileDialog<'a>
impl<'a> !Sync for FileDialog<'a>
impl<'a> Unpin for FileDialog<'a>
impl<'a> UnsafeUnpin for FileDialog<'a>
impl<'a> !UnwindSafe for FileDialog<'a>
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