@@ -27,7 +27,6 @@ namespace WallstopStudios.DataVisualizer.Editor
2727 using UnityEngine . UIElements ;
2828 using Utilities ;
2929 using Helper ;
30- using NUnit . Framework ;
3130 using Debug = UnityEngine . Debug ;
3231 using Object = UnityEngine . Object ;
3332
@@ -3392,11 +3391,7 @@ private void HandleCreateConfirmed(Type type, TextField nameField, Label errorLa
33923391 if ( type == _namespaceController . SelectedType )
33933392 {
33943393 _selectedObjects . Add ( instance ) ;
3395- BuildObjectRow ( instance , _objectListContainer . childCount ) ;
3396- foreach ( VisualElement child in _objectListContainer . Children ( ) )
3397- {
3398- NamespaceController . RecalibrateVisualElements ( child , offset : 1 ) ;
3399- }
3394+ BuildObjectsView ( ) ;
34003395 }
34013396 }
34023397
@@ -4633,9 +4628,12 @@ private VisualElement CreateObjectColumn()
46334628
46344629 SetCurrentPage ( _namespaceController . SelectedType , currentPage - 1 ) ;
46354630 BuildObjectsView ( ) ;
4636- } ) { text = "←" } ;
4631+ } )
4632+ {
4633+ text = "←" ,
4634+ } ;
46374635 _previousPageButton . AddToClassList ( "go-button-disabled" ) ;
4638-
4636+
46394637 _currentPageField = new IntegerField ( ) ;
46404638 _currentPageField . AddToClassList ( "current-page-field" ) ;
46414639 _currentPageField . RegisterValueChangedCallback ( evt =>
@@ -4655,14 +4653,17 @@ private VisualElement CreateObjectColumn()
46554653 _nextPageButton = new Button ( ( ) =>
46564654 {
46574655 int currentPage = GetCurrentPage ( _namespaceController . SelectedType ) ;
4658- if ( _filteredObjects . Count / MaxObjectsPerPage <= currentPage )
4656+ if ( _filteredObjects . Count / MaxObjectsPerPage <= currentPage )
46594657 {
46604658 return ;
46614659 }
46624660
46634661 SetCurrentPage ( _namespaceController . SelectedType , currentPage + 1 ) ;
46644662 BuildObjectsView ( ) ;
4665- } ) { text = "→" } ;
4663+ } )
4664+ {
4665+ text = "→" ,
4666+ } ;
46664667 _nextPageButton . AddToClassList ( "go-button-disabled" ) ;
46674668 _objectPageController . Add ( _previousPageButton ) ;
46684669 _objectPageController . Add ( _currentPageField ) ;
@@ -5260,7 +5261,7 @@ private void RemoveLabelFromFilter(string labelText, LabelFilterSection sectionI
52605261 }
52615262 }
52625263
5263- private void ApplyLabelFilter ( )
5264+ private void ApplyLabelFilter ( bool buildObjectsView = true )
52645265 {
52655266 TypeLabelFilterConfig config = CurrentTypeLabelFilterConfig ;
52665267 try
@@ -5272,6 +5273,7 @@ private void ApplyLabelFilter()
52725273 {
52735274 _filterStatusLabel . text = "Select a type to see objects." ;
52745275 }
5276+
52755277 return ;
52765278 }
52775279
@@ -5371,7 +5373,10 @@ private void ApplyLabelFilter()
53715373 {
53725374 UpdateLabelsCollapsedClickableState ( ) ;
53735375 UpdateAdvancedClickableState ( ) ;
5374- BuildObjectsView ( ) ;
5376+ if ( buildObjectsView )
5377+ {
5378+ BuildObjectsView ( ) ;
5379+ }
53755380 }
53765381 }
53775382
@@ -5775,11 +5780,13 @@ internal void BuildObjectsView()
57755780 return ;
57765781 }
57775782
5783+ ApplyLabelFilter ( buildObjectsView : false ) ;
5784+
57785785 _emptyObjectLabel . style . display = DisplayStyle . None ;
5779- if ( _filteredObjects == null || ! _filteredObjects . Any ( ) )
5786+ if ( _filteredObjects . Count == 0 )
57805787 {
57815788 // If _selectedObjects has items, then filter is active and hiding all
5782- if ( _selectedObjects != null && _selectedObjects . Any ( ) )
5789+ if ( _selectedObjects . Count > 0 )
57835790 {
57845791 Label noMatchLabel = new (
57855792 $ "No objects of type '{ NamespaceController . GetTypeDisplayName ( _namespaceController . SelectedType ) } ' match the current label filter."
@@ -5804,8 +5811,8 @@ internal void BuildObjectsView()
58045811 return ;
58055812 }
58065813
5807- if ( _filteredObjects . Count <= MaxObjectsPerPage )
5808- {
5814+ if ( _filteredObjects . Count <= MaxObjectsPerPage )
5815+ {
58095816 if ( _objectPageController != null )
58105817 {
58115818 _objectPageController . style . display = DisplayStyle . None ;
@@ -5824,17 +5831,30 @@ internal void BuildObjectsView()
58245831
58255832 _maxPageField . value = _filteredObjects . Count / MaxObjectsPerPage ;
58265833 int currentPage = GetCurrentPage ( _namespaceController . SelectedType ) ;
5827- currentPage = Mathf . Clamp ( currentPage , 0 , _filteredObjects . Count / MaxObjectsPerPage ) ;
5834+ currentPage = Mathf . Clamp (
5835+ currentPage ,
5836+ 0 ,
5837+ _filteredObjects . Count / MaxObjectsPerPage
5838+ ) ;
58285839 _currentPageField . SetValueWithoutNotify ( currentPage ) ;
58295840
58305841 _previousPageButton . EnableInClassList ( "go-button-disabled" , currentPage <= 0 ) ;
5831- _previousPageButton . EnableInClassList ( StyleConstants . ActionButtonClass , 0 < currentPage ) ;
5842+ _previousPageButton . EnableInClassList (
5843+ StyleConstants . ActionButtonClass ,
5844+ 0 < currentPage
5845+ ) ;
58325846 _previousPageButton . EnableInClassList ( "go-button" , 0 < currentPage ) ;
5833-
5834- _nextPageButton . EnableInClassList ( "go-button-disabled" , _maxPageField . value <= currentPage ) ;
5835- _nextPageButton . EnableInClassList ( StyleConstants . ActionButtonClass , currentPage < _maxPageField . value ) ;
5847+
5848+ _nextPageButton . EnableInClassList (
5849+ "go-button-disabled" ,
5850+ _maxPageField . value <= currentPage
5851+ ) ;
5852+ _nextPageButton . EnableInClassList (
5853+ StyleConstants . ActionButtonClass ,
5854+ currentPage < _maxPageField . value
5855+ ) ;
58365856 _nextPageButton . EnableInClassList ( "go-button" , currentPage < _maxPageField . value ) ;
5837-
5857+
58385858 int max = Mathf . Min ( ( currentPage + 1 ) * MaxObjectsPerPage , _filteredObjects . Count ) ;
58395859 for ( int i = currentPage * MaxObjectsPerPage ; i < max ; i ++ )
58405860 {
@@ -6850,6 +6870,16 @@ private void CloneObject(ScriptableObject originalObject)
68506870 _selectedObjects . Add ( cloneAsset ) ;
68516871 }
68526872
6873+ originalIndex = _filteredObjects . IndexOf ( originalObject ) ;
6874+ if ( 0 <= originalIndex )
6875+ {
6876+ _filteredObjects . Insert ( originalIndex + 1 , cloneAsset ) ;
6877+ }
6878+ else
6879+ {
6880+ _filteredObjects . Add ( cloneAsset ) ;
6881+ }
6882+
68536883 UpdateAndSaveObjectOrderList ( cloneAsset . GetType ( ) , _selectedObjects ) ;
68546884 BuildObjectsView ( ) ;
68556885 SelectObject ( cloneAsset ) ;
@@ -7052,17 +7082,27 @@ internal void LoadObjectTypes(Type type)
70527082 remainingObjects . Sort (
70537083 ( a , b ) =>
70547084 {
7055- int comparison = string . Compare ( a . name , b . name , StringComparison . OrdinalIgnoreCase ) ;
7085+ int comparison = string . Compare (
7086+ a . name ,
7087+ b . name ,
7088+ StringComparison . OrdinalIgnoreCase
7089+ ) ;
70567090 if ( comparison != 0 )
70577091 {
70587092 return comparison ;
70597093 }
7060- return string . Compare ( AssetDatabase . GetAssetPath ( a ) , AssetDatabase . GetAssetPath ( b ) , StringComparison . OrdinalIgnoreCase ) ;
7061- } ) ;
7094+ return string . Compare (
7095+ AssetDatabase . GetAssetPath ( a ) ,
7096+ AssetDatabase . GetAssetPath ( b ) ,
7097+ StringComparison . OrdinalIgnoreCase
7098+ ) ;
7099+ }
7100+ ) ;
70627101 sortedObjects . AddRange ( remainingObjects ) ;
70637102
70647103 _selectedObjects . Clear ( ) ;
70657104 _selectedObjects . AddRange ( sortedObjects ) ;
7105+ _filteredObjects . AddRange ( sortedObjects ) ;
70667106 }
70677107
70687108 private void LoadScriptableObjectTypes ( )
@@ -8158,49 +8198,52 @@ private int GetCurrentPage(Type type)
81588198
81598199 private void SetCurrentPage ( Type type , int page )
81608200 {
8161- PersistSettings ( settings =>
8162- {
8163- bool dirty = false ;
8164- TypeObjectOrder entry = settings . objectOrders ? . Find ( o =>
8165- string . Equals ( o . TypeFullName , type . FullName , StringComparison . Ordinal )
8166- ) ;
8167- if ( entry == null )
8201+ PersistSettings (
8202+ settings =>
81688203 {
8169- entry = new TypeObjectOrder ( ) ;
8170- settings . objectOrders ??= new List < TypeObjectOrder > ( ) ;
8171- settings . objectOrders . Add ( entry ) ;
8172- dirty = true ;
8173- }
8204+ bool dirty = false ;
8205+ TypeObjectOrder entry = settings . objectOrders ? . Find ( o =>
8206+ string . Equals ( o . TypeFullName , type . FullName , StringComparison . Ordinal )
8207+ ) ;
8208+ if ( entry == null )
8209+ {
8210+ entry = new TypeObjectOrder { TypeFullName = type . FullName } ;
8211+ settings . objectOrders ??= new List < TypeObjectOrder > ( ) ;
8212+ settings . objectOrders . Add ( entry ) ;
8213+ dirty = true ;
8214+ }
81748215
8175- if ( page != entry . page )
8176- {
8177- dirty = true ;
8178- entry . page = page ;
8179- }
8216+ if ( page != entry . page )
8217+ {
8218+ dirty = true ;
8219+ entry . page = page ;
8220+ }
81808221
8181- return dirty ;
8182- } , userState =>
8183- {
8184- bool dirty = false ;
8185- TypeObjectOrder entry = userState . objectOrders ? . Find ( o =>
8186- string . Equals ( o . TypeFullName , type . FullName , StringComparison . Ordinal )
8187- ) ;
8188- if ( entry == null )
8222+ return dirty ;
8223+ } ,
8224+ userState =>
81898225 {
8190- entry = new TypeObjectOrder ( ) ;
8191- userState . objectOrders ??= new List < TypeObjectOrder > ( ) ;
8192- userState . objectOrders . Add ( entry ) ;
8193- dirty = true ;
8194- }
8226+ bool dirty = false ;
8227+ TypeObjectOrder entry = userState . objectOrders ? . Find ( o =>
8228+ string . Equals ( o . TypeFullName , type . FullName , StringComparison . Ordinal )
8229+ ) ;
8230+ if ( entry == null )
8231+ {
8232+ entry = new TypeObjectOrder { TypeFullName = type . FullName } ;
8233+ userState . objectOrders ??= new List < TypeObjectOrder > ( ) ;
8234+ userState . objectOrders . Add ( entry ) ;
8235+ dirty = true ;
8236+ }
81958237
8196- if ( page != entry . page )
8197- {
8198- dirty = true ;
8199- entry . page = page ;
8200- }
8238+ if ( page != entry . page )
8239+ {
8240+ dirty = true ;
8241+ entry . page = page ;
8242+ }
82018243
8202- return dirty ;
8203- } ) ;
8244+ return dirty ;
8245+ }
8246+ ) ;
82048247 }
82058248
82068249 private void SetObjectOrderForType ( string typeFullName , List < string > objectGuids )
0 commit comments