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>

source

pub fn new(dialog: Dialog<R>) -> Self

Gets the default file dialog builder.

source

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

source

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

Set starting directory of the dialog.

source

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

Set starting file name of the dialog.

source

pub fn set_parent<W: HasWindowHandle>(self, parent: &W) -> Self

Sets the parent window of the dialog.

source

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

Set the title of the dialog.

source

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.

source

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
    })
  })
source

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
    })
  })
source

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
    })
  })
source

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
    })
  })
source

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>

Blocking APIs.

source

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
}
source

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
}
source

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
}
source

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
}
source

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
}

Trait Implementations§

source§

impl<R: Debug + Runtime> Debug for FileDialogBuilder<R>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<R: Runtime> From<FileDialogBuilder<R>> for AsyncFileDialog

source§

fn from(d: FileDialogBuilder<R>) -> Self

Converts to this type from the input type.
source§

impl<R: Runtime> Send for FileDialogBuilder<R>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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.