Skip to content

Commit

Permalink
#6140: Clear the resource tree view toolbar's filter on ESC
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Oct 28, 2022
1 parent 4f48766 commit 3e3b99b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 15 additions & 1 deletion libs/wxutil/dataview/ResourceTreeViewToolbar.cpp
Expand Up @@ -12,7 +12,7 @@ namespace wxutil

namespace
{
constexpr const int APPLY_FILTER_TEXT_DELAY_MSEC = 250;
constexpr int APPLY_FILTER_TEXT_DELAY_MSEC = 250;
}

ResourceTreeViewToolbar::ResourceTreeViewToolbar(wxWindow* parent, ResourceTreeView* treeView) :
Expand Down Expand Up @@ -48,6 +48,7 @@ ResourceTreeViewToolbar::ResourceTreeViewToolbar(wxWindow* parent, ResourceTreeV
_filterEntry->SetMinSize(wxSize(100, -1));
_filterEntry->Bind(wxEVT_TEXT, &ResourceTreeViewToolbar::_onEntryText, this);
_filterEntry->Bind(wxEVT_CHAR, &ResourceTreeViewToolbar::_onEntryChar, this);
_filterEntry->Bind(wxEVT_KEY_DOWN, &ResourceTreeViewToolbar::_onEntryKeyDown, this);
_filterEntry->SetToolTip(_("Enter search text to filter the tree,\nuse arrow keys to navigate"));

auto nextImg = wxutil::GetLocalBitmap("arrow_down.png");
Expand Down Expand Up @@ -163,6 +164,19 @@ void ResourceTreeViewToolbar::_onEntryChar(wxKeyEvent& ev)
}
}

void ResourceTreeViewToolbar::_onEntryKeyDown(wxKeyEvent& ev)
{
if (ev.GetKeyCode() == WXK_ESCAPE)
{
// Clear the search box on esc and focus the tree view
ClearFilter();
_treeView->SetFocus();
return;
}

ev.Skip();
}

void ResourceTreeViewToolbar::_onEntryText(wxCommandEvent& ev)
{
HandleFilterEntryChanged();
Expand Down
1 change: 1 addition & 0 deletions libs/wxutil/dataview/ResourceTreeViewToolbar.h
Expand Up @@ -52,6 +52,7 @@ class ResourceTreeViewToolbar :
void JumpToPrevFilterMatch();

void _onEntryChar(wxKeyEvent& ev);
void _onEntryKeyDown(wxKeyEvent& ev);
void _onEntryText(wxCommandEvent& ev);
void _onFilterButtonToggled(wxCommandEvent& ev);
void _onTreeViewFilterTextCleared(wxCommandEvent& ev);
Expand Down

0 comments on commit 3e3b99b

Please sign in to comment.