Navigation Menu

Skip to content

Commit

Permalink
#3250: Add up/down button functionality like in the existing search p…
Browse files Browse the repository at this point in the history
…opups
  • Loading branch information
codereader committed Jan 10, 2021
1 parent c0f5a44 commit 3af5798
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 2 deletions.
26 changes: 26 additions & 0 deletions libs/wxutil/dataview/ResourceTreeView.cpp
Expand Up @@ -243,6 +243,32 @@ void ResourceTreeView::JumpToFirstFilterMatch()
}
}

void ResourceTreeView::JumpToNextFilterMatch()
{
if (_filterText.empty()) return;

auto selectedItem = GetSelection();
auto item = _treeModelFilter->FindNextString(_filterText, _colsToSearch, selectedItem);

if (item.IsOk())
{
JumpToSearchMatch(item);
}
}

void ResourceTreeView::JumpToPrevFilterMatch()
{
if (_filterText.empty()) return;

auto selectedItem = GetSelection();
auto item = _treeModelFilter->FindPrevString(_filterText, _colsToSearch, selectedItem);

if (item.IsOk())
{
JumpToSearchMatch(item);
}
}

void ResourceTreeView::ClearFilterText()
{
_filterText.clear();
Expand Down
5 changes: 4 additions & 1 deletion libs/wxutil/dataview/ResourceTreeView.h
Expand Up @@ -136,6 +136,10 @@ class ResourceTreeView :
// hook as an alternative to this method.
void AddCustomMenuItem(const ui::IMenuItemPtr& item);

virtual void JumpToFirstFilterMatch();
virtual void JumpToNextFilterMatch();
virtual void JumpToPrevFilterMatch();

protected:
virtual void PopulateContextMenu(wxutil::PopupMenu& popupMenu);

Expand All @@ -153,7 +157,6 @@ class ResourceTreeView :
// Returns true if the given row is filtered (i.e. node and all child nodes are invisible)
bool IsTreeModelRowFilteredRecursively(wxutil::TreeModel::Row& row);
bool RowContainsSearchString(wxutil::TreeModel::Row& row);
void JumpToFirstFilterMatch();

void _onContextMenu(wxDataViewEvent& ev);
void _onTreeStorePopulationProgress(TreeModel::PopulationProgressEvent& ev);
Expand Down
63 changes: 62 additions & 1 deletion libs/wxutil/dataview/ResourceTreeViewToolbar.h
@@ -1,6 +1,7 @@
#pragma once

#include "i18n.h"
#include "iuimanager.h"
#include <wx/panel.h>
#include <wx/sizer.h>
#include <wx/radiobut.h>
Expand All @@ -24,6 +25,9 @@ class ResourceTreeViewToolbar :
wxRadioButton* _showAll;
wxRadioButton* _showFavourites;

wxBitmapButton* _findPrevButton;
wxBitmapButton* _findNextButton;

public:
ResourceTreeViewToolbar(wxWindow* parent, ResourceTreeView* treeView = nullptr) :
wxPanel(parent, wxID_ANY),
Expand Down Expand Up @@ -61,8 +65,33 @@ class ResourceTreeViewToolbar :
_treeView->SetFilterText(ev.GetString().ToStdString());
}
});
filterEntry->Bind(wxEVT_CHAR, &ResourceTreeViewToolbar::_onEntryChar, this);

auto nextImg = wxArtProvider::GetBitmap(GlobalUIManager().ArtIdPrefix() + "arrow_down.png");
_findNextButton = new wxBitmapButton(this, wxID_ANY, nextImg);

auto prevImg = wxArtProvider::GetBitmap(GlobalUIManager().ArtIdPrefix() + "arrow_up.png");
_findPrevButton = new wxBitmapButton(this, wxID_ANY, prevImg);

_findNextButton->SetSize(wxSize(16, 16));
_findPrevButton->SetSize(wxSize(16, 16));

_findNextButton->SetToolTip(_("Go to next match"));
_findPrevButton->SetToolTip(_("Go to previous match"));

_findNextButton->Bind(wxEVT_BUTTON, [this](wxCommandEvent& ev)
{
jumpToNextFilterMatch();
});
_findPrevButton->Bind(wxEVT_BUTTON, [this](wxCommandEvent& ev)
{
jumpToPrevFilterMatch();
});

filterBox->Add(filterImage, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 6);
filterBox->Add(filterEntry, 0, wxALIGN_CENTER_VERTICAL, 6);
filterBox->Add(filterEntry, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 6);
filterBox->Add(_findPrevButton, 0, wxEXPAND | wxRIGHT, 3);
filterBox->Add(_findNextButton, 0, wxEXPAND, 6);

grid->Add(favourites, 0, wxALIGN_CENTER_VERTICAL| wxALIGN_LEFT | wxRIGHT, 6);
grid->Add(filterBox, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT, 6);
Expand All @@ -77,6 +106,38 @@ class ResourceTreeViewToolbar :
}

private:
void jumpToNextFilterMatch()
{
if (_treeView != nullptr)
{
_treeView->JumpToNextFilterMatch();
}
}

void jumpToPrevFilterMatch()
{
if (_treeView != nullptr)
{
_treeView->JumpToPrevFilterMatch();
}
}

void _onEntryChar(wxKeyEvent& ev)
{
if (ev.GetKeyCode() == WXK_UP)
{
jumpToPrevFilterMatch();
}
else if (ev.GetKeyCode() == WXK_DOWN)
{
jumpToNextFilterMatch();
}
else
{
ev.Skip();
}
}

void _onFilterButtonToggled(wxCommandEvent& ev)
{
if (_treeView == nullptr) return;
Expand Down

0 comments on commit 3af5798

Please sign in to comment.