From a77d3da3bdf741c5f3aa1891ff020a04b8d8a771 Mon Sep 17 00:00:00 2001 From: codereader Date: Sat, 9 Jan 2021 18:44:53 +0100 Subject: [PATCH] #3250: The visibility logic needs to inspect all child nodes too. This 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. --- libs/wxutil/dataview/ResourceTreeView.cpp | 30 +++++++++++++++++++++-- libs/wxutil/dataview/ResourceTreeView.h | 3 +++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/libs/wxutil/dataview/ResourceTreeView.cpp b/libs/wxutil/dataview/ResourceTreeView.cpp index 1fc47b4615..4b89caa281 100644 --- a/libs/wxutil/dataview/ResourceTreeView.cpp +++ b/libs/wxutil/dataview/ResourceTreeView.cpp @@ -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) diff --git a/libs/wxutil/dataview/ResourceTreeView.h b/libs/wxutil/dataview/ResourceTreeView.h index 8fc642cd06..fc5a00b66b 100644 --- a/libs/wxutil/dataview/ResourceTreeView.h +++ b/libs/wxutil/dataview/ResourceTreeView.h @@ -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);