From 2020451686767bc3736ceb6abfeb99e91bea3cc7 Mon Sep 17 00:00:00 2001 From: Areloch Date: Sat, 18 May 2019 02:37:28 -0500 Subject: [PATCH] Forgot changes to the guiTreeViewCtrl to enable advanced filtering behavior. --- .../source/gui/controls/guiTreeViewCtrl.cpp | 47 +++++++++++++++++-- Engine/source/gui/controls/guiTreeViewCtrl.h | 10 +++- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/Engine/source/gui/controls/guiTreeViewCtrl.cpp b/Engine/source/gui/controls/guiTreeViewCtrl.cpp index f9ad7e411..62f3a86a7 100644 --- a/Engine/source/gui/controls/guiTreeViewCtrl.cpp +++ b/Engine/source/gui/controls/guiTreeViewCtrl.cpp @@ -832,6 +832,8 @@ GuiTreeViewCtrl::GuiTreeViewCtrl() mTexSelected = NULL; mRenderTooltipDelegate.bind( this, &GuiTreeViewCtrl::renderTooltip ); + + mDoFilterChildren = true; } //----------------------------------------------------------------------------- @@ -1122,7 +1124,7 @@ void GuiTreeViewCtrl::_expandObjectHierarchy( SimGroup* group ) //------------------------------------------------------------------------------ -void GuiTreeViewCtrl::_buildItem( Item* item, U32 tabLevel, bool bForceFullUpdate ) +void GuiTreeViewCtrl::_buildItem( Item* item, U32 tabLevel, bool bForceFullUpdate, bool skipFlter ) { if (!item || !mActive || !isVisible() || !mProfile ) return; @@ -1145,7 +1147,7 @@ void GuiTreeViewCtrl::_buildItem( Item* item, U32 tabLevel, bool bForceFullUpdat // If we have a filter pattern, sync the item's filtering status to it. - if( !getFilterText().isEmpty() ) + if( !getFilterText().isEmpty() && !skipFlter) { // Determine the filtering status by looking for the filter // text in the item's display text. @@ -1154,7 +1156,11 @@ void GuiTreeViewCtrl::_buildItem( Item* item, U32 tabLevel, bool bForceFullUpdat item->getDisplayText( sizeof( displayText ), displayText ); if( !dStristr( displayText, mFilterText ) ) { - item->mState.set( Item::Filtered ); + //Last check, see if we special-exception this item + if (!mItemFilterExceptionList.contains(item->mId)) + item->mState.set(Item::Filtered); + else + item->mState.clear(Item::Filtered); // If it's not a parent, we're done. Otherwise, there may be children // that are not filtered so we need to process them first. @@ -1163,7 +1169,9 @@ void GuiTreeViewCtrl::_buildItem( Item* item, U32 tabLevel, bool bForceFullUpdat return; } else - item->mState.clear( Item::Filtered ); + { + item->mState.clear(Item::Filtered); + } } else item->mState.clear( Item::Filtered ); @@ -1217,7 +1225,10 @@ void GuiTreeViewCtrl::_buildItem( Item* item, U32 tabLevel, bool bForceFullUpdat Item *pChildTemp = child; child = child->mNext; - _buildItem( pChildTemp, tabLevel + 1, bForceFullUpdate ); + if (!mItemFilterExceptionList.contains(item->mId) && !mDoFilterChildren && !item->isFiltered()) + _buildItem( pChildTemp, tabLevel + 1, bForceFullUpdate, true ); + else + _buildItem(pChildTemp, tabLevel + 1, bForceFullUpdate, false); } } } @@ -4775,6 +4786,18 @@ void GuiTreeViewCtrl::setFilterText( const String& text ) mFlags.set( RebuildVisible ); } +void GuiTreeViewCtrl::setItemFilterException(U32 item, bool isExempted) +{ + if (isExempted) + { + mItemFilterExceptionList.push_back(item); + } + else + { + mItemFilterExceptionList.remove(item); + } +} + //============================================================================= // Console Methods. //============================================================================= @@ -5574,6 +5597,20 @@ DefineEngineMethod( GuiTreeViewCtrl, setFilterText, void, ( const char* pattern object->setFilterText( pattern ); } +DefineEngineMethod(GuiTreeViewCtrl, setFilterChildren, void, (bool doFilterChildren), (true), + "Sets if the filter will also apply to any children of items that manage to pass being filtered.\n\n" + "@param doFilterChildren If true, items that pass the filter do not have their children filtered. If false, all items are filtered.\n\n") +{ + object->setFilterChildren(doFilterChildren); +} + +DefineEngineMethod(GuiTreeViewCtrl, setItemFilterException, void, (U32 item, bool isExempt), (0, true), + "Set a given item to be excluded from being filtered.\n\n" + "@param item Item ID of the item that is to be exempt from the filter.\n\n" + "@param isExempt If the item is exempt from the filter.\n\n") +{ + object->setItemFilterException(item, isExempt); +} //----------------------------------------------------------------------------- DefineEngineMethod( GuiTreeViewCtrl, clearFilterText, void, (),, diff --git a/Engine/source/gui/controls/guiTreeViewCtrl.h b/Engine/source/gui/controls/guiTreeViewCtrl.h index 17b9aed04..123118db7 100644 --- a/Engine/source/gui/controls/guiTreeViewCtrl.h +++ b/Engine/source/gui/controls/guiTreeViewCtrl.h @@ -356,6 +356,11 @@ class GuiTreeViewCtrl : public GuiArrayCtrl /// Current filter that determines which items in the tree are displayed and which are hidden. String mFilterText; + /// If true, all items are filtered. If false, then children of items that successfully pass filter are not filtered + bool mDoFilterChildren; + + Vector mItemFilterExceptionList; + /// If true, a trace of actions taken by the control is logged to the console. Can /// be turned on with the setDebug() script method. bool mDebug; @@ -431,7 +436,7 @@ class GuiTreeViewCtrl : public GuiArrayCtrl void _deleteItem(Item* item); - void _buildItem(Item* item, U32 tabLevel, bool bForceFullUpdate = false); + void _buildItem(Item* item, U32 tabLevel, bool bForceFullUpdate = false, bool skipFlter = false); Item* _findItemByAmbiguousId( S32 itemOrObjectId, bool buildVirtual = true ); @@ -569,6 +574,9 @@ class GuiTreeViewCtrl : public GuiArrayCtrl /// matches this pattern are displayed. void setFilterText( const String& text ); + void setFilterChildren(bool doFilter) { mDoFilterChildren = doFilter; } + void setItemFilterException(U32 item, bool isExempt); + /// Clear the current item filtering pattern. void clearFilterText() { setFilterText( String::EmptyString ); }