@@ -170,34 +170,38 @@ public static void UpdateUnityProjectViews()
170170
171171 public static void MoveSelectedProjectDown ( )
172172 {
173- if ( ! TryGetSelectedProject ( out var unityProject ) || unityProject is null )
174- return ;
175- var ind = UnityHubUtils . UnityProjects . IndexOf ( unityProject ) ;
176- if ( ind == - 1 )
173+ var ind = GetUnityProjectSelectedIndex ( ) ;
174+ if ( ind == - 1 || s_unityProjectsParent . Items [ ind ] == null )
177175 return ;
178- var replacedIndex = ( ind + 1 ) % UnityHubUtils . UnityProjects . Count ;
179- ( UnityHubUtils . UnityProjects [ ind ] , UnityHubUtils . UnityProjects [ replacedIndex ] ) = ( UnityHubUtils . UnityProjects [ replacedIndex ] , UnityHubUtils . UnityProjects [ ind ] ) ;
176+ var targetIndex = ind == UnityHubUtils . UnityProjects . Count - 1 ? 0 : ind + 1 ;
177+ var unityProject = UnityHubUtils . UnityProjects [ ind ] ;
178+ UnityHubUtils . UnityProjects . RemoveAt ( ind ) ;
179+ UnityHubUtils . UnityProjects . Insert ( targetIndex , unityProject ) ;
180180 UnityHubUtils . SaveUnityProjects ( ) ;
181- ( s_unityProjectsParent . Items [ ind ] , s_unityProjectsParent . Items [ replacedIndex ] ) = ( s_unityProjectsParent . Items [ replacedIndex ] , s_unityProjectsParent . Items [ ind ] ) ;
182- s_unityProjectsParent . SelectedIndex = replacedIndex ;
183- ( ( UnityProjectView ) s_unityProjectsParent . Items [ ind ] ) . Update ( UnityHubUtils . UnityProjects [ ind ] ) ;
184- ( ( UnityProjectView ) s_unityProjectsParent . Items [ replacedIndex ] ) . Update ( UnityHubUtils . UnityProjects [ replacedIndex ] ) ;
181+ var item = s_unityProjectsParent . Items [ ind ] ;
182+ s_unityProjectsParent . Items . RemoveAt ( ind ) ;
183+ s_unityProjectsParent . Items . Insert ( targetIndex , item ) ;
184+ s_unityProjectsParent . SelectedIndex = targetIndex ;
185+ for ( int i = 0 ; i < s_unityProjectsParent . Items . Count ; i ++ )
186+ ( ( UnityProjectView ) s_unityProjectsParent . Items [ i ] ) . Update ( UnityHubUtils . UnityProjects [ i ] ) ;
185187 }
186188
187189 public static void MoveSelectedProjectUp ( )
188190 {
189- if ( ! TryGetSelectedProject ( out var unityProject ) || unityProject is null )
190- return ;
191- var ind = UnityHubUtils . UnityProjects . IndexOf ( unityProject ) ;
192- if ( ind == - 1 )
191+ var ind = GetUnityProjectSelectedIndex ( ) ;
192+ if ( ind == - 1 || s_unityProjectsParent . Items [ ind ] == null )
193193 return ;
194- var replacedIndex = ind == 0 ? UnityHubUtils . UnityProjects . Count - 1 : ind - 1 ;
195- ( UnityHubUtils . UnityProjects [ ind ] , UnityHubUtils . UnityProjects [ replacedIndex ] ) = ( UnityHubUtils . UnityProjects [ replacedIndex ] , UnityHubUtils . UnityProjects [ ind ] ) ;
194+ var targetIndex = ind == 0 ? UnityHubUtils . UnityProjects . Count - 1 : ind - 1 ;
195+ var unityProject = UnityHubUtils . UnityProjects [ ind ] ;
196+ UnityHubUtils . UnityProjects . RemoveAt ( ind ) ;
197+ UnityHubUtils . UnityProjects . Insert ( targetIndex , unityProject ) ;
196198 UnityHubUtils . SaveUnityProjects ( ) ;
197- ( s_unityProjectsParent . Items [ ind ] , s_unityProjectsParent . Items [ replacedIndex ] ) = ( s_unityProjectsParent . Items [ replacedIndex ] , s_unityProjectsParent . Items [ ind ] ) ;
198- s_unityProjectsParent . SelectedIndex = replacedIndex ;
199- ( ( UnityProjectView ) s_unityProjectsParent . Items [ ind ] ) . Update ( UnityHubUtils . UnityProjects [ ind ] ) ;
200- ( ( UnityProjectView ) s_unityProjectsParent . Items [ replacedIndex ] ) . Update ( UnityHubUtils . UnityProjects [ replacedIndex ] ) ;
199+ var item = s_unityProjectsParent . Items [ ind ] ;
200+ s_unityProjectsParent . Items . RemoveAt ( ind ) ;
201+ s_unityProjectsParent . Items . Insert ( targetIndex , item ) ;
202+ s_unityProjectsParent . SelectedIndex = targetIndex ;
203+ for ( int i = 0 ; i < s_unityProjectsParent . Items . Count ; i ++ )
204+ ( ( UnityProjectView ) s_unityProjectsParent . Items [ i ] ) . Update ( UnityHubUtils . UnityProjects [ i ] ) ;
201205 }
202206
203207 static Control CreateContent ( ) => new DockPanel
0 commit comments