@@ -30,6 +30,7 @@ class MainWindow : Window
3030 static TextBox s_openInTerminalFormatText ;
3131 static Key s_lastKey ;
3232 private static TabControl s_tabControl ;
33+ private static bool _updatingUnityProjectList ;
3334
3435 public MainWindow ( object data )
3536 {
@@ -107,6 +108,8 @@ public static void ReloadEverything()
107108 UpdateUnityVersionViews ( ) ;
108109 UpdateUnitySearchPathViews ( ) ;
109110 UpdateUnityProjectViews ( ) ;
111+ if ( UnityHubNativeNetApp . Config . saveProjectSelection )
112+ LoadProjectSelectedIndex ( ) ;
110113 }
111114
112115 public static void OpenSelectedProjectWith ( )
@@ -154,10 +157,12 @@ public static void UpdateUnitySearchPathViews()
154157
155158 public static void UpdateUnityProjectViews ( )
156159 {
160+ _updatingUnityProjectList = true ;
157161 SyncListBoxWithView < UnityProject , UnityProjectView > ( s_unityProjectsParent , UnityHubUtils . UnityProjects ) ;
158162
159163 for ( int i = 0 ; i < UnityHubUtils . UnityProjects . Count ; i ++ )
160164 ( ( UnityProjectView ) s_unityProjectsParent . Items [ i ] ! ) . Update ( UnityHubUtils . UnityProjects [ i ] ) ;
165+ _updatingUnityProjectList = false ;
161166 }
162167
163168 public static void MoveSelectedProjectUp ( )
@@ -591,6 +596,25 @@ public static void MoveSelectedProjectDown()
591596 ] ) . SetDock ( Dock . Top ) . SetTooltip ( "Whether or not to close the app after opening project in terminal" ) ,
592597 ] )
593598 } . SetTooltip ( "Defines the process format of when opening a project in terminal. {path} will be replaced by the project path" ) ,
599+ new SettingsExpanderItem
600+ {
601+ Content = new DockPanel
602+ {
603+ LastChildFill = false
604+ } . AddChildren
605+ ( [
606+ new TextBlock
607+ {
608+ Text = "Remember Unity Project selection" ,
609+ VerticalAlignment = VerticalAlignment . Center ,
610+ } . SetDock ( Dock . Left ) ,
611+ new CheckBox
612+ {
613+ IsChecked = UnityHubNativeNetApp . Config . saveProjectSelection ,
614+ VerticalAlignment = VerticalAlignment . Center ,
615+ } . OnCheckChanged ( OnRememberProjectSelectionChanged ) . SetDock ( Dock . Right )
616+ ] )
617+ } . SetTooltip ( "If checked, the last selected Unity Project will be kept across sessions" ) ,
594618 ] )
595619 ] )
596620 }
@@ -599,6 +623,14 @@ public static void MoveSelectedProjectDown()
599623 ] )
600624 ] ) ;
601625
626+ static void OnRememberProjectSelectionChanged ( )
627+ {
628+ UnityHubNativeNetApp . Config . saveProjectSelection = ! UnityHubNativeNetApp . Config . saveProjectSelection ;
629+ UnityHubNativeNetApp . SaveConfig ( UnityHubNativeNetApp . Config ) ;
630+ if ( UnityHubNativeNetApp . Config . saveProjectSelection )
631+ SaveProjectSelectedIndex ( ) ;
632+ }
633+
602634 static void OnCloseAfterOpenInTerminalChanged ( )
603635 {
604636 UnityHubNativeNetApp . Config . closeAfterOpenInTerminal = ! UnityHubNativeNetApp . Config . closeAfterOpenInTerminal ;
@@ -742,11 +774,14 @@ static void UnityInstallationSearchPathSelectedIndexChanged()
742774
743775 static void UnityProjectSelectedIndexChanged ( )
744776 {
745- var index = GetUnityProjectSelectedIndex ( ) ;
746- Debug . WriteLine ( $ "selection changed to { index } ") ;
747- bool isAnySelected = IsAnyProjectSelected ( ) ;
777+ if ( ! _updatingUnityProjectList && UnityHubNativeNetApp . Config . saveProjectSelection )
778+ SaveProjectSelectedIndex ( ) ;
748779 }
749780
781+ static void SaveProjectSelectedIndex ( ) => File . WriteAllText ( Paths . SelectedProject , GetUnityProjectSelectedIndex ( ) . ToString ( ) ) ;
782+
783+ static void LoadProjectSelectedIndex ( ) => s_unityProjectsParent . SelectedIndex = File . Exists ( Paths . SelectedProject ) && int . TryParse ( File . ReadAllText ( Paths . SelectedProject ) , out var result ) ? result : 0 ;
784+
750785 static async void AddNewUnitySearchPath ( )
751786 {
752787 try
0 commit comments