From d5b082c09371fe69beea259472ea8add0a0f6193 Mon Sep 17 00:00:00 2001 From: yasirkula Date: Sun, 3 Nov 2024 12:52:18 +0300 Subject: [PATCH] Added "Hide Search Results" to search result groups' context menu if their search results are filtered via a search term (i.e. text filtering). For example, you can filter search results with term "[Prefab object]" and then right click the group and select this option to hide all prefab instance occurrences in that group --- .../AssetUsageDetector/Editor/SearchResult.cs | 45 +++++++++++++------ .../Editor/SearchResultTreeView.cs | 2 +- Plugins/AssetUsageDetector/README.txt | 2 +- package.json | 2 +- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/Plugins/AssetUsageDetector/Editor/SearchResult.cs b/Plugins/AssetUsageDetector/Editor/SearchResult.cs index 543d7f5..fe9d175 100644 --- a/Plugins/AssetUsageDetector/Editor/SearchResult.cs +++ b/Plugins/AssetUsageDetector/Editor/SearchResult.cs @@ -778,28 +778,47 @@ public float DrawOnGUI( SearchResult searchResult, EditorWindow window, float sc IsExpanded = true; } ); - if( searchResult != null && searchResult.NumberOfGroups > 1 && !string.IsNullOrEmpty( treeViewState.searchTerm ) ) + if( !string.IsNullOrEmpty( treeViewState.searchTerm ) ) { if( contextMenu.GetItemCount() > 0 ) contextMenu.AddSeparator( "" ); - contextMenu.AddItem( new GUIContent( "Apply Search to All Results" ), false, () => + if( searchResult != null && searchResult.NumberOfGroups > 1 ) { - for( int i = 0; i < searchResult.NumberOfGroups; i++ ) + contextMenu.AddItem( new GUIContent( "Apply Search to All Results" ), false, () => { - if( searchResult[i].treeView == null ) - continue; + for( int i = 0; i < searchResult.NumberOfGroups; i++ ) + { + if( searchResult[i].treeView == null ) + continue; - string previousSearchTerm = searchResult[i].treeViewState.searchTerm ?? ""; - SearchResultTreeView.SearchMode previousSearchMode = searchResult[i].treeViewState.searchMode; + string previousSearchTerm = searchResult[i].treeViewState.searchTerm ?? ""; + SearchResultTreeView.SearchMode previousSearchMode = searchResult[i].treeViewState.searchMode; - searchResult[i].treeViewState.searchTerm = treeViewState.searchTerm ?? ""; - searchResult[i].treeViewState.searchMode = treeViewState.searchMode; + searchResult[i].treeViewState.searchTerm = treeViewState.searchTerm ?? ""; + searchResult[i].treeViewState.searchMode = treeViewState.searchMode; - if( treeViewState.searchTerm != previousSearchTerm || treeViewState.searchMode != previousSearchMode ) - searchResult[i].treeView.RefreshSearch( previousSearchTerm ); - } - } ); + if( treeViewState.searchTerm != previousSearchTerm || treeViewState.searchMode != previousSearchMode ) + searchResult[i].treeView.RefreshSearch( previousSearchTerm ); + } + } ); + } + + IList treeViewRows = treeView.GetRows(); + if( treeViewRows.Count > 1 ) // References are at depth 1 so if there are any references, at least 2 rows must exist + { + contextMenu.AddItem( new GUIContent( "Hide Search Results" ), false, () => + { + List removedRows = new List( treeViewRows.Count ); + for( int i = treeViewRows.Count - 1; i >= 0; i-- ) + { + if( treeViewRows[i].depth > 0 ) + removedRows.Add( treeViewRows[i].id ); + } + + treeView.HideItems( removedRows ); + } ); + } } } diff --git a/Plugins/AssetUsageDetector/Editor/SearchResultTreeView.cs b/Plugins/AssetUsageDetector/Editor/SearchResultTreeView.cs index 20c6c3f..2c2abc8 100644 --- a/Plugins/AssetUsageDetector/Editor/SearchResultTreeView.cs +++ b/Plugins/AssetUsageDetector/Editor/SearchResultTreeView.cs @@ -991,7 +991,7 @@ private bool GetReferenceNodeOccurrenceIdsRecursive( TreeViewItem item, HashSet< return referenceNodes.Contains( GetDataFromId( item.id ).node ); } - private void HideItems( IList ids ) + public void HideItems( IList ids ) { if( ids.Count > 0 ) { diff --git a/Plugins/AssetUsageDetector/README.txt b/Plugins/AssetUsageDetector/README.txt index f962275..2b43697 100644 --- a/Plugins/AssetUsageDetector/README.txt +++ b/Plugins/AssetUsageDetector/README.txt @@ -1,4 +1,4 @@ -= Asset Usage Detector (v2.5.3) = += Asset Usage Detector (v2.5.4) = Documentation: https://github.com/yasirkula/UnityAssetUsageDetector E-mail: yasirkula@gmail.com \ No newline at end of file diff --git a/package.json b/package.json index f703d99..4e86af0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.yasirkula.assetusagedetector", "displayName": "Asset Usage Detector", - "version": "2.5.3", + "version": "2.5.4", "documentationUrl": "https://github.com/yasirkula/UnityAssetUsageDetector", "changelogUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/releases", "licensesUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/blob/master/LICENSE.txt",