Skip to content

Commit

Permalink
#4764: In cases the popup window is sticking around, allow ESC to clo…
Browse files Browse the repository at this point in the history
…se it immediately
  • Loading branch information
codereader committed Nov 11, 2022
1 parent c6eb476 commit 1a5db70
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion libs/wxutil/TransientPopupWindow.h
Expand Up @@ -10,13 +10,22 @@ namespace wxutil
* A popup window that is destroying itself as soon as it loses focus
*/
class TransientPopupWindow :
public wxPopupTransientWindow
public wxPopupTransientWindow,
public wxEventFilter
{
public:
TransientPopupWindow(wxWindow* parent) :
wxPopupTransientWindow(parent, wxBORDER_DEFAULT)
{
SetSizer(new wxBoxSizer(wxVERTICAL));

// Register as global filter to catch events
wxEvtHandler::AddFilter(this);
}

~TransientPopupWindow() override
{
wxEvtHandler::RemoveFilter(this);
}

void Dismiss() override
Expand All @@ -25,6 +34,18 @@ class TransientPopupWindow :
Destroy();
}

int FilterEvent(wxEvent& ev) override
{
// Close the popup on any ESC keypress
if (ev.GetEventType() == wxEVT_KEY_DOWN && static_cast<wxKeyEvent&>(ev).GetKeyCode() == WXK_ESCAPE)
{
Dismiss();
return Event_Processed;
}

return Event_Skip;
}

// Attempts to position the popup to the right or left of the given window
// The vertical offset is added to the screen position of the given window
void PositionNextTo(wxWindow* win, int verticalOffset, const wxSize& size)
Expand Down

0 comments on commit 1a5db70

Please sign in to comment.