@@ -39,7 +39,7 @@ public partial class MainWindow : Window
3939 public static readonly string launcherArgumentsFile = "LauncherArguments.txt" ;
4040 string _filterString = null ;
4141 const string githubURL = "https://github.com/unitycoder/UnityLauncherPro" ;
42-
42+ int lastSelectedProjectIndex = 0 ;
4343 Mutex myMutex ;
4444
4545 public MainWindow ( )
@@ -339,14 +339,20 @@ void AddUnityInstallationRootFolder()
339339 }
340340 }
341341
342- void SetFocusToGrid ( DataGrid targetGrid )
342+ void SetFocusToGrid ( DataGrid targetGrid , int index = 0 )
343343 {
344344 //e.Handled = true; // if enabled, we enter to first row initially
345345 if ( targetGrid . Items . Count < 1 ) return ;
346346 targetGrid . Focus ( ) ;
347- targetGrid . SelectedIndex = 0 ;
348- DataGridRow row = ( DataGridRow ) targetGrid . ItemContainerGenerator . ContainerFromIndex ( 0 ) ;
347+ DataGridRow row = ( DataGridRow ) targetGrid . ItemContainerGenerator . ContainerFromIndex ( index ) ;
348+ if ( row == null )
349+ {
350+ gridRecent . UpdateLayout ( ) ;
351+ gridRecent . ScrollIntoView ( gridRecent . Items [ index ] ) ;
352+ row = ( DataGridRow ) gridRecent . ItemContainerGenerator . ContainerFromIndex ( index ) ;
353+ }
349354 row . MoveFocus ( new TraversalRequest ( FocusNavigationDirection . Next ) ) ;
355+ targetGrid . SelectedIndex = index ;
350356 }
351357
352358 async void CallGetUnityUpdates ( )
@@ -490,17 +496,20 @@ private void OnWindowKeyDown(object sender, KeyEventArgs e)
490496
491497 switch ( e . Key )
492498 {
493- case Key . F5 : // refresh projects
494- projectsSource = GetProjects . Scan ( getGitBranch : ( bool ) chkShowGitBranchColumn . IsChecked , getArguments : ( bool ) chkShowLauncherArgumentsColumn . IsChecked , showMissingFolders : ( bool ) chkShowMissingFolderProjects . IsChecked ) ;
495- gridRecent . ItemsSource = projectsSource ;
496- break ;
497499 case Key . Escape : // clear project search
498500 if ( txtSearchBox . Text == "" )
499501 {
500502 SetFocusToGrid ( gridRecent ) ;
501503 }
502504 txtSearchBox . Text = "" ;
503505 break ;
506+ case Key . F5 :
507+ txtSearchBox . Text = "" ;
508+ break ;
509+ case Key . Up :
510+ case Key . Left :
511+ case Key . Right :
512+ case Key . Down :
504513 case Key . F2 : // edit arguments
505514 break ;
506515 default : // any key
@@ -563,8 +572,8 @@ private async void OnTabSelectionChanged(object sender, SelectionChangedEventArg
563572 if ( updatesSource == null )
564573 {
565574 var task = GetUnityUpdates . Scan ( ) ;
575+ if ( task . IsCompleted == false ) return ;
566576 var items = await task ;
567- // TODO handle errors?
568577 if ( items == null ) return ;
569578 updatesSource = GetUnityUpdates . Parse ( items ) ;
570579 if ( updatesSource == null ) return ;
@@ -661,6 +670,7 @@ private void BtnUpgradeProject_Click(object sender, RoutedEventArgs e)
661670
662671 private void GridRecent_Loaded ( object sender , RoutedEventArgs e )
663672 {
673+ //Console.WriteLine("GridRecent_Loaded");
664674 SetFocusToGrid ( gridRecent ) ;
665675 }
666676
@@ -763,6 +773,17 @@ private void GridRecent_PreviewKeyDown(object sender, KeyEventArgs e)
763773 {
764774 switch ( e . Key )
765775 {
776+ case Key . Up :
777+ case Key . Down :
778+ break ;
779+
780+ case Key . F5 : // refresh projects
781+ txtSearchBox . Text = "" ;
782+ lastSelectedProjectIndex = gridRecent . SelectedIndex ;
783+ projectsSource = GetProjects . Scan ( getGitBranch : ( bool ) chkShowGitBranchColumn . IsChecked , getArguments : ( bool ) chkShowLauncherArgumentsColumn . IsChecked , showMissingFolders : ( bool ) chkShowMissingFolderProjects . IsChecked ) ;
784+ gridRecent . ItemsSource = projectsSource ;
785+ SetFocusToGrid ( gridRecent , lastSelectedProjectIndex ) ;
786+ break ;
766787 case Key . Tab :
767788 if ( ( Keyboard . Modifiers & ModifierKeys . Control ) == ModifierKeys . Control )
768789 {
0 commit comments