Skip to content

Commit

Permalink
Added "Hide Search Results" to search result groups' context menu if …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
yasirkula committed Nov 3, 2024
1 parent 1faa789 commit d5b082c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
45 changes: 32 additions & 13 deletions Plugins/AssetUsageDetector/Editor/SearchResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TreeViewItem> 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<int> removedRows = new List<int>( treeViewRows.Count );
for( int i = treeViewRows.Count - 1; i >= 0; i-- )
{
if( treeViewRows[i].depth > 0 )
removedRows.Add( treeViewRows[i].id );
}

treeView.HideItems( removedRows );
} );
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Plugins/AssetUsageDetector/Editor/SearchResultTreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ private bool GetReferenceNodeOccurrenceIdsRecursive( TreeViewItem item, HashSet<
return referenceNodes.Contains( GetDataFromId( item.id ).node );
}

private void HideItems( IList<int> ids )
public void HideItems( IList<int> ids )
{
if( ids.Count > 0 )
{
Expand Down
2 changes: 1 addition & 1 deletion Plugins/AssetUsageDetector/README.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit d5b082c

Please sign in to comment.