diff --git a/CHANGELOG.md b/CHANGELOG.md index 81a89cb..9f931d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Update `winit` in example to 0.29. - Update wasm CSS to respect the color scheme (including dark mode) - Fix macOS sync backend incorrectly setting the parent window +- Add `FileDialog/AsyncFileDialog::set_can_create_directories`, supported on macOS only. ## 0.13.0 - **[Breaking]** Users of the `xdg-portal` feature must now also select the `tokio` diff --git a/src/backend/macos/file_dialog/panel_ffi.rs b/src/backend/macos/file_dialog/panel_ffi.rs index 83bb3f3..7b3bbfe 100644 --- a/src/backend/macos/file_dialog/panel_ffi.rs +++ b/src/backend/macos/file_dialog/panel_ffi.rs @@ -193,6 +193,13 @@ impl Panel { panel.set_parent(parent); } + if let Some(can) = opt.can_create_directories { + panel.set_can_create_directories(match can { + true => YES, + false => NO, + }); + } + panel.set_can_choose_directories(NO); panel.set_can_choose_files(YES); @@ -222,6 +229,13 @@ impl Panel { panel.set_parent(parent); } + if let Some(can) = opt.can_create_directories { + panel.set_can_create_directories(match can { + true => YES, + false => NO, + }); + } + panel } @@ -240,8 +254,13 @@ impl Panel { panel.set_parent(parent); } + let can_create_directories = opt.can_create_directories.unwrap_or(true); + panel.set_can_create_directories(match can_create_directories { + true => YES, + false => NO, + }); + panel.set_can_choose_directories(YES); - panel.set_can_create_directories(YES); panel.set_can_choose_files(NO); panel @@ -262,8 +281,13 @@ impl Panel { panel.set_parent(parent); } + let can = opt.can_create_directories.unwrap_or(true); + panel.set_can_create_directories(match can { + true => YES, + false => NO, + }); + panel.set_can_choose_directories(YES); - panel.set_can_create_directories(YES); panel.set_can_choose_files(NO); panel.set_allows_multiple_selection(YES); @@ -289,6 +313,13 @@ impl Panel { panel.set_parent(parent); } + if let Some(can) = opt.can_create_directories { + panel.set_can_create_directories(match can { + true => YES, + false => NO, + }); + } + panel.set_can_choose_directories(NO); panel.set_can_choose_files(YES); panel.set_allows_multiple_selection(YES); diff --git a/src/file_dialog.rs b/src/file_dialog.rs index 435383a..75d574f 100644 --- a/src/file_dialog.rs +++ b/src/file_dialog.rs @@ -24,6 +24,7 @@ pub struct FileDialog { pub(crate) file_name: Option, pub(crate) title: Option, pub(crate) parent: Option, + pub(crate) can_create_directories: Option, } // Oh god, I don't like sending RawWindowHandle between threads but here we go anyways... @@ -92,6 +93,13 @@ impl FileDialog { self.parent = parent.window_handle().ok().map(|x| x.as_raw()); self } + + /// Set can create directories in the dialog. + /// Suported in: `macos`. + pub fn set_can_create_directories(mut self, can: bool) -> Self { + self.can_create_directories.replace(can); + self + } } #[cfg(not(target_arch = "wasm32"))] @@ -203,6 +211,13 @@ impl AsyncFileDialog { self.file_dialog = self.file_dialog.set_parent(parent); self } + + /// Set can create directories in the dialog. + /// Suported in: `macos`. + pub fn set_can_create_directories(mut self, can: bool) -> Self { + self.file_dialog = self.file_dialog.set_can_create_directories(can); + self + } } use crate::backend::AsyncFilePickerDialogImpl;