From 0e20af8647040d6417103cd2c5948793b271f61d Mon Sep 17 00:00:00 2001 From: codereader Date: Fri, 15 Jan 2021 06:06:22 +0100 Subject: [PATCH] #3250: To rebuild the tree on filter text changes, TreeView::Rebuild is 1) doing too much and 2) is not present in Linux. It turns out a wxDataViewModel::Cleared() call is enough to let the attached view re-query the tree and achieve the desired effect. --- libs/wxutil/dataview/ResourceTreeView.cpp | 12 +++++++++++- libs/wxutil/dataview/ResourceTreeView.h | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libs/wxutil/dataview/ResourceTreeView.cpp b/libs/wxutil/dataview/ResourceTreeView.cpp index 0765baadf2..26c2b6bd45 100644 --- a/libs/wxutil/dataview/ResourceTreeView.cpp +++ b/libs/wxutil/dataview/ResourceTreeView.cpp @@ -207,7 +207,8 @@ void ResourceTreeView::SetFilterText(const wxString& filterText) wxDataViewItem item = GetSelection(); - Rebuild(); + // Update the top level tree items which rebuilds the view + UpdateTreeVisibility(); // Keep the previous selection if not filtered out and is meaningful if (item.IsOk() && _treeModelFilter->ItemIsVisible(item)) @@ -231,6 +232,15 @@ void ResourceTreeView::SetFilterText(const wxString& filterText) } } +void ResourceTreeView::UpdateTreeVisibility() +{ + if (_treeModelFilter) + { + // Notify the attached views that it should reload + _treeModelFilter->Cleared(); + } +} + void ResourceTreeView::JumpToFirstFilterMatch() { if (_filterText.empty()) return; diff --git a/libs/wxutil/dataview/ResourceTreeView.h b/libs/wxutil/dataview/ResourceTreeView.h index 75f04189ee..923941dd1f 100644 --- a/libs/wxutil/dataview/ResourceTreeView.h +++ b/libs/wxutil/dataview/ResourceTreeView.h @@ -153,6 +153,8 @@ class ResourceTreeView : virtual bool IsTreeModelRowVisible(TreeModel::Row& row); + virtual void UpdateTreeVisibility(); + private: // Returns true if the given row is visible according // to the current view mode (show favourites vs. show all)