mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-06-06 13:53:54 +02:00
feat(dialog): allow setting canCreateDirectories on macOS (#978)
* feat(dialog): allow setting `canCreateDirectories` on macOS closes #949 * Discard changes to plugins/log/src/api-iife.js * Discard changes to plugins/store/src/api-iife.js * Discard changes to plugins/window-state/src/api-iife.js * Update plugins/dialog/src/commands.rs Co-authored-by: Fabian-Lars <fabianlars@fabianlars.de> * Update plugins/dialog/src/commands.rs Co-authored-by: Fabian-Lars <fabianlars@fabianlars.de> * Update plugins/dialog/src/lib.rs Co-authored-by: Fabian-Lars <fabianlars@fabianlars.de> * Update plugins/dialog/guest-js/index.ts Co-authored-by: Fabian-Lars <fabianlars@fabianlars.de> * Update plugins/dialog/guest-js/index.ts Co-authored-by: Fabian-Lars <fabianlars@fabianlars.de> --------- Co-authored-by: Fabian-Lars <fabianlars@fabianlars.de>
This commit is contained in:
@@ -55,6 +55,8 @@ interface OpenDialogOptions {
|
||||
* Defines whether subdirectories will be allowed on the scope or not.
|
||||
*/
|
||||
recursive?: boolean;
|
||||
/** Whether to allow creating directories in the dialog. Enabled by default. **macOS Only** */
|
||||
canCreateDirectories?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,6 +75,8 @@ interface SaveDialogOptions {
|
||||
* If it's not an existing directory, the file name will be set to the dialog's file name input and the dialog will be set to the parent folder.
|
||||
*/
|
||||
defaultPath?: string;
|
||||
/** Whether to allow creating directories in the dialog. Enabled by default. **macOS Only** */
|
||||
canCreateDirectories?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -51,6 +51,8 @@ pub struct OpenDialogOptions {
|
||||
#[serde(default)]
|
||||
#[cfg_attr(mobile, allow(dead_code))]
|
||||
recursive: bool,
|
||||
/// Whether to allow creating directories in the dialog **macOS Only**
|
||||
can_create_directories: Option<bool>,
|
||||
}
|
||||
|
||||
/// The options for the save dialog API.
|
||||
@@ -65,6 +67,8 @@ pub struct SaveDialogOptions {
|
||||
filters: Vec<DialogFilter>,
|
||||
/// The initial path of the dialog.
|
||||
default_path: Option<PathBuf>,
|
||||
/// Whether to allow creating directories in the dialog **macOS Only**
|
||||
can_create_directories: Option<bool>,
|
||||
}
|
||||
|
||||
fn set_default_path<R: Runtime>(
|
||||
@@ -105,6 +109,9 @@ pub(crate) async fn open<R: Runtime>(
|
||||
if let Some(default_path) = options.default_path {
|
||||
dialog_builder = set_default_path(dialog_builder, default_path);
|
||||
}
|
||||
if let Some(can) = options.can_create_directories {
|
||||
dialog_builder = dialog_builder.set_can_create_directories(can);
|
||||
}
|
||||
for filter in options.filters {
|
||||
let extensions: Vec<&str> = filter.extensions.iter().map(|s| &**s).collect();
|
||||
dialog_builder = dialog_builder.add_filter(filter.name, &extensions);
|
||||
@@ -185,6 +192,9 @@ pub(crate) async fn save<R: Runtime>(
|
||||
if let Some(default_path) = options.default_path {
|
||||
dialog_builder = set_default_path(dialog_builder, default_path);
|
||||
}
|
||||
if let Some(can) = options.can_create_directories {
|
||||
dialog_builder = dialog_builder.set_can_create_directories(can);
|
||||
}
|
||||
for filter in options.filters {
|
||||
let extensions: Vec<&str> = filter.extensions.iter().map(|s| &**s).collect();
|
||||
dialog_builder = dialog_builder.add_filter(filter.name, &extensions);
|
||||
|
||||
@@ -127,6 +127,8 @@ impl<R: Runtime> From<FileDialogBuilder<R>> for FileDialog {
|
||||
builder = builder.set_parent(&WindowHandle(parent));
|
||||
}
|
||||
|
||||
builder = builder.set_can_create_directories(d.can_create_directories.unwrap_or(true));
|
||||
|
||||
builder
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,6 +267,7 @@ pub struct FileDialogBuilder<R: Runtime> {
|
||||
pub(crate) starting_directory: Option<PathBuf>,
|
||||
pub(crate) file_name: Option<String>,
|
||||
pub(crate) title: Option<String>,
|
||||
pub(crate) can_create_directories: Option<bool>,
|
||||
#[cfg(desktop)]
|
||||
pub(crate) parent: Option<raw_window_handle::RawWindowHandle>,
|
||||
}
|
||||
@@ -291,6 +292,7 @@ impl<R: Runtime> FileDialogBuilder<R> {
|
||||
starting_directory: None,
|
||||
file_name: None,
|
||||
title: None,
|
||||
can_create_directories: None,
|
||||
#[cfg(desktop)]
|
||||
parent: None,
|
||||
}
|
||||
@@ -345,6 +347,12 @@ impl<R: Runtime> FileDialogBuilder<R> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set whether it should be possible to create new directories in the dialog. Enabled by default. **macOS only**.
|
||||
pub fn set_can_create_directories(mut self, can: bool) -> Self {
|
||||
self.can_create_directories.replace(can);
|
||||
self
|
||||
}
|
||||
|
||||
/// 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.
|
||||
|
||||
Reference in New Issue
Block a user