From 3d59db4be4532e73fbc407b6e09fe3f8ac6dfe80 Mon Sep 17 00:00:00 2001 From: Conrad Pankoff Date: Wed, 1 Jan 2020 11:58:37 +1100 Subject: [PATCH] LibGUI: Close and cancel GDialog on escape This is a small usability enhancement. If you press escape with a GDialog focused, it will now return its "Cancel" status. --- Libraries/LibGUI/GDialog.cpp | 14 ++++++++++++++ Libraries/LibGUI/GDialog.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/Libraries/LibGUI/GDialog.cpp b/Libraries/LibGUI/GDialog.cpp index 1db0fbadf4..5713e77d40 100644 --- a/Libraries/LibGUI/GDialog.cpp +++ b/Libraries/LibGUI/GDialog.cpp @@ -1,5 +1,6 @@ #include #include +#include GDialog::GDialog(CObject* parent) : GWindow(parent) @@ -40,6 +41,19 @@ void GDialog::done(int result) m_event_loop->quit(result); } +void GDialog::event(CEvent& event) +{ + if (event.type() == GEvent::KeyUp) { + auto& key_event = static_cast(event); + if (key_event.key() == KeyCode::Key_Escape) { + done(ExecCancel); + return; + } + } + + GWindow::event(event); +} + void GDialog::close() { GWindow::close(); diff --git a/Libraries/LibGUI/GDialog.h b/Libraries/LibGUI/GDialog.h index 581d2b406e..5303eb2ac3 100644 --- a/Libraries/LibGUI/GDialog.h +++ b/Libraries/LibGUI/GDialog.h @@ -19,6 +19,8 @@ public: int result() const { return m_result; } void done(int result); + virtual void event(CEvent&) override; + virtual void close() override; protected: