Skip to content

Commit

Permalink
Add OPEN_PANEL_CANCELLED and SAVE_PANEL_CANCELLED commands
Browse files Browse the repository at this point in the history
This lets the user take special action if needed in either of
these cases.
  • Loading branch information
cmyr committed Jul 14, 2020
1 parent 1d6a30f commit 5bc7dae
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ You can find its changes [documented below](#060---2020-06-01).
### Highlights

### Added
- `OPEN_PANEL_CANCELLED` and `SAVE_PANEL_CANCELLED` commands. ([#1061] by @cmyr)

- Added ctrl/shift key support to textbox. ([#1063] by [@vkahl])

Expand Down Expand Up @@ -351,6 +352,7 @@ Last release without a changelog :(
[#1050]: https://github.com/linebender/druid/pull/1050
[#1054]: https://github.com/linebender/druid/pull/1054
[#1058]: https://github.com/linebender/druid/pull/1058
[#1061]: https://github.com/linebender/druid/pull/1061
[#1062]: https://github.com/linebender/druid/pull/1062
[#1081]: https://github.com/linebender/druid/pull/1081

Expand All @@ -360,4 +362,3 @@ Last release without a changelog :(
[0.4.0]: https://github.com/linebender/druid/compare/v0.3.2...v0.4.0
[0.3.2]: https://github.com/linebender/druid/compare/v0.3.1...v0.3.2
[0.3.1]: https://github.com/linebender/druid/compare/v0.3.0...v0.3.1

6 changes: 6 additions & 0 deletions druid/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ pub mod sys {
pub const SHOW_OPEN_PANEL: Selector<FileDialogOptions> =
Selector::new("druid-builtin.menu-file-open");

/// Sent when the user cancels an open file panel.
pub const OPEN_PANEL_CANCELLED: Selector = Selector::new("druid-builtin.open-panel-cancelled");

/// Open a file, must be handled by the application.
///
/// [`FileInfo`]: ../struct.FileInfo.html
Expand All @@ -206,6 +209,9 @@ pub mod sys {
pub const SHOW_SAVE_PANEL: Selector<FileDialogOptions> =
Selector::new("druid-builtin.menu-file-save-as");

/// Sent when the user cancels a save file panel.
pub const SAVE_PANEL_CANCELLED: Selector = Selector::new("druid-builtin.save-panel-cancelled");

/// Save the current file, must be handled by the application.
///
/// How this should be handled depends on the payload:
Expand Down
6 changes: 6 additions & 0 deletions druid/src/win_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,9 @@ impl<T: Data> AppState<T> {
if let Some(info) = result {
let cmd = Command::new(sys_cmd::OPEN_FILE, info);
self.inner.borrow_mut().dispatch_cmd(window_id.into(), cmd);
} else {
let cmd = sys_cmd::OPEN_PANEL_CANCELLED.into();
self.inner.borrow_mut().dispatch_cmd(window_id.into(), cmd);
}
}

Expand All @@ -596,6 +599,9 @@ impl<T: Data> AppState<T> {
if let Some(info) = result {
let cmd = Command::new(sys_cmd::SAVE_FILE, Some(info));
self.inner.borrow_mut().dispatch_cmd(window_id.into(), cmd);
} else {
let cmd = sys_cmd::SAVE_PANEL_CANCELLED.into();
self.inner.borrow_mut().dispatch_cmd(window_id.into(), cmd);
}
}

Expand Down

0 comments on commit 5bc7dae

Please sign in to comment.