Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/dialog-can-create-directories.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"dialog": "patch"
"dialog-js": "patch"
---

Allow configuring `canCreateDirectories` for open and save dialogs on macOS, if not configured, it will be set to `true` by default.
58 changes: 29 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/deep-link/src/api-iife.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions plugins/dialog/guest-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions plugins/dialog/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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>(
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions plugins/dialog/src/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
8 changes: 8 additions & 0 deletions plugins/dialog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
}
Expand All @@ -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,
}
Expand Down Expand Up @@ -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.
Expand Down