22using Avalonia . Interactivity ;
33using System ;
44using System . Collections . Generic ;
5+ using System . IO ;
56using System . Threading . Tasks ;
67using VisualPairCoding . BL ;
78using VisualPairCoding . BL . AutoUpdates ;
@@ -12,12 +13,12 @@ namespace VisualPairCoding.AvaloniaUI
1213 public partial class EnterNamesForm : Window
1314 {
1415 private bool _autostart = false ;
15-
1616 public EnterNamesForm ( )
1717 {
1818 InitializeComponent ( ) ;
1919 WindowStartupLocation = WindowStartupLocation . CenterScreen ;
2020 Opened += OnActivated ;
21+ Closed += OnClosed ;
2122 }
2223
2324 public EnterNamesForm ( bool autostart )
@@ -26,6 +27,12 @@ public EnterNamesForm(bool autostart)
2627 InitializeComponent ( ) ;
2728 WindowStartupLocation = WindowStartupLocation . CenterScreen ;
2829 Opened += OnActivated ;
30+ Closed += OnClosed ;
31+ }
32+
33+ private MenuItem GetRecentMenuItem ( )
34+ {
35+ return this . FindControl < MenuItem > ( "recentMenuItem" ) ;
2936 }
3037
3138 private async Task < bool > AutoUpdate ( )
@@ -52,8 +59,40 @@ private async Task<bool> AutoUpdate()
5259 return false ;
5360 }
5461
62+ private void OnClosed ( object ? sender , EventArgs e )
63+ {
64+ var appDataPath = SessionConfigurationFolderHandler . GetSessionFolderPath ( ) ;
65+ if ( ! string . IsNullOrEmpty ( appDataPath ) )
66+ {
67+ var participants = GetParticipants ( ) ;
68+ string configName = string . Join ( "_" , participants ) ;
69+ var path = Path . Combine ( appDataPath , configName + ".vpcsession" ) ;
70+ SaveSessionConfiguration ( path , participants ) ;
71+ }
72+ }
73+
74+ private void OnMenuItemClicked ( object ? sender , RoutedEventArgs e )
75+ {
76+ MenuItem clickedMenuItem = ( MenuItem ) e . Source ! ;
77+ string subMenuHeader = clickedMenuItem . Header . ToString ( ) ! ;
78+ var configPath = Path . Combine ( SessionConfigurationFolderHandler . GetSessionFolderPath ( ) , subMenuHeader + ".vpcsession" ) ;
79+ LoadSessionIntoGui ( configPath ) ;
80+ }
5581 private async void OnActivated ( object ? sender , EventArgs e )
5682 {
83+ MenuItem menuItem = GetRecentMenuItem ( ) ;
84+
85+
86+ if ( ! SessionConfigurationFolderHandler . CheckIfConfigurationFolderExistsUnderAppDataFolder ( ) )
87+ {
88+ SessionConfigurationFolderHandler . CreateConfigurationFolderUnderAppDataFolder ( ) ;
89+ }
90+
91+ var configs = SessionConfigurationFolderHandler . GetConfigurationFiles ( ) ;
92+
93+ menuItem . Items = configs ;
94+ menuItem . SelectedIndex = 0 ;
95+
5796 //Only perform auto - updates if not in dev environment
5897 if ( AutoUpdateDetector . isUpdateAvailable ( ) )
5998 {
@@ -283,6 +322,11 @@ public async void SaveSessionConfiguration(object? sender, RoutedEventArgs args)
283322 }
284323 }
285324
325+ public void SaveSessionConfiguration ( string path , List < string > participants )
326+ {
327+ SessionConfigurationFileHandler . Save ( path , new SessionConfiguration ( participants , ( int ) minutesPerTurn . Value ) ) ;
328+ }
329+
286330 public void NewSessionClick ( object sender , RoutedEventArgs args )
287331 {
288332 var session = new SessionConfiguration ( new List < string > ( ) , 7 ) ;
0 commit comments