pub struct FileDialog { /* private fields */ }Expand description
A native file dialog builder.
Implementations§
Source§impl FileDialog
impl FileDialog
Sourcepub fn add_filter(
self,
name: impl Into<String>,
extensions: &[impl ToString],
) -> Self
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.
Sourcepub fn set_filters<N, X, E>(
self,
filters: impl IntoIterator<Item = (N, X)>,
) -> Self
pub fn set_filters<N, X, E>( self, filters: impl IntoIterator<Item = (N, X)>, ) -> Self
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"]),
]);Sourcepub fn set_mime_type(self, mime_type: impl Into<String>) -> Self
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.
Sourcepub fn set_directory<P: AsRef<Path>>(self, path: P) -> Self
pub fn set_directory<P: AsRef<Path>>(self, path: P) -> Self
Sets the initial directory, where supported.
Sourcepub fn set_start_location(self, location: StartLocation) -> Self
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.
Sourcepub fn set_file_name(self, file_name: impl Into<String>) -> Self
pub fn set_file_name(self, file_name: impl Into<String>) -> Self
Sets the suggested file name, where supported.
Sourcepub fn set_title(self, title: impl Into<String>) -> Self
pub fn set_title(self, title: impl Into<String>) -> Self
Sets the dialog title, where supported.
Sourcepub fn set_media_representation(
self,
representation: MediaRepresentation,
) -> Self
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.
Sourcepub fn pick_file<F>(self, on_completion: F) -> Result<()>
pub fn pick_file<F>(self, on_completion: F) -> Result<()>
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.
Sourcepub fn pick_image<F>(self, on_completion: F) -> Result<()>
pub fn pick_image<F>(self, on_completion: F) -> Result<()>
Shows the platform’s native image picker.
The callback is called with Ok(None) if the user cancels the picker.
Sourcepub fn pick_video<F>(self, on_completion: F) -> Result<()>
pub fn pick_video<F>(self, on_completion: F) -> Result<()>
Shows the platform’s native video picker.
The callback is called with Ok(None) if the user cancels the picker.
Sourcepub fn pick_image_or_video<F>(self, on_completion: F) -> Result<()>
pub fn pick_image_or_video<F>(self, on_completion: F) -> Result<()>
Shows the platform’s native image and video picker.
The callback is called with Ok(None) if the user cancels the picker.
Sourcepub fn pick_media<F>(
self,
media_kind: MediaKind,
on_completion: F,
) -> Result<()>
pub fn pick_media<F>( self, media_kind: MediaKind, on_completion: F, ) -> Result<()>
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.
Sourcepub fn save_data<D, F>(self, data: D, on_completion: F) -> Result<()>
pub fn save_data<D, F>(self, data: D, on_completion: F) -> Result<()>
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.