Skip to content

Commit 8146e38

Browse files
committed
press F2 to rename project name (folder)
1 parent eb3e391 commit 8146e38

File tree

2 files changed

+92
-22
lines changed

2 files changed

+92
-22
lines changed

UnityLauncherPro/MainWindow.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@
301301
<Button Style="{StaticResource CustomButton}" ToolTip="Add existing project" x:Name="btnAddProjectFolder" Content="Add Project.." Height="22" Width="78" HorizontalAlignment="Right" VerticalAlignment="Top" Background="#FF3F3F46" Foreground="#FFC1C1C1" Margin="0,4,34,0" Click="BtnAddProjectFolder_Click" BorderBrush="{x:Null}" TabIndex="10" />
302302
<Button Style="{StaticResource CustomButton}" ToolTip="Refresh list (F5)" x:Name="btnRefreshProjectList" Content="" Height="22" Width="22" HorizontalAlignment="Right" VerticalAlignment="Top" FontSize="16" Background="#FF3F3F46" Foreground="#FFC1C1C1" Margin="0,4,3,0" Padding="1,-2,1,1" BorderBrush="{x:Null}" Click="BtnRefreshProjectList_Click" TabIndex="11"/>
303303

304-
<DataGrid x:Name="gridRecent" SelectionMode="Single" Margin="4,30,2,42" CanUserAddRows="False" Background="{x:Null}" BorderBrush="{x:Null}" ColumnHeaderStyle="{StaticResource HeaderStyle}" Padding="0" HorizontalScrollBarVisibility="Disabled" HeadersVisibility="Column" Foreground="#FFD8D8D8" HorizontalGridLinesBrush="#4C000000" VerticalGridLinesBrush="#19000000" AutoGenerateColumns="False" PreviewKeyDown="GridRecent_PreviewKeyDown" Loaded="GridRecent_Loaded" TabIndex="2" CellEditEnding="GridRecent_CellEditEnding" PreviewMouseDoubleClick="GridRecent_PreviewMouseDoubleClick" >
304+
<DataGrid x:Name="gridRecent" SelectionMode="Single" Margin="4,30,2,42" CanUserAddRows="False" Background="{x:Null}" BorderBrush="{x:Null}" ColumnHeaderStyle="{StaticResource HeaderStyle}" Padding="0" HorizontalScrollBarVisibility="Disabled" HeadersVisibility="Column" Foreground="#FFD8D8D8" HorizontalGridLinesBrush="#4C000000" VerticalGridLinesBrush="#19000000" AutoGenerateColumns="False" PreviewKeyDown="GridRecent_PreviewKeyDown" Loaded="GridRecent_Loaded" TabIndex="2" CellEditEnding="GridRecent_CellEditEnding" PreviewMouseDoubleClick="GridRecent_PreviewMouseDoubleClick" BeginningEdit="GridRecent_BeginningEdit" >
305305

306306
<DataGrid.CommandBindings>
307307
<CommandBinding Command="ApplicationCommands.Copy" Executed="CopyRowFolderToClipBoard" CanExecute="CanExecute_Copy"/>
@@ -534,7 +534,7 @@
534534
</DataGrid.CommandBindings>
535535
<DataGrid.Columns>
536536
<DataGridTextColumn Binding="{Binding ReleaseDate, StringFormat=\{0:dd/MM/yyyy\}}" ClipboardContentBinding="{x:Null}" MinWidth="100" Header="ReleaseDate" IsReadOnly="True"/>
537-
<DataGridTextColumn Binding="{Binding Version}" ClipboardContentBinding="{x:Null}" Header="Version" IsReadOnly="True" MinWidth="123">
537+
<DataGridTextColumn Binding="{Binding Version}" ClipboardContentBinding="{x:Null}" Header="Version" IsReadOnly="True" MinWidth="222">
538538
<DataGridTextColumn.CellStyle>
539539
<Style TargetType="{x:Type DataGridCell}">
540540
<Style.Triggers>

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 90 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)