Struct tauri_plugin_dialog::FileDialogBuilder
source · 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>(self, parent: &W) -> Self
pub fn set_parent<W: HasWindowHandle>(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<FileResponse>) + Send + 'static>(self, f: F)
pub fn pick_file<F: FnOnce(Option<FileResponse>) + 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()
.build(tauri::generate_context!("test/tauri.conf.json"))
.expect("failed to build tauri app")
.run(|app, _event| {
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
})
})
sourcepub fn pick_files<F: FnOnce(Option<Vec<FileResponse>>) + Send + 'static>(
self,
f: F
)
pub fn pick_files<F: FnOnce(Option<Vec<FileResponse>>) + 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_plugin_dialog::DialogExt;
tauri::Builder::default()
.build(tauri::generate_context!("test/tauri.conf.json"))
.expect("failed to build tauri app")
.run(|app, _event| {
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
})
})
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_plugin_dialog::DialogExt;
tauri::Builder::default()
.build(tauri::generate_context!("test/tauri.conf.json"))
.expect("failed to build tauri app")
.run(|app, _event| {
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
})
})
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_plugin_dialog::DialogExt;
tauri::Builder::default()
.build(tauri::generate_context!("test/tauri.conf.json"))
.expect("failed to build tauri app")
.run(|app, _event| {
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
})
})
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_plugin_dialog::DialogExt;
tauri::Builder::default()
.build(tauri::generate_context!("test/tauri.conf.json"))
.expect("failed to build tauri app")
.run(|app, _event| {
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
})
})
source§impl<R: Runtime> FileDialogBuilder<R>
impl<R: Runtime> FileDialogBuilder<R>
Blocking APIs.
sourcepub fn blocking_pick_file(self) -> Option<FileResponse>
pub fn blocking_pick_file(self) -> Option<FileResponse>
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<FileResponse>>
pub fn blocking_pick_files(self) -> Option<Vec<FileResponse>>
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<PathBuf>
pub fn blocking_pick_folder(self) -> Option<PathBuf>
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<PathBuf>>
pub fn blocking_pick_folders(self) -> Option<Vec<PathBuf>>
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<PathBuf>
pub fn blocking_save_file(self) -> Option<PathBuf>
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
}