Struct tauri::api::dialog::FileDialogBuilder
source · pub struct FileDialogBuilder(/* private fields */);
desktop
and crate feature dialog
only.Expand description
The file dialog builder.
Constructs file picker dialogs that can select single/multiple files or directories.
Implementations§
source§impl FileDialogBuilder
impl FileDialogBuilder
sourcepub fn add_filter(self, name: impl AsRef<str>, extensions: &[&str]) -> Self
pub fn add_filter(self, name: impl AsRef<str>, extensions: &[&str]) -> Self
Add file extension filter. Takes in the name of the filter, and list of extensions
sourcepub fn set_directory<P: AsRef<Path>>(self, directory: P) -> Self
pub fn set_directory<P: AsRef<Path>>(self, directory: P) -> Self
Set starting directory of the dialog.
sourcepub fn set_file_name(self, file_name: &str) -> Self
pub fn set_file_name(self, file_name: &str) -> Self
Set starting file name of the dialog.
sourcepub fn set_parent<W: HasRawWindowHandle>(self, parent: &W) -> Self
pub fn set_parent<W: HasRawWindowHandle>(self, parent: &W) -> Self
Sets the parent window of the dialog.
source§impl FileDialogBuilder
impl FileDialogBuilder
sourcepub fn pick_file<F: FnOnce(Option<PathBuf>) + Send + 'static>(self, f: F)
pub fn pick_file<F: FnOnce(Option<PathBuf>) + Send + 'static>(self, f: F)
Shows the dialog to select a single file. This is not a blocking operation, and should be used when running on the main thread to avoid deadlocks with the event loop.
For usage in other contexts such as commands, prefer Self::pick_file
.
§Examples
use tauri::api::dialog::FileDialogBuilder;
tauri::Builder::default()
.build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
.expect("failed to build tauri app")
.run(|_app, _event| {
FileDialogBuilder::new().pick_file(|file_path| {
// do something with the optional file path here
// the file path is `None` if the user closed the dialog
})
})
sourcepub fn pick_files<F: FnOnce(Option<Vec<PathBuf>>) + Send + 'static>(self, f: F)
pub fn pick_files<F: FnOnce(Option<Vec<PathBuf>>) + Send + 'static>(self, f: F)
Shows the dialog to select multiple files. This is not a blocking operation, and should be used when running on the main thread to avoid deadlocks with the event loop.
§Examples
use tauri::api::dialog::FileDialogBuilder;
tauri::Builder::default()
.build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
.expect("failed to build tauri app")
.run(|_app, _event| {
FileDialogBuilder::new().pick_files(|file_paths| {
// do something with the optional file paths here
// the file paths value is `None` if the user closed the dialog
})
})
sourcepub fn pick_folder<F: FnOnce(Option<PathBuf>) + Send + 'static>(self, f: F)
pub fn pick_folder<F: FnOnce(Option<PathBuf>) + Send + 'static>(self, f: F)
Shows the dialog to select a single folder. This is not a blocking operation, and should be used when running on the main thread to avoid deadlocks with the event loop.
§Examples
use tauri::api::dialog::FileDialogBuilder;
tauri::Builder::default()
.build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
.expect("failed to build tauri app")
.run(|_app, _event| {
FileDialogBuilder::new().pick_folder(|folder_path| {
// do something with the optional folder path here
// the folder path is `None` if the user closed the dialog
})
})
sourcepub fn pick_folders<F: FnOnce(Option<Vec<PathBuf>>) + Send + 'static>(
self,
f: F
)
pub fn pick_folders<F: FnOnce(Option<Vec<PathBuf>>) + Send + 'static>( self, f: F )
Shows the dialog to select multiple folders. This is not a blocking operation, and should be used when running on the main thread to avoid deadlocks with the event loop.
§Examples
use tauri::api::dialog::FileDialogBuilder;
tauri::Builder::default()
.build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
.expect("failed to build tauri app")
.run(|_app, _event| {
FileDialogBuilder::new().pick_folders(|file_paths| {
// do something with the optional folder paths here
// the folder paths value is `None` if the user closed the dialog
})
})
sourcepub fn save_file<F: FnOnce(Option<PathBuf>) + Send + 'static>(self, f: F)
pub fn save_file<F: FnOnce(Option<PathBuf>) + Send + 'static>(self, f: F)
Shows the dialog to save a file.
This is not a blocking operation, and should be used when running on the main thread to avoid deadlocks with the event loop.
§Examples
use tauri::api::dialog::FileDialogBuilder;
tauri::Builder::default()
.build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
.expect("failed to build tauri app")
.run(|_app, _event| {
FileDialogBuilder::new().save_file(|file_path| {
// do something with the optional file path here
// the file path is `None` if the user closed the dialog
})
})