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

Close preferences with Esc #486

Merged
merged 1 commit into from
Jul 3, 2024
Merged
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
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