Skip to main content

FileDialog

Struct FileDialog 

Source
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 str

The 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>

Source

pub fn pick_file(&self) -> Option<PathBuf>

Show open file dialog, allowing the user to select a single file.

Source

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}
Source

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>

Source§

fn clone(&self) -> FileDialog<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.