pub struct FileDialog<'a> { /* private fields */ }
Expand description

Builds and shows file dialogs.

Implementations§

source§

impl<'a> FileDialog<'a>

source

pub fn new() -> Self

Creates a file dialog builder.

Examples found in repository?
examples/tour.rs (line 23)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
fn main() {
    let result = MessageDialog::new()
        .set_title("Tour")
        .set_text("Do you want to begin the tour?")
        .set_type(MessageType::Warning)
        .show_confirm()
        .unwrap();
    if !result {
        return;
    }
    echo("show_confirm", &result);

    let result = FileDialog::new()
        .set_location("~")
        .show_open_single_file()
        .unwrap();
    echo("show_open_single_file", &result);

    let result = FileDialog::new()
        .add_filter("Rust Source", &["rs"])
        .add_filter("Image", &["png", "jpg", "gif"])
        .show_open_multiple_file()
        .unwrap();
    echo("show_open_multiple_file", &result);

    let result = FileDialog::new().show_open_single_dir().unwrap();
    echo("show_open_single_dir", &result);

    let result = FileDialog::new()
        .add_filter("Rust Source", &["rs"])
        .add_filter("Image", &["png", "jpg", "gif"])
        .show_save_single_file()
        .unwrap();
    echo("show_save_single_file", &result);

    MessageDialog::new()
        .set_title("End")
        .set_text("That's the end!")
        .show_alert()
        .unwrap();
}
source

pub fn set_title(self, title: &'a str) -> Self

Sets the window title for the dialog.

source

pub fn set_filename(self, filename: &'a str) -> Self

Sets the default value of the filename text field in the dialog. For open dialogs of macOS and zenity, this is a no-op because there’s no such text field on the dialog.

source

pub fn reset_filename(self) -> Self

Resets the default value of the filename field in the dialog.

source

pub fn set_location<P: AsRef<Path> + ?Sized>(self, path: &'a P) -> Self

Sets the default location that the dialog shows at open.

Examples found in repository?
examples/tour.rs (line 24)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
fn main() {
    let result = MessageDialog::new()
        .set_title("Tour")
        .set_text("Do you want to begin the tour?")
        .set_type(MessageType::Warning)
        .show_confirm()
        .unwrap();
    if !result {
        return;
    }
    echo("show_confirm", &result);

    let result = FileDialog::new()
        .set_location("~")
        .show_open_single_file()
        .unwrap();
    echo("show_open_single_file", &result);

    let result = FileDialog::new()
        .add_filter("Rust Source", &["rs"])
        .add_filter("Image", &["png", "jpg", "gif"])
        .show_open_multiple_file()
        .unwrap();
    echo("show_open_multiple_file", &result);

    let result = FileDialog::new().show_open_single_dir().unwrap();
    echo("show_open_single_dir", &result);

    let result = FileDialog::new()
        .add_filter("Rust Source", &["rs"])
        .add_filter("Image", &["png", "jpg", "gif"])
        .show_save_single_file()
        .unwrap();
    echo("show_save_single_file", &result);

    MessageDialog::new()
        .set_title("End")
        .set_text("That's the end!")
        .show_alert()
        .unwrap();
}
source

pub fn reset_location(self) -> Self

Resets the default location that the dialog shows at open. Without a default location set, the dialog will probably use the current working directory as default location.

source

pub fn add_filter(self, description: &'a str, extensions: &'a [&'a str]) -> Self

Adds a file type filter. The filter must contains at least one extension, otherwise this method will panic. For dialogs that open directories, this is a no-op.

Examples found in repository?
examples/tour.rs (line 30)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
fn main() {
    let result = MessageDialog::new()
        .set_title("Tour")
        .set_text("Do you want to begin the tour?")
        .set_type(MessageType::Warning)
        .show_confirm()
        .unwrap();
    if !result {
        return;
    }
    echo("show_confirm", &result);

    let result = FileDialog::new()
        .set_location("~")
        .show_open_single_file()
        .unwrap();
    echo("show_open_single_file", &result);

    let result = FileDialog::new()
        .add_filter("Rust Source", &["rs"])
        .add_filter("Image", &["png", "jpg", "gif"])
        .show_open_multiple_file()
        .unwrap();
    echo("show_open_multiple_file", &result);

    let result = FileDialog::new().show_open_single_dir().unwrap();
    echo("show_open_single_dir", &result);

    let result = FileDialog::new()
        .add_filter("Rust Source", &["rs"])
        .add_filter("Image", &["png", "jpg", "gif"])
        .show_save_single_file()
        .unwrap();
    echo("show_save_single_file", &result);

    MessageDialog::new()
        .set_title("End")
        .set_text("That's the end!")
        .show_alert()
        .unwrap();
}
source

pub fn remove_all_filters(self) -> Self

Removes all file type filters.

source

pub fn set_owner<W: HasRawWindowHandle>(self, window: &W) -> Self

Sets the owner of the dialog. On Unix and GNU/Linux, this is a no-op.

source

pub unsafe fn set_owner_handle(self, handle: RawWindowHandle) -> Self

Sets the owner of the dialog by raw handle. On Unix and GNU/Linux, this is a no-op.

Safety

It’s the caller’s responsibility that ensuring the handle is valid.

source

pub fn reset_owner(self) -> Self

Resets the owner of the dialog to nothing.

source

pub fn show_open_single_file(self) -> Result<Option<PathBuf>>

Shows a dialog that let users to open one file.

Examples found in repository?
examples/tour.rs (line 25)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
fn main() {
    let result = MessageDialog::new()
        .set_title("Tour")
        .set_text("Do you want to begin the tour?")
        .set_type(MessageType::Warning)
        .show_confirm()
        .unwrap();
    if !result {
        return;
    }
    echo("show_confirm", &result);

    let result = FileDialog::new()
        .set_location("~")
        .show_open_single_file()
        .unwrap();
    echo("show_open_single_file", &result);

    let result = FileDialog::new()
        .add_filter("Rust Source", &["rs"])
        .add_filter("Image", &["png", "jpg", "gif"])
        .show_open_multiple_file()
        .unwrap();
    echo("show_open_multiple_file", &result);

    let result = FileDialog::new().show_open_single_dir().unwrap();
    echo("show_open_single_dir", &result);

    let result = FileDialog::new()
        .add_filter("Rust Source", &["rs"])
        .add_filter("Image", &["png", "jpg", "gif"])
        .show_save_single_file()
        .unwrap();
    echo("show_save_single_file", &result);

    MessageDialog::new()
        .set_title("End")
        .set_text("That's the end!")
        .show_alert()
        .unwrap();
}
source

pub fn show_open_multiple_file(self) -> Result<Vec<PathBuf>>

Shows a dialog that let users to open multiple files.

Examples found in repository?
examples/tour.rs (line 32)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
fn main() {
    let result = MessageDialog::new()
        .set_title("Tour")
        .set_text("Do you want to begin the tour?")
        .set_type(MessageType::Warning)
        .show_confirm()
        .unwrap();
    if !result {
        return;
    }
    echo("show_confirm", &result);

    let result = FileDialog::new()
        .set_location("~")
        .show_open_single_file()
        .unwrap();
    echo("show_open_single_file", &result);

    let result = FileDialog::new()
        .add_filter("Rust Source", &["rs"])
        .add_filter("Image", &["png", "jpg", "gif"])
        .show_open_multiple_file()
        .unwrap();
    echo("show_open_multiple_file", &result);

    let result = FileDialog::new().show_open_single_dir().unwrap();
    echo("show_open_single_dir", &result);

    let result = FileDialog::new()
        .add_filter("Rust Source", &["rs"])
        .add_filter("Image", &["png", "jpg", "gif"])
        .show_save_single_file()
        .unwrap();
    echo("show_save_single_file", &result);

    MessageDialog::new()
        .set_title("End")
        .set_text("That's the end!")
        .show_alert()
        .unwrap();
}
source

pub fn show_open_single_dir(self) -> Result<Option<PathBuf>>

Shows a dialog that let users to open one directory.

Examples found in repository?
examples/tour.rs (line 36)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
fn main() {
    let result = MessageDialog::new()
        .set_title("Tour")
        .set_text("Do you want to begin the tour?")
        .set_type(MessageType::Warning)
        .show_confirm()
        .unwrap();
    if !result {
        return;
    }
    echo("show_confirm", &result);

    let result = FileDialog::new()
        .set_location("~")
        .show_open_single_file()
        .unwrap();
    echo("show_open_single_file", &result);

    let result = FileDialog::new()
        .add_filter("Rust Source", &["rs"])
        .add_filter("Image", &["png", "jpg", "gif"])
        .show_open_multiple_file()
        .unwrap();
    echo("show_open_multiple_file", &result);

    let result = FileDialog::new().show_open_single_dir().unwrap();
    echo("show_open_single_dir", &result);

    let result = FileDialog::new()
        .add_filter("Rust Source", &["rs"])
        .add_filter("Image", &["png", "jpg", "gif"])
        .show_save_single_file()
        .unwrap();
    echo("show_save_single_file", &result);

    MessageDialog::new()
        .set_title("End")
        .set_text("That's the end!")
        .show_alert()
        .unwrap();
}
source

pub fn show_save_single_file(self) -> Result<Option<PathBuf>>

Shows a dialog that let users to save one file.

Examples found in repository?
examples/tour.rs (line 42)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
fn main() {
    let result = MessageDialog::new()
        .set_title("Tour")
        .set_text("Do you want to begin the tour?")
        .set_type(MessageType::Warning)
        .show_confirm()
        .unwrap();
    if !result {
        return;
    }
    echo("show_confirm", &result);

    let result = FileDialog::new()
        .set_location("~")
        .show_open_single_file()
        .unwrap();
    echo("show_open_single_file", &result);

    let result = FileDialog::new()
        .add_filter("Rust Source", &["rs"])
        .add_filter("Image", &["png", "jpg", "gif"])
        .show_open_multiple_file()
        .unwrap();
    echo("show_open_multiple_file", &result);

    let result = FileDialog::new().show_open_single_dir().unwrap();
    echo("show_open_single_dir", &result);

    let result = FileDialog::new()
        .add_filter("Rust Source", &["rs"])
        .add_filter("Image", &["png", "jpg", "gif"])
        .show_save_single_file()
        .unwrap();
    echo("show_save_single_file", &result);

    MessageDialog::new()
        .set_title("End")
        .set_text("That's the end!")
        .show_alert()
        .unwrap();
}

Trait Implementations§

source§

impl<'a> Clone for FileDialog<'a>

source§

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

Returns a copy 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> Debug for FileDialog<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for FileDialog<'_>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

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> UnwindSafe for FileDialog<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.