Skip to content

Commit

Permalink
#3250: The visibility logic needs to inspect all child nodes too. Thi…
Browse files Browse the repository at this point in the history
…s is likely to check the same items over and over again, but as long as this is not a performance problem, this can be left as it is.
  • Loading branch information
codereader committed Jan 9, 2021
1 parent fbda72d commit a77d3da
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
30 changes: 28 additions & 2 deletions libs/wxutil/dataview/ResourceTreeView.cpp
Expand Up @@ -453,13 +453,39 @@ bool ResourceTreeView::IsTreeModelRowVisible(wxutil::TreeModel::Row& row)
return true; // done here
}

return !IsTreeModelRowFilteredRecursively(row);
}

bool ResourceTreeView::IsTreeModelRowFilteredRecursively(wxutil::TreeModel::Row& row)
{
wxDataViewIconText iconAndName = row[_columns.iconAndName];

auto displayString = iconAndName.GetText().ToStdString();
string::to_lower(displayString);
rMessage() << "displayString: " << displayString << ": " << displayString.find(_filterText) << std::endl;
//rMessage() << "displayString: " << displayString << ": " << displayString.find(_filterText) << std::endl;

if (displayString.find(_filterText) != std::string::npos)
{
return false; // row itself is visible, no need to check child nodes
}

// This node might also be visible if a single child node is visible, dive into it
wxDataViewItemArray children;
_treeStore->GetChildren(row.getItem(), children);

for (const wxDataViewItem& child : children)
{
wxutil::TreeModel::Row childRow(child, *_treeStore);

if (!IsTreeModelRowFilteredRecursively(childRow))
{
return false; // unfiltered node, break the loop
}
}

return displayString.find(_filterText) != std::string::npos;
// Either we don't have any children, or
// all child nodes are filtered, so this node is filtered too
return true;
}

bool ResourceTreeView::IsTreeModelRowVisibleByViewMode(wxutil::TreeModel::Row& row)
Expand Down
3 changes: 3 additions & 0 deletions libs/wxutil/dataview/ResourceTreeView.h
Expand Up @@ -149,6 +149,9 @@ class ResourceTreeView :
// Returns true if the given row is visible according
// to the current view mode (show favourites vs. show all)
bool IsTreeModelRowVisibleByViewMode(TreeModel::Row& row);

// Returns true if the given row is filtered (i.e. node and all child nodes are invisible)
bool IsTreeModelRowFilteredRecursively(wxutil::TreeModel::Row& row);

void _onContextMenu(wxDataViewEvent& ev);
void _onTreeStorePopulationProgress(TreeModel::PopulationProgressEvent& ev);
Expand Down

0 comments on commit a77d3da

Please sign in to comment.