mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-24 09:52:31 +00:00
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.
This commit is contained in:
parent
8602fa5b49
commit
3d59db4be4
Notes:
sideshowbarker
2024-07-19 10:29:49 +09:00
Author: https://github.com/deoxxa
Commit: 3d59db4be4
Pull-request: https://github.com/SerenityOS/serenity/pull/939
2 changed files with 16 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include <LibGUI/GDesktop.h>
|
#include <LibGUI/GDesktop.h>
|
||||||
#include <LibGUI/GDialog.h>
|
#include <LibGUI/GDialog.h>
|
||||||
|
#include <LibGUI/GEvent.h>
|
||||||
|
|
||||||
GDialog::GDialog(CObject* parent)
|
GDialog::GDialog(CObject* parent)
|
||||||
: GWindow(parent)
|
: GWindow(parent)
|
||||||
|
@ -40,6 +41,19 @@ void GDialog::done(int result)
|
||||||
m_event_loop->quit(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()
|
void GDialog::close()
|
||||||
{
|
{
|
||||||
GWindow::close();
|
GWindow::close();
|
||||||
|
|
|
@ -19,6 +19,8 @@ public:
|
||||||
int result() const { return m_result; }
|
int result() const { return m_result; }
|
||||||
void done(int result);
|
void done(int result);
|
||||||
|
|
||||||
|
virtual void event(CEvent&) override;
|
||||||
|
|
||||||
virtual void close() override;
|
virtual void close() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue