Skip to content

Commit

Permalink
#5288: ESC to exit search field in child window instead of closing th…
Browse files Browse the repository at this point in the history
…e dialog
  • Loading branch information
codereader committed Sep 19, 2020
1 parent 28c763f commit 321fc5b
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions libs/wxutil/TreeView.cpp
Expand Up @@ -35,7 +35,6 @@ class TreeView::Search :

~Search();

void OnIntervalReached(wxTimerEvent& ev);

void HandleKeyEvent(wxKeyEvent& ev);

Expand All @@ -46,6 +45,8 @@ class TreeView::Search :

private:
void HighlightMatch(const wxDataViewItem& item);
void _onIntervalReached(wxTimerEvent& ev);
void _onTreeViewCharHook(wxKeyEvent& keyEvent);
};

TreeView::TreeView(wxWindow* parent, TreeModel::Ptr model, long style) :
Expand Down Expand Up @@ -367,7 +368,7 @@ class TreeView::SearchPopupWindow :
_owner.Close();
}
}

void _onParentMoved(wxMoveEvent&)
{
Reposition();
Expand Down Expand Up @@ -397,7 +398,8 @@ TreeView::Search::Search(TreeView& treeView) :
_popup->Show();
_curSearchMatch = wxDataViewItem();

Bind(wxEVT_TIMER, std::bind(&Search::OnIntervalReached, this, std::placeholders::_1));
_treeView.Bind(wxEVT_CHAR_HOOK, &Search::_onTreeViewCharHook, this);
Bind(wxEVT_TIMER, &Search::_onIntervalReached, this);

_closeTimer.Start(MSECS_TO_AUTO_CLOSE_POPUP);
}
Expand All @@ -406,6 +408,9 @@ TreeView::Search::~Search()
{
_closeTimer.Stop();

_treeView.Unbind(wxEVT_CHAR_HOOK, &Search::_onTreeViewCharHook, this);
Unbind(wxEVT_TIMER, &Search::_onIntervalReached, this);

// Always hide popup windows before destroying them, otherwise the
// wx-internal wxCurrentPopupWindow pointer doesn't get cleared (in MSW at least)
_popup->Hide();
Expand All @@ -414,7 +419,20 @@ TreeView::Search::~Search()
_curSearchMatch = wxDataViewItem();
}

void TreeView::Search::OnIntervalReached(wxTimerEvent& ev)
void TreeView::Search::_onTreeViewCharHook(wxKeyEvent& ev)
{
if (ev.GetKeyCode() == WXK_ESCAPE)
{
// The parent dialog listens to ESC keys to close the window
// While this search window is alive, eat the event and close the popup instead
_treeView.CloseSearch();
return;
}

ev.Skip();
}

void TreeView::Search::_onIntervalReached(wxTimerEvent& ev)
{
// Disconnect the timing event
_closeTimer.Stop();
Expand Down

0 comments on commit 321fc5b

Please sign in to comment.