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 26, 2020
1 parent f3ce232 commit 14c4958
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)

- Export `Image` and `ImageData` by default. ([#1011] by [@covercash2])
- Re-export `druid_shell::Scalable` under `druid` namespace. ([#1075] by [@ForLoveOfCats])
Expand Down Expand Up @@ -360,6 +361,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
[#1072]: https://github.com/linebender/druid/pull/1072
[#1075]: https://github.com/linebender/druid/pull/1075
Expand All @@ -375,4 +377,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 14c4958

Please sign in to comment.