Skip to content

Commit

Permalink
feat(macos): add set_can_create_directories (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir authored Feb 14, 2024
1 parent 9639ccc commit fe60253
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
35 changes: 33 additions & 2 deletions src/backend/macos/file_dialog/panel_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand All @@ -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);

Expand All @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions src/file_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct FileDialog {
pub(crate) file_name: Option<String>,
pub(crate) title: Option<String>,
pub(crate) parent: Option<RawWindowHandle>,
pub(crate) can_create_directories: Option<bool>,
}

// Oh god, I don't like sending RawWindowHandle between threads but here we go anyways...
Expand Down Expand Up @@ -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"))]
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit fe60253

Please sign in to comment.