Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(macos): add set_can_create_directories #172

Merged
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
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
Loading