Skip to content

Commit

Permalink
LibGUI: Close and cancel GDialog on escape
Browse files Browse the repository at this point in the history
This is a small usability enhancement. If you press escape with a GDialog
focused, it will now return its "Cancel" status.
  • Loading branch information
deoxxa authored and awesomekling committed Jan 1, 2020
1 parent 8602fa5 commit 3d59db4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Libraries/LibGUI/GDialog.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <LibGUI/GDesktop.h>
#include <LibGUI/GDialog.h>
#include <LibGUI/GEvent.h>

GDialog::GDialog(CObject* parent)
: GWindow(parent)
Expand Down Expand Up @@ -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<GKeyEvent&>(event);
if (key_event.key() == KeyCode::Key_Escape) {
done(ExecCancel);
return;
}
}

GWindow::event(event);
}

void GDialog::close()
{
GWindow::close();
Expand Down
2 changes: 2 additions & 0 deletions Libraries/LibGUI/GDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class GDialog : public GWindow {
int result() const { return m_result; }
void done(int result);

virtual void event(CEvent&) override;

virtual void close() override;

protected:
Expand Down

0 comments on commit 3d59db4

Please sign in to comment.