From 16b0689841a7e0c6b7d92fa494367cb615ff4d51 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Sat, 24 Oct 2020 15:58:13 -0400 Subject: [PATCH] Make HTML message box close on escape key. Fixes: https://gitlab.com/kicad/code/kicad/-/issues/6110 --- common/html_messagebox.cpp | 13 +++++++++++++ include/dialog_shim.h | 3 ++- include/html_messagebox.h | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/common/html_messagebox.cpp b/common/html_messagebox.cpp index 8f30919321..c8789b7cc7 100644 --- a/common/html_messagebox.cpp +++ b/common/html_messagebox.cpp @@ -127,3 +127,16 @@ void HTML_MESSAGE_BOX::ShowModeless() Show( true ); } + + +void HTML_MESSAGE_BOX::OnCharHook( wxKeyEvent& aEvent ) +{ + // shift-return (Mac default) or Ctrl-Return (GTK) for OK + if( aEvent.GetKeyCode() == WXK_ESCAPE ) + { + wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) ); + return; + } + + aEvent.Skip(); +} diff --git a/include/dialog_shim.h b/include/dialog_shim.h index 2ef79229f8..ba1f8ec992 100644 --- a/include/dialog_shim.h +++ b/include/dialog_shim.h @@ -94,7 +94,8 @@ class DIALOG_SHIM : public wxDialog, public KIWAY_HOLDER */ void OnButton( wxCommandEvent& aEvent ); - void OnCharHook( wxKeyEvent& aEvt ); +protected: + virtual void OnCharHook( wxKeyEvent& aEvt ); public: diff --git a/include/html_messagebox.h b/include/html_messagebox.h index 41f2f4bf14..563ee855a6 100644 --- a/include/html_messagebox.h +++ b/include/html_messagebox.h @@ -38,6 +38,8 @@ protected: // Handlers for HTML_MESSAGE_BOX_BASE events. void OnOKButtonClick( wxCommandEvent& event ) override; + virtual void OnCharHook( wxKeyEvent& aEvt ) override; + public: HTML_MESSAGE_BOX( wxWindow* aParent, const wxString& aTitle = wxEmptyString, const wxPoint& aPosition = wxDefaultPosition,