Skip to main content

FileSelection

Struct FileSelection 

Source
pub struct FileSelection { /* private fields */ }
Expand description

A file chooser dialog box.

This dialog box opens a file choser with an optional title in the specified path. If the path is not specified, it defaults to the user’s home directory.

The backends might support multiple operation modes, for example open or save dialogs. You can select a mode using the FileSelectionMode enum, though the backend might ignore the mode and just display a simple file dialog. Per default, the mode is set to Open.

§Example

use dialog::DialogBox;

let choice = dialog::FileSelection::new("Please select a file")
    .title("File Selection")
    .path("/home/user/Downloads")
    .show()
    .expect("Could not display dialog box");
println!("The user chose: {:?}", choice);

Implementations§

Source§

impl FileSelection

Source

pub fn new(text: impl Into<String>) -> FileSelection

Creates a new file chooser with the given path.

Examples found in repository?
examples/file_selection.rs (line 7)
6fn main() -> dialog::Result<()> {
7    let choice = dialog::FileSelection::new("Please select a file")
8        .title("File Chooser Example (Open)")
9        .path("/etc")
10        .show()?;
11    println!("The user chose: {:?}", choice);
12
13    let choice = dialog::FileSelection::new("Please select a file")
14        .title("File Chooser Example (Save)")
15        .mode(dialog::FileSelectionMode::Save)
16        .path("/etc")
17        .show()?;
18    println!("The user chose: {:?}", choice);
19
20    Ok(())
21}
Source

pub fn title(&mut self, title: impl Into<String>) -> &mut FileSelection

Sets the title of this file chooser dialog box.

This method returns a reference to self to enable chaining.

Examples found in repository?
examples/file_selection.rs (line 8)
6fn main() -> dialog::Result<()> {
7    let choice = dialog::FileSelection::new("Please select a file")
8        .title("File Chooser Example (Open)")
9        .path("/etc")
10        .show()?;
11    println!("The user chose: {:?}", choice);
12
13    let choice = dialog::FileSelection::new("Please select a file")
14        .title("File Chooser Example (Save)")
15        .mode(dialog::FileSelectionMode::Save)
16        .path("/etc")
17        .show()?;
18    println!("The user chose: {:?}", choice);
19
20    Ok(())
21}
Source

pub fn path(&mut self, path: impl AsRef<Path>) -> &mut FileSelection

Sets the path of this file chooser dialog box.

This method returns a reference to self to enable chaining.

Examples found in repository?
examples/file_selection.rs (line 9)
6fn main() -> dialog::Result<()> {
7    let choice = dialog::FileSelection::new("Please select a file")
8        .title("File Chooser Example (Open)")
9        .path("/etc")
10        .show()?;
11    println!("The user chose: {:?}", choice);
12
13    let choice = dialog::FileSelection::new("Please select a file")
14        .title("File Chooser Example (Save)")
15        .mode(dialog::FileSelectionMode::Save)
16        .path("/etc")
17        .show()?;
18    println!("The user chose: {:?}", choice);
19
20    Ok(())
21}
Source

pub fn path_to_string(&self) -> Option<String>

Gets the path of this file chooser dialog box.

This method returns the validated directory as a String.

Source

pub fn mode(&mut self, mode: FileSelectionMode) -> &mut FileSelection

Sets the operation mode of the file chooser.

This method returns a reference to self to enable chaining.

Examples found in repository?
examples/file_selection.rs (line 15)
6fn main() -> dialog::Result<()> {
7    let choice = dialog::FileSelection::new("Please select a file")
8        .title("File Chooser Example (Open)")
9        .path("/etc")
10        .show()?;
11    println!("The user chose: {:?}", choice);
12
13    let choice = dialog::FileSelection::new("Please select a file")
14        .title("File Chooser Example (Save)")
15        .mode(dialog::FileSelectionMode::Save)
16        .path("/etc")
17        .show()?;
18    println!("The user chose: {:?}", choice);
19
20    Ok(())
21}

Trait Implementations§

Source§

impl DialogBox for FileSelection

Source§

type Output = Option<String>

The type of the data returned by the dialog box.
Source§

fn show_with<B>(&self, backend: impl AsRef<B>) -> Result<Self::Output>
where B: Backend + ?Sized,

Shows this dialog box using the given backend and returns the output.
Source§

fn show(&self) -> Result<Self::Output>

Shows this dialog box using the default backend and returns the output. 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.