Skip to main content

FileDialog

Struct FileDialog 

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

A native file dialog builder.

Implementations§

Source§

impl FileDialog

Source

pub fn new() -> Self

Creates a new file dialog builder.

Source

pub fn add_filter( self, name: impl Into<String>, extensions: &[impl ToString], ) -> Self

Appends a single named file extension filter, leaving existing filters intact.

Upon creation, a FileDialog has no filters. Adding any filter manually will result in the default image or video extension filters not being used.

Extensions may be supplied with or without a leading dot ‘.’. To replace the whole filter set, use set_filters instead.

See the README or top-level docs for more info.

Source

pub fn set_filters<N, X, E>( self, filters: impl IntoIterator<Item = (N, X)>, ) -> Self
where N: Into<String>, X: IntoIterator<Item = E>, E: ToString,

Replaces every previously added filter with the given set of filters.

Passing an empty set clears all filters, including those previously added via add_filter().

let dialog = FileDialog::new().set_filters([
    ("Images", &["png", "jpg"]),
    ("Documents", &["pdf", "txt"]),
]);
Source

pub fn set_mime_type(self, mime_type: impl Into<String>) -> Self

Sets a platform MIME type hint.

This is primarily used on Android and iOS. Desktop backends might ignore it.

Source

pub fn set_directory<P: AsRef<Path>>(self, path: P) -> Self

Sets the initial directory, where supported.

Source

pub fn set_start_location(self, location: StartLocation) -> Self

Hints which well-known folder the dialog should open in.

This is merely a hint; the OS might very well open the last-used location instead.

Source

pub fn set_file_name(self, file_name: impl Into<String>) -> Self

Sets the suggested file name, where supported.

Source

pub fn set_title(self, title: impl Into<String>) -> Self

Sets the dialog title, where supported.

Source

pub fn set_media_representation( self, representation: MediaRepresentation, ) -> Self

Sets which representation of a picked media item the platform should hand back.

Only the media pickers (pick_image, pick_video, pick_image_or_video, pick_media) use this, and only on iOS so far. Defaults to MediaRepresentation::Original.

Source

pub fn pick_file<F>(self, on_completion: F) -> Result<()>
where F: FnOnce(Result<Option<PickedFile>>) + Send + 'static,

Shows a native open-file dialog.

The callback is called with Ok(None) if the user cancels the dialog. Returns Error::AlreadyOpen if a dialow is already being shown.

Source

pub fn pick_image<F>(self, on_completion: F) -> Result<()>
where F: FnOnce(Result<Option<PickedFile>>) + Send + 'static,

Shows the platform’s native image picker.

The callback is called with Ok(None) if the user cancels the picker.

Source

pub fn pick_video<F>(self, on_completion: F) -> Result<()>
where F: FnOnce(Result<Option<PickedFile>>) + Send + 'static,

Shows the platform’s native video picker.

The callback is called with Ok(None) if the user cancels the picker.

Source

pub fn pick_image_or_video<F>(self, on_completion: F) -> Result<()>
where F: FnOnce(Result<Option<PickedFile>>) + Send + 'static,

Shows the platform’s native image and video picker.

The callback is called with Ok(None) if the user cancels the picker.

Source

pub fn pick_media<F>( self, media_kind: MediaKind, on_completion: F, ) -> Result<()>
where F: FnOnce(Result<Option<PickedFile>>) + Send + 'static,

Shows the platform’s native media picker.

  • Android: shows the Android Photo Picker, falling back to the document picker with a filter for images/videos.
  • iOS: shows the PHPickerViewController.
  • Desktop: shows a filtered file dialog.

With no explicit location set, defaults the start location to Pictures or Videos, which only the desktop dialog and document-picker fallbacks use.

Returns Error::AlreadyOpen if a dialow is already being shown.

Source

pub fn save_data<D, F>(self, data: D, on_completion: F) -> Result<()>
where D: AsRef<[u8]> + Send + 'static, F: FnOnce(Result<Option<PickedFile>>) + Send + 'static,

Saves the given data bytes to a user-specific location via platform-native operations.

You should first set a file name via FileDialog::set_file_name, otherwise this will return Error::InvalidFileName. Returns Error::AlreadyOpen if a dialow is already being shown.

Source

pub fn save_to_downloads<P, F>( self, source_path: P, on_completion: F, ) -> Result<()>
where P: AsRef<Path>, F: FnOnce(Result<Option<PickedFile>>) + Send + 'static,

Saves a file to the user’s Downloads location.

Trait Implementations§

Source§

impl Clone for FileDialog

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for FileDialog

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§

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.