@@ -522,7 +522,17 @@ private void OnWindowKeyDown(object sender, KeyEventArgs e)
522
522
case Key . Right :
523
523
case Key . Down :
524
524
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
+ }
526
536
break ;
527
537
default : // any key
528
538
// cancel if editing cell
@@ -1044,9 +1054,14 @@ private void BtnOpenGithub_Click(object sender, RoutedEventArgs e)
1044
1054
Process . Start ( githubURL ) ;
1045
1055
}
1046
1056
1057
+ // finished editing project name cell or launcher argument cell
1047
1058
private void GridRecent_CellEditEnding ( object sender , DataGridCellEditEndingEventArgs e )
1048
1059
{
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
1050
1065
var proj = GetSelectedProject ( ) ;
1051
1066
1052
1067
// check that folder exists
@@ -1055,31 +1070,81 @@ private void GridRecent_CellEditEnding(object sender, DataGridCellEditEndingEven
1055
1070
1056
1071
// get current arguments, after editing
1057
1072
TextBox t = e . EditingElement as TextBox ;
1058
- string arguments = t . Text . ToString ( ) ;
1073
+ string newcellValue = t . Text . ToString ( ) ;
1059
1074
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 )
1065
1077
{
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
+ }
1068
1086
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
+ }
1071
1119
1072
- try
1073
- {
1074
- StreamWriter sw = new StreamWriter ( outputFile ) ;
1075
- sw . WriteLine ( arguments ) ;
1076
- sw . Close ( ) ;
1077
1120
}
1078
- catch ( Exception ex )
1121
+ else // it was launcher arguments
1079
1122
{
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
+ }
1082
1146
}
1147
+
1083
1148
// TODO select the same row again
1084
1149
}
1085
1150
@@ -1289,6 +1354,11 @@ public void CanExecute_Copy(object sender, CanExecuteRoutedEventArgs e)
1289
1354
e . CanExecute = true ;
1290
1355
}
1291
1356
1357
+ bool isDirtyCell = false ;
1358
+ private void GridRecent_BeginningEdit ( object sender , DataGridBeginningEditEventArgs e )
1359
+ {
1360
+ isDirtyCell = true ;
1361
+ }
1292
1362
} // class
1293
1363
} //namespace
1294
1364
0 commit comments