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 Jun 26, 2020
1 parent 0548b7a commit fc835a2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions 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
- Add `OPEN_PANEL_CANCELLED` and `SAVE_PANEL_CANCELLED` commands ([#1061] by @cmyr)

### Changed

Expand Down Expand Up @@ -340,6 +341,7 @@ Last release without a changelog :(
[#1043]: https://github.com/linebender/druid/pull/1043
[#1050]: https://github.com/linebender/druid/pull/1050
[#1054]: https://github.com/linebender/druid/pull/1054
[#1061]: https://github.com/xi-editor/druid/pull/1062

[Unreleased]: https://github.com/linebender/druid/compare/v0.6.0...master
[0.6.0]: https://github.com/linebender/druid/compare/v0.5.0...v0.6.0
Expand Down
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 an open 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 fc835a2

Please sign in to comment.