Skip to content

Commit

Permalink
Close preferences with Esc (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksongoode authored Jul 3, 2024
1 parent 16b06ab commit 1b1f0c4
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion psst-gui/src/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ impl Delegate {
self.main_window = None;
self.preferences_window = None;
}

fn close_preferences(&mut self, ctx: &mut DelegateCtx) {
if let Some(id) = self.preferences_window.take() {
ctx.submit_command(commands::CLOSE_WINDOW.to(id));
}
}
}

impl AppDelegate<AppState> for Delegate {
Expand All @@ -112,6 +118,14 @@ impl AppDelegate<AppState> for Delegate {
} else if cmd.is(cmd::CLOSE_ALL_WINDOWS) {
self.close_all_windows(ctx);
Handled::Yes
} else if cmd.is(commands::CLOSE_WINDOW) {
if let Some(window_id) = self.preferences_window {
if target == Target::Window(window_id) {
self.close_preferences(ctx);
return Handled::Yes;
}
}
Handled::No
} else if let Some(text) = cmd.get(cmd::COPY) {
Application::global().clipboard().put_string(text);
Handled::Yes
Expand Down Expand Up @@ -149,7 +163,7 @@ impl AppDelegate<AppState> for Delegate {

fn event(
&mut self,
_ctx: &mut DelegateCtx,
ctx: &mut DelegateCtx,
window_id: WindowId,
event: Event,
data: &mut AppState,
Expand All @@ -164,6 +178,13 @@ impl AppDelegate<AppState> for Delegate {
data.config.window_size = size;
}
}
} else if self.preferences_window == Some(window_id) {
if let Event::KeyDown(key_event) = &event {
if key_event.key == druid::KbKey::Escape {
ctx.submit_command(commands::CLOSE_WINDOW.to(window_id));
return None;
}
}
}
Some(event)
}
Expand Down

0 comments on commit 1b1f0c4

Please sign in to comment.