@@ -522,7 +522,17 @@ private void OnWindowKeyDown(object sender, KeyEventArgs e)
522522 case Key . Right :
523523 case Key . Down :
524524 break ;
525- case Key . F2 : // edit arguments
525+ case Key . F2 : // edit arguments or project name
526+ // if in first cell (or no cell)
527+ var cell = gridRecent . CurrentCell ;
528+ if ( cell . Column . DisplayIndex == 0 )
529+ {
530+ // enable cell edit
531+ cell . Column . IsReadOnly = false ;
532+ // start editing that cell
533+ gridRecent . CurrentCell = new DataGridCellInfo ( gridRecent . Items [ gridRecent . SelectedIndex ] , gridRecent . Columns [ cell . Column . DisplayIndex ] ) ;
534+ gridRecent . BeginEdit ( ) ;
535+ }
526536 break ;
527537 default : // any key
528538 // cancel if editing cell
@@ -1044,9 +1054,14 @@ private void BtnOpenGithub_Click(object sender, RoutedEventArgs e)
10441054 Process . Start ( githubURL ) ;
10451055 }
10461056
1057+ // finished editing project name cell or launcher argument cell
10471058 private void GridRecent_CellEditEnding ( object sender , DataGridCellEditEndingEventArgs e )
10481059 {
1049- // get current row data
1060+ // avoid ending event running twice
1061+ if ( isDirtyCell == false ) return ;
1062+ isDirtyCell = false ;
1063+
1064+ // get selected row data
10501065 var proj = GetSelectedProject ( ) ;
10511066
10521067 // check that folder exists
@@ -1055,31 +1070,81 @@ private void GridRecent_CellEditEnding(object sender, DataGridCellEditEndingEven
10551070
10561071 // get current arguments, after editing
10571072 TextBox t = e . EditingElement as TextBox ;
1058- string arguments = t . Text . ToString ( ) ;
1073+ string newcellValue = t . Text . ToString ( ) ;
10591074
1060- string projSettingsFolder = "ProjectSettings" ;
1061-
1062- // check if projectsettings folder exists, if not then add
1063- string outputFolder = Path . Combine ( path , projSettingsFolder ) ;
1064- if ( Directory . Exists ( outputFolder ) == false )
1075+ // check if we edited project name, or launcher arguments
1076+ if ( e . Column . DisplayIndex == 0 )
10651077 {
1066- Directory . CreateDirectory ( outputFolder ) ;
1067- }
1078+ // restore read only
1079+ e . Column . IsReadOnly = true ;
1080+ // TODO validate filename
1081+ if ( string . IsNullOrEmpty ( newcellValue ) )
1082+ {
1083+ Console . WriteLine ( "Invalid new project name: " + newcellValue ) ;
1084+ return ;
1085+ }
10681086
1069- // save arguments to projectsettings folder
1070- string outputFile = Path . Combine ( path , projSettingsFolder , launcherArgumentsFile ) ;
1087+ var newPath = Path . Combine ( Directory . GetParent ( path ) . ToString ( ) , newcellValue ) ;
1088+
1089+ //Console.WriteLine("Old folder: " + path);
1090+ //Console.WriteLine("New folder: " + newPath);
1091+
1092+ // check if same as before (need to replace mismatch slashes)
1093+ if ( path . Replace ( '/' , '\\ ' ) == newPath . Replace ( '/' , '\\ ' ) )
1094+ {
1095+ Console . WriteLine ( "Rename cancelled.." ) ;
1096+ return ;
1097+ }
1098+
1099+ // check if new folder already exists
1100+ if ( Directory . Exists ( newPath ) )
1101+ {
1102+ Console . WriteLine ( "Directory already exists: " + newPath ) ;
1103+ return ;
1104+ }
1105+
1106+ // try rename project folder
1107+ Directory . Move ( path , newPath ) ;
1108+
1109+ // check if success
1110+ if ( Directory . Exists ( newPath ) )
1111+ {
1112+ proj . Path = newPath ;
1113+ // TODO save to registry (otherwise not listed in recent projects, unless opened)
1114+ }
1115+ else
1116+ {
1117+ Console . WriteLine ( "Failed to rename directory.." ) ;
1118+ }
10711119
1072- try
1073- {
1074- StreamWriter sw = new StreamWriter ( outputFile ) ;
1075- sw . WriteLine ( arguments ) ;
1076- sw . Close ( ) ;
10771120 }
1078- catch ( Exception ex )
1121+ else // it was launcher arguments
10791122 {
1080- //SetStatus("File error: " + exception.Message);
1081- Console . WriteLine ( ex ) ;
1123+
1124+ string projSettingsFolder = "ProjectSettings" ;
1125+
1126+ // check if projectsettings folder exists, if not then add
1127+ string outputFolder = Path . Combine ( path , projSettingsFolder ) ;
1128+ if ( Directory . Exists ( outputFolder ) == false )
1129+ {
1130+ Directory . CreateDirectory ( outputFolder ) ;
1131+ }
1132+
1133+ // save arguments to projectsettings folder
1134+ string outputFile = Path . Combine ( path , projSettingsFolder , launcherArgumentsFile ) ;
1135+
1136+ try
1137+ {
1138+ StreamWriter sw = new StreamWriter ( outputFile ) ;
1139+ sw . WriteLine ( newcellValue ) ;
1140+ sw . Close ( ) ;
1141+ }
1142+ catch ( Exception ex )
1143+ {
1144+ Console . WriteLine ( "Error saving launcher arguments: " + ex ) ;
1145+ }
10821146 }
1147+
10831148 // TODO select the same row again
10841149 }
10851150
@@ -1289,6 +1354,11 @@ public void CanExecute_Copy(object sender, CanExecuteRoutedEventArgs e)
12891354 e . CanExecute = true ;
12901355 }
12911356
1357+ bool isDirtyCell = false ;
1358+ private void GridRecent_BeginningEdit ( object sender , DataGridBeginningEditEventArgs e )
1359+ {
1360+ isDirtyCell = true ;
1361+ }
12921362 } // class
12931363} //namespace
12941364
0 commit comments