pub struct FileDialogBuilder<R: Runtime> { /* private fields */ }
Expand description
The file dialog builder.
Constructs file picker dialogs that can select single/multiple files or directories.
Implementations§
Source§impl<R: Runtime> FileDialogBuilder<R>
impl<R: Runtime> FileDialogBuilder<R>
Sourcepub fn add_filter(self, name: impl Into<String>, extensions: &[&str]) -> Self
pub fn add_filter(self, name: impl Into<String>, 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: impl Into<String>) -> Self
pub fn set_file_name(self, file_name: impl Into<String>) -> Self
Set starting file name of the dialog.
Sourcepub fn set_parent<W: HasWindowHandle + HasDisplayHandle>(
self,
parent: &W,
) -> Self
pub fn set_parent<W: HasWindowHandle + HasDisplayHandle>( self, parent: &W, ) -> Self
Sets the parent window of the dialog.
Sourcepub fn set_can_create_directories(self, can: bool) -> Self
pub fn set_can_create_directories(self, can: bool) -> Self
Set whether it should be possible to create new directories in the dialog. Enabled by default. macOS only.
Sourcepub fn pick_file<F: FnOnce(Option<FilePath>) + Send + 'static>(self, f: F)
pub fn pick_file<F: FnOnce(Option<FilePath>) + 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_plugin_dialog::DialogExt;
tauri::Builder::default()
.setup(|app| {
app.dialog().file().pick_file(|file_path| {
// do something with the optional file path here
// the file path is `None` if the user closed the dialog
});
Ok(())
});
Sourcepub fn pick_files<F: FnOnce(Option<Vec<FilePath>>) + Send + 'static>(self, f: F)
pub fn pick_files<F: FnOnce(Option<Vec<FilePath>>) + 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.
§Reading the files
The file paths cannot be read directly on Android as they are behind a content URI.
The recommended way to read the files is using the fs
plugin:
use tauri_plugin_dialog::DialogExt;
use tauri_plugin_fs::FsExt;
tauri::Builder::default()
.setup(|app| {
let handle = app.handle().clone();
app.dialog().file().pick_file(move |file_path| {
let Some(path) = file_path else { return };
let Ok(contents) = handle.fs().read_to_string(path) else {
eprintln!("failed to read file, <todo add error handling!>");
return;
};
});
Ok(())
});
See https://developer.android.com/guide/topics/providers/content-provider-basics for more information.
§Examples
use tauri_plugin_dialog::DialogExt;
tauri::Builder::default()
.setup(|app| {
app.dialog().file().pick_files(|file_paths| {
// do something with the optional file paths here
// the file paths value is `None` if the user closed the dialog
});
Ok(())
});
Sourcepub fn pick_folder<F: FnOnce(Option<FilePath>) + Send + 'static>(self, f: F)
pub fn pick_folder<F: FnOnce(Option<FilePath>) + 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_plugin_dialog::DialogExt;
tauri::Builder::default()
.setup(|app| {
app.dialog().file().pick_folder(|folder_path| {
// do something with the optional folder path here
// the folder path is `None` if the user closed the dialog
});
Ok(())
});
Sourcepub fn pick_folders<F: FnOnce(Option<Vec<FilePath>>) + Send + 'static>(
self,
f: F,
)
pub fn pick_folders<F: FnOnce(Option<Vec<FilePath>>) + 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_plugin_dialog::DialogExt;
tauri::Builder::default()
.setup(|app| {
app.dialog().file().pick_folders(|file_paths| {
// do something with the optional folder paths here
// the folder paths value is `None` if the user closed the dialog
});
Ok(())
});
Sourcepub fn save_file<F: FnOnce(Option<FilePath>) + Send + 'static>(self, f: F)
pub fn save_file<F: FnOnce(Option<FilePath>) + 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_plugin_dialog::DialogExt;
tauri::Builder::default()
.setup(|app| {
app.dialog().file().save_file(|file_path| {
// do something with the optional file path here
// the file path is `None` if the user closed the dialog
});
Ok(())
});
Source§impl<R: Runtime> FileDialogBuilder<R>
Blocking APIs.
impl<R: Runtime> FileDialogBuilder<R>
Blocking APIs.
Sourcepub fn blocking_pick_file(self) -> Option<FilePath>
pub fn blocking_pick_file(self) -> Option<FilePath>
Shows the dialog to select a single file. This is a blocking operation, and should NOT be used when running on the main thread context.
§Examples
use tauri_plugin_dialog::DialogExt;
#[tauri::command]
async fn my_command(app: tauri::AppHandle) {
let file_path = app.dialog().file().blocking_pick_file();
// do something with the optional file path here
// the file path is `None` if the user closed the dialog
}
Sourcepub fn blocking_pick_files(self) -> Option<Vec<FilePath>>
pub fn blocking_pick_files(self) -> Option<Vec<FilePath>>
Shows the dialog to select multiple files. This is a blocking operation, and should NOT be used when running on the main thread context.
§Examples
use tauri_plugin_dialog::DialogExt;
#[tauri::command]
async fn my_command(app: tauri::AppHandle) {
let file_path = app.dialog().file().blocking_pick_files();
// do something with the optional file paths here
// the file paths value is `None` if the user closed the dialog
}
Sourcepub fn blocking_pick_folder(self) -> Option<FilePath>
pub fn blocking_pick_folder(self) -> Option<FilePath>
Shows the dialog to select a single folder. This is a blocking operation, and should NOT be used when running on the main thread context.
§Examples
use tauri_plugin_dialog::DialogExt;
#[tauri::command]
async fn my_command(app: tauri::AppHandle) {
let folder_path = app.dialog().file().blocking_pick_folder();
// do something with the optional folder path here
// the folder path is `None` if the user closed the dialog
}
Sourcepub fn blocking_pick_folders(self) -> Option<Vec<FilePath>>
pub fn blocking_pick_folders(self) -> Option<Vec<FilePath>>
Shows the dialog to select multiple folders. This is a blocking operation, and should NOT be used when running on the main thread context.
§Examples
use tauri_plugin_dialog::DialogExt;
#[tauri::command]
async fn my_command(app: tauri::AppHandle) {
let folder_paths = app.dialog().file().blocking_pick_folders();
// do something with the optional folder paths here
// the folder paths value is `None` if the user closed the dialog
}
Sourcepub fn blocking_save_file(self) -> Option<FilePath>
pub fn blocking_save_file(self) -> Option<FilePath>
Shows the dialog to save a file. This is a blocking operation, and should NOT be used when running on the main thread context.
§Examples
use tauri_plugin_dialog::DialogExt;
#[tauri::command]
async fn my_command(app: tauri::AppHandle) {
let file_path = app.dialog().file().blocking_save_file();
// do something with the optional file path here
// the file path is `None` if the user closed the dialog
}