@@ -823,6 +823,57 @@ private void ShowOptionsForIndex(MouseUpEvent evt, int targetIndex)
823823 }
824824 ) ;
825825
826+
827+ List < ScriptableObjectCollection > possibleAnotherCollections = GetPossibleAnotherCollections ( ) ;
828+
829+ if ( possibleAnotherCollections . Count > 0 )
830+ {
831+ foreach ( ScriptableObjectCollection scriptableObjectCollection in possibleAnotherCollections )
832+ {
833+ if ( scriptableObjectCollection == collection )
834+ continue ;
835+
836+ menu . AddItem (
837+ new GUIContent ( $ "Move to { ( AssetDatabase . GetAssetPath ( scriptableObject ) . Replace ( "/" , "\\ " ) . Replace ( "Assets" , "" ) . Replace ( ".asset" , "" ) ) } ") ,
838+ false ,
839+ ( ) =>
840+ {
841+ if ( selectedItemsCount > 0 )
842+ {
843+ if ( ! EditorUtility . DisplayDialog ( $ "Move { collectionItemListView . selectedIndices . Count ( ) } Items",
844+ $ "Are you sure you want to move { collectionItemListView . selectedIndices . Count ( ) } items, from { AssetDatabase . GetAssetPath ( collection ) } to { AssetDatabase . GetAssetPath ( scriptableObject ) } ", "Yes" , "No" ) )
845+ {
846+ return ;
847+ }
848+
849+ List < ScriptableObject > moveItems =
850+ new List < ScriptableObject > ( ) ;
851+ foreach ( int selectedIndex in collectionItemListView . selectedIndices )
852+ {
853+ moveItems . Add ( filteredItems [ selectedIndex ] ) ;
854+ }
855+
856+ foreach ( ScriptableObject item in moveItems )
857+ {
858+ MoveItem ( item , scriptableObjectCollection ) ;
859+ }
860+
861+ }
862+ else
863+ {
864+ if ( ! EditorUtility . DisplayDialog ( $ "Move Item",
865+ $ "Are you sure you want to move { filteredItems [ ^ 1 ] . name } , from { AssetDatabase . GetAssetPath ( collection ) } to { AssetDatabase . GetAssetPath ( scriptableObject ) } ", "Yes" , "No" ) )
866+ {
867+ return ;
868+ }
869+
870+ MoveItem ( filteredItems [ targetIndex ] , scriptableObjectCollection ) ;
871+ }
872+ }
873+ ) ;
874+ }
875+ }
876+
826877 menu . AddSeparator ( "" ) ;
827878 menu . AddItem (
828879 new GUIContent ( "Select Asset" ) ,
@@ -840,9 +891,41 @@ private void ShowOptionsForIndex(MouseUpEvent evt, int targetIndex)
840891 }
841892 ) ;
842893
894+ if ( selectedItemsCount == 1 )
895+ {
896+ menu . AddItem (
897+ new GUIContent ( "Rename Asset" ) ,
898+ false ,
899+ ( ) =>
900+ {
901+ RenameItemAtIndex ( collectionItemListView . selectedIndices . First ( ) ) ;
902+ }
903+ ) ;
904+ }
905+
843906 menu . ShowAsContext ( ) ;
844907 }
845908
909+ private void MoveItem ( ScriptableObject item , ScriptableObjectCollection targetCollection )
910+ {
911+ Undo . RecordObject ( collection , "Move Item" ) ;
912+ Undo . RecordObject ( targetCollection , "Move Item" ) ;
913+
914+ collection . Remove ( item ) ;
915+ targetCollection . Add ( item ) ;
916+
917+ AssetDatabase . SaveAssets ( ) ;
918+ AssetDatabase . Refresh ( ) ;
919+
920+ ReloadFilteredItems ( ) ;
921+ }
922+
923+ private List < ScriptableObjectCollection > GetPossibleAnotherCollections ( )
924+ {
925+ CollectionsRegistry . Instance . TryGetCollectionsOfItemType ( collection . GetItemType ( ) , out List < ScriptableObjectCollection > collections ) ;
926+ return collections ;
927+ }
928+
846929 private void SelectItemAtIndex ( params int [ ] index )
847930 {
848931 Object [ ] selectedObjects = new Object [ index . Length ] ;
@@ -885,7 +968,7 @@ private void RenameItemAtIndex(MouseDownEvent evt, int targetIndex)
885968
886969 private void RenameItemAtIndex ( int targetIndex )
887970 {
888- ClearCurrentRenamingItem ( ) ;
971+ ClearCurrentRenamingItem ( false ) ;
889972
890973 Undo . RecordObject ( filteredItems [ targetIndex ] , "Rename Item" ) ;
891974 VisualElement targetElement = collectionItemListView . GetRootElementForIndex ( targetIndex ) ;
@@ -895,19 +978,24 @@ private void RenameItemAtIndex(int targetIndex)
895978 currentRenamingLabel . style . display = DisplayStyle . None ;
896979
897980 currentRenamingTextField = targetElement . Q < TextField > ( ) ;
898- currentRenamingTextField . RegisterCallback < FocusOutEvent > ( OnRenamingAssetLostFocus ) ;
899- currentRenamingTextField . RegisterValueChangedCallback ( _ => OnFinishRenamingItem ( targetIndex ) ) ;
900981
901982 currentRenamingTextField . SetValueWithoutNotify ( currentRenamingLabel . text ) ;
902983 currentRenamingTextField . style . display = DisplayStyle . Flex ;
903984 currentRenamingTextField . SelectAll ( ) ;
904985 currentRenamingTextField . Focus ( ) ;
905986 collectionItemListView . ClearSelection ( ) ;
987+
988+ currentRenamingTextField . schedule . Execute ( ( ) =>
989+ {
990+ currentRenamingTextField . SelectAll ( ) ;
991+ currentRenamingTextField . RegisterCallback < FocusOutEvent > ( OnRenamingAssetLostFocus ) ;
992+ currentRenamingTextField . RegisterValueChangedCallback ( _ => OnFinishRenamingItem ( targetIndex ) ) ;
993+ } ) . ExecuteLater ( 0 ) ;
906994 }
907995
908996 private void OnRenamingAssetLostFocus ( FocusOutEvent evt )
909997 {
910- ClearCurrentRenamingItem ( ) ;
998+ ClearCurrentRenamingItem ( false ) ;
911999 }
9121000
9131001 private void OnFinishRenamingItem ( int targetIndex )
@@ -929,18 +1017,22 @@ private void OnFinishRenamingItem(int targetIndex)
9291017 AssetDatabase . SaveAssetIfDirty ( asset ) ;
9301018 }
9311019
932- ClearCurrentRenamingItem ( ) ;
1020+ ClearCurrentRenamingItem ( true ) ;
9331021 }
9341022
935- private void ClearCurrentRenamingItem ( )
1023+ private void ClearCurrentRenamingItem ( bool renamedSuccessfully )
9361024 {
9371025 if ( currentRenamingTextField == null )
9381026 return ;
9391027
1028+ currentRenamingTextField . UnregisterCallback < FocusOutEvent > ( OnRenamingAssetLostFocus ) ;
9401029 currentRenamingTextField . style . display = DisplayStyle . None ;
9411030 currentRenamingLabel . style . display = DisplayStyle . Flex ;
942- currentRenamingLabel . text = currentRenamingTextField . text ;
943- currentRenamingTextField . SetValueWithoutNotify ( "" ) ;
1031+ if ( renamedSuccessfully )
1032+ {
1033+ currentRenamingLabel . text = currentRenamingTextField . text ;
1034+ currentRenamingTextField . SetValueWithoutNotify ( "" ) ;
1035+ }
9441036 currentRenamingLabel = null ;
9451037 currentRenamingTextField = null ;
9461038 }
0 commit comments