Skip to content

Commit 7ec0a1f

Browse files
committed
fix null ref on new project creation (if no version selected), improve New Project window (can select another versions)
1 parent 95f4377 commit 7ec0a1f

File tree

4 files changed

+230
-24
lines changed

4 files changed

+230
-24
lines changed

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Unity Project Launcher by https://unitycoder.com
2-
// Sources https://github.com/unitycoder/UnityLauncherPro
2+
// https://github.com/unitycoder/UnityLauncherPro
33

44
using System;
55
using System.Collections.Generic;
@@ -1323,7 +1323,7 @@ void CreateNewEmptyProject()
13231323
}
13241324
else // unity tab
13251325
{
1326-
newVersion = GetSelectedUnity().Version == null ? preferredVersion : GetSelectedUnity().Version;
1326+
newVersion = (GetSelectedUnity() == null || GetSelectedUnity().Version == null) ? preferredVersion : GetSelectedUnity().Version;
13271327
}
13281328

13291329
if (string.IsNullOrEmpty(newVersion))
@@ -1332,7 +1332,7 @@ void CreateNewEmptyProject()
13321332
return;
13331333
}
13341334

1335-
NewProject modalWindow = new NewProject(newVersion, Tools.GetSuggestedProjectName(newVersion, txtRootFolderForNewProjects.Text));
1335+
NewProject modalWindow = new NewProject(newVersion, Tools.GetSuggestedProjectName(newVersion, txtRootFolderForNewProjects.Text), txtRootFolderForNewProjects.Text);
13361336
modalWindow.ShowInTaskbar = this == null;
13371337
modalWindow.WindowStartupLocation = this == null ? WindowStartupLocation.CenterScreen : WindowStartupLocation.CenterOwner;
13381338
modalWindow.Topmost = this == null;
@@ -1344,14 +1344,14 @@ void CreateNewEmptyProject()
13441344
if (results == true)
13451345
{
13461346
var projectPath = txtRootFolderForNewProjects.Text;
1347-
Console.WriteLine("create project " + projectPath);
1347+
Console.WriteLine("Create project " + NewProject.newVersion + " : " + projectPath);
13481348
if (string.IsNullOrEmpty(projectPath)) return;
13491349

1350-
Tools.FastCreateProject(newVersion, projectPath, NewProject.newProjectName);
1350+
Tools.FastCreateProject(NewProject.newVersion, projectPath, NewProject.newProjectName);
13511351
}
13521352
else // false, cancel
13531353
{
1354-
Console.WriteLine("Cancellled project creation..");
1354+
Console.WriteLine("Cancelled project creation..");
13551355
}
13561356

13571357
}

UnityLauncherPro/NewProject.xaml

Lines changed: 150 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:local="clr-namespace:UnityLauncherPro"
77
mc:Ignorable="d"
8-
Title="Create New Project" Height="200" Width="300" Background="{DynamicResource DarkestBackground}" PreviewKeyDown="Window_PreviewKeyDown">
8+
Title="Create New Project" Height="296" Width="300" Background="{DynamicResource DarkestBackground}" PreviewKeyDown="Window_PreviewKeyDown" ResizeMode="NoResize" WindowStartupLocation="CenterOwner">
99
<Window.Resources>
1010
<!-- custom buttons -->
1111
<Style x:Key="CustomButton" TargetType="{x:Type Button}">
@@ -29,23 +29,165 @@
2929
</Setter.Value>
3030
</Setter>
3131
</Style>
32+
33+
<!--TODO move to styles-->
34+
<!-- datagrid rows & row selection -->
35+
<Style TargetType="DataGridRow">
36+
<Setter Property="Background" Value="{StaticResource ButtonBackground}" />
37+
<Setter Property="BorderBrush" Value="{x:Null}" />
38+
<Setter Property="BorderThickness" Value="0,0,0,0" />
39+
<Style.Triggers>
40+
<!--<Trigger Property="IsMouseOver" Value="True">
41+
<Setter Property="Background" Value="{StaticResource DataGridRowMouseOver}"/>
42+
</Trigger>-->
43+
<Trigger Property="IsSelected" Value="True">
44+
<Setter Property="Background" Value="{StaticResource DataGridRowSelectedBackground}" />
45+
</Trigger>
46+
</Style.Triggers>
47+
</Style>
48+
49+
<!-- datagrid hide selected cell borders -->
50+
<Style TargetType="{x:Type DataGridCell}">
51+
<Setter Property="BorderBrush" Value="Transparent" />
52+
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
53+
<Setter Property="Margin" Value="0,0.5,0,0.5" />
54+
<Style.Triggers>
55+
<Trigger Property="IsSelected" Value="True">
56+
<Setter Property="Background" Value="Transparent" />
57+
</Trigger>
58+
<Trigger Property="IsSelected" Value="False">
59+
<Setter Property="Background" Value="Transparent" />
60+
</Trigger>
61+
</Style.Triggers>
62+
</Style>
63+
64+
<!-- datagrid scrollbar customization -->
65+
<!-- scrollbar top/bottom arrow buttons -->
66+
<Style x:Key="ScrollBarLineButton" TargetType="{x:Type RepeatButton}">
67+
<Setter Property="SnapsToDevicePixels" Value="True"/>
68+
<Setter Property="OverridesDefaultStyle" Value="true"/>
69+
<Setter Property="Focusable" Value="false"/>
70+
<Setter Property="Template">
71+
<Setter.Value>
72+
<ControlTemplate TargetType="{x:Type RepeatButton}">
73+
<!-- button background -->
74+
<Border Name="Border" Margin="1" CornerRadius="0" BorderThickness="0" Background="{DynamicResource ButtonBackground}" BorderBrush="{x:Null}">
75+
<!-- arrow sign -->
76+
<Path HorizontalAlignment="Center" VerticalAlignment="Center" Fill="{DynamicResource ScrollArrowForeground}" Data="{Binding Path=Content,RelativeSource={RelativeSource TemplatedParent}}" />
77+
</Border>
78+
<ControlTemplate.Triggers>
79+
<!-- NOTE order matters, if pressed is before mouseover, then it gets overwritten -->
80+
<Trigger Property="IsMouseOver" Value="true">
81+
<Setter TargetName="Border" Property="Background" Value="{StaticResource TextBoxBackground}" />
82+
</Trigger>
83+
<Trigger Property="IsPressed" Value="true">
84+
<Setter TargetName="Border" Property="Background" Value="{StaticResource ScrollArrowPressed}" />
85+
</Trigger>
86+
<Trigger Property="IsEnabled" Value="false">
87+
<Setter Property="Foreground" Value="Black"/>
88+
</Trigger>
89+
</ControlTemplate.Triggers>
90+
</ControlTemplate>
91+
</Setter.Value>
92+
</Setter>
93+
</Style>
94+
95+
<Style x:Key="ScrollBarPageButton" TargetType="{x:Type RepeatButton}">
96+
<Setter Property="SnapsToDevicePixels" Value="True"/>
97+
<Setter Property="OverridesDefaultStyle" Value="true"/>
98+
<Setter Property="IsTabStop" Value="false"/>
99+
<Setter Property="Focusable" Value="false"/>
100+
<Setter Property="Template">
101+
<Setter.Value>
102+
<ControlTemplate TargetType="{x:Type RepeatButton}">
103+
<Border Background="Transparent" />
104+
</ControlTemplate>
105+
</Setter.Value>
106+
</Setter>
107+
</Style>
108+
109+
<!-- scroll thumb (elevator) bar -->
110+
<Style x:Key="ScrollBarThumb" TargetType="{x:Type Thumb}">
111+
<Setter Property="SnapsToDevicePixels" Value="True"/>
112+
<Setter Property="OverridesDefaultStyle" Value="true"/>
113+
<Setter Property="IsTabStop" Value="false"/>
114+
<Setter Property="Focusable" Value="false"/>
115+
<Setter Property="Template">
116+
<Setter.Value>
117+
<ControlTemplate TargetType="{x:Type Thumb}">
118+
<Border Name="Border" CornerRadius="0" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" />
119+
<ControlTemplate.Triggers>
120+
<Trigger Property="IsMouseOver" Value="true">
121+
<Setter TargetName="Border" Property="Background" Value="{StaticResource ScrollBarThumbFill}" />
122+
</Trigger>
123+
</ControlTemplate.Triggers>
124+
</ControlTemplate>
125+
</Setter.Value>
126+
</Setter>
127+
</Style>
128+
129+
<ControlTemplate x:Key="VerticalScrollBar" TargetType="{x:Type ScrollBar}">
130+
<Grid >
131+
<Grid.RowDefinitions>
132+
<RowDefinition MaxHeight="18"/>
133+
<RowDefinition Height="0.00001*"/>
134+
<RowDefinition MaxHeight="18"/>
135+
</Grid.RowDefinitions>
136+
<!-- scrollbar background -->
137+
<Border Grid.RowSpan="3" CornerRadius="0" Background="{DynamicResource ScrollBarBackground}" />
138+
<!-- scrollbar top button -->
139+
<RepeatButton Grid.Row="0" Style="{StaticResource ScrollBarLineButton}" Height="18" Command="ScrollBar.LineUpCommand" Content="M 0 4 L 8 4 L 4 0 Z" />
140+
<Track Name="PART_Track" Grid.Row="1" IsDirectionReversed="true">
141+
<Track.DecreaseRepeatButton>
142+
<RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageUpCommand" />
143+
</Track.DecreaseRepeatButton>
144+
<Track.Thumb>
145+
<!-- scrollbar foreground -->
146+
<Thumb Style="{StaticResource ScrollBarThumb}" Margin="1,0,1,0" Background="{DynamicResource ScrollBarFill}" BorderBrush="{x:Null}"/>
147+
</Track.Thumb>
148+
<Track.IncreaseRepeatButton>
149+
<RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageDownCommand" />
150+
</Track.IncreaseRepeatButton>
151+
</Track>
152+
<!-- scrollbar bottom button -->
153+
<RepeatButton Grid.Row="3" Style="{StaticResource ScrollBarLineButton}" Height="18" Command="ScrollBar.LineDownCommand" Content="M 0 0 L 4 4 L 8 0 Z" />
154+
</Grid>
155+
</ControlTemplate>
156+
157+
<Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}">
158+
<Setter Property="SnapsToDevicePixels" Value="True"/>
159+
<Setter Property="OverridesDefaultStyle" Value="true"/>
160+
<Style.Triggers>
161+
<Trigger Property="Orientation" Value="Vertical">
162+
<Setter Property="Width" Value="18"/>
163+
<Setter Property="Height" Value="Auto" />
164+
<Setter Property="Template" Value="{StaticResource VerticalScrollBar}" />
165+
</Trigger>
166+
</Style.Triggers>
167+
</Style>
168+
32169
</Window.Resources>
33170

34171
<Grid>
35172
<StackPanel Margin="10,3">
36-
<Label Content="Unity Version " Foreground="{DynamicResource ButtonForeground}" Margin="0,0,0,3" />
37-
<TextBox x:Name="txtNewProjectVersion" VerticalAlignment="Center" Margin="0,0,0,3" IsEnabled="False" IsReadOnly="True" IsUndoEnabled="False" />
38-
<Label Content="Project Name:" Foreground="{DynamicResource ButtonForeground}" Margin="0,0,0,3" />
39-
<TextBox x:Name="txtNewProjectName" VerticalAlignment="Center" Margin="0,0,0,3" IsUndoEnabled="True" TextChanged="TxtNewProjectName_TextChanged" />
40-
<Grid HorizontalAlignment="Stretch" Margin="0,15,0,0">
173+
<Label Content="Unity Version " Foreground="{DynamicResource ButtonForeground}" Margin="0,0,0,3" Padding="5,5,5,3" />
174+
<DataGrid x:Name="gridAvailableVersions" SelectionMode="Single" Height="120" Margin="3,0" VerticalAlignment="Top" HeadersVisibility="None" AutoGenerateColumns="False" IsSynchronizedWithCurrentItem="True" Foreground="{DynamicResource ButtonForeground}" Background="{DynamicResource MainBackgroundColor}" SelectionChanged="GridAvailableVersions_SelectionChanged" IsTabStop="True" TabIndex="1" KeyboardNavigation.TabNavigation = "None" Loaded="GridAvailableVersions_Loaded" EnableRowVirtualization="False">
175+
<DataGrid.Columns>
176+
<DataGridTextColumn Header="Key" Binding="{Binding Key}" IsReadOnly="True" CanUserResize="False" MinWidth="300" />
177+
</DataGrid.Columns>
178+
</DataGrid>
179+
<Label Content="Project Name:" Foreground="{DynamicResource ButtonForeground}" Margin="0,0,0,3" Padding="5,5,5,3" />
180+
<TextBox x:Name="txtNewProjectName" VerticalAlignment="Center" Margin="3,0,3,3" IsUndoEnabled="True" TextChanged="TxtNewProjectName_TextChanged" PreviewKeyDown="TxtNewProjectName_PreviewKeyDown" TabIndex="0" />
181+
<Label x:Name="lblNewProjectFolder" Content="(folder)" Foreground="{DynamicResource ButtonBackground}" Margin="0" FontSize="10" Padding="5,0,5,3" />
182+
<Grid HorizontalAlignment="Stretch" Margin="0,8,0,0">
41183
<Grid.ColumnDefinitions>
42184
<ColumnDefinition Width="*"/>
43185
<ColumnDefinition Width="*"/>
44186
</Grid.ColumnDefinitions>
45-
<Button Grid.Column="0" Style="{StaticResource CustomButton}" x:Name="btnCancelNewProject" Background="{DynamicResource ButtonBackground}" Foreground="#FFC1C1C1" Margin="3,0,3,3" BorderBrush="{x:Null}" VerticalAlignment="Top" Height="35" Click="BtnCancelNewProject_Click" >
187+
<Button Grid.Column="0" Style="{StaticResource CustomButton}" x:Name="btnCancelNewProject" Background="{DynamicResource ButtonBackground}" Foreground="#FFC1C1C1" Margin="3,0,3,3" BorderBrush="{x:Null}" VerticalAlignment="Top" Height="35" Click="BtnCancelNewProject_Click" IsTabStop="False" >
46188
<Label Foreground="{DynamicResource ButtonForeground}" Content="Cancel"/>
47189
</Button>
48-
<Button Grid.Column="1" Style="{StaticResource CustomButton}" x:Name="btnCreateNewProject" Background="{DynamicResource ButtonBackground}" Foreground="#FFC1C1C1" Margin="3,0,3,3" BorderBrush="{x:Null}" VerticalAlignment="Top" Height="35" Click="BtnCreateNewProject_Click">
190+
<Button Grid.Column="1" Style="{StaticResource CustomButton}" x:Name="btnCreateNewProject" Background="{DynamicResource ButtonBackground}" Foreground="#FFC1C1C1" Margin="3,0,3,3" BorderBrush="{x:Null}" VerticalAlignment="Top" Height="35" Click="BtnCreateNewProject_Click" IsTabStop="False">
49191
<Label Foreground="{DynamicResource ButtonForeground}" Content="_Create"/>
50192
</Button>
51193
</Grid>

UnityLauncherPro/NewProject.xaml.cs

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,38 @@
1-
using System.Windows;
1+
using System.Collections.Generic;
2+
using System.Windows;
3+
using System.Windows.Controls;
24
using System.Windows.Input;
5+
using System.Windows.Media;
36

47
namespace UnityLauncherPro
58
{
69
public partial class NewProject : Window
710
{
811
public static string newProjectName = null;
12+
public static string newVersion = null;
13+
public static string newName = null;
914

10-
public NewProject(string unityVersion, string suggestedName)
15+
public NewProject(string unityVersion, string suggestedName, string targetFolder)
1116
{
1217
InitializeComponent();
1318

1419
// get version
15-
txtNewProjectVersion.Text = unityVersion;
16-
txtNewProjectName.Text = suggestedName;
20+
newVersion = unityVersion;
21+
newName = suggestedName;
22+
23+
txtNewProjectName.Text = newName;
24+
lblNewProjectFolder.Content = targetFolder;
25+
26+
// fill available versions, TODO could show which modules are installed
27+
gridAvailableVersions.ItemsSource = MainWindow.unityInstalledVersions;
28+
29+
var item = Tools.GetEntry(MainWindow.unityInstalledVersions, unityVersion);
30+
int index = gridAvailableVersions.Items.IndexOf(item);
31+
if (index > -1)
32+
{
33+
gridAvailableVersions.SelectedIndex = index;
34+
gridAvailableVersions.ScrollIntoView(item);
35+
}
1736

1837
// select projectname text so can overwrite if needed
1938
txtNewProjectName.Focus();
@@ -23,6 +42,7 @@ public NewProject(string unityVersion, string suggestedName)
2342

2443
private void BtnCreateNewProject_Click(object sender, RoutedEventArgs e)
2544
{
45+
UpdateSelectedVersion();
2646
DialogResult = true;
2747
}
2848

@@ -31,13 +51,13 @@ private void BtnCancelNewProject_Click(object sender, RoutedEventArgs e)
3151
DialogResult = false;
3252
}
3353

54+
3455
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
3556
{
3657
switch (e.Key)
3758
{
38-
// TODO allow typing anywhere
39-
4059
case Key.Enter: // enter accept
60+
UpdateSelectedVersion();
4161
DialogResult = true;
4262
e.Handled = true;
4363
break;
@@ -50,9 +70,57 @@ private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
5070
}
5171
}
5272

73+
void UpdateSelectedVersion()
74+
{
75+
var k = gridAvailableVersions.SelectedItem as KeyValuePair<string, string>?;
76+
if (k != null && k.Value.Key != newVersion)
77+
{
78+
newVersion = k.Value.Key;
79+
}
80+
}
81+
5382
private void TxtNewProjectName_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
5483
{
5584
newProjectName = txtNewProjectName.Text;
5685
}
86+
87+
private void TxtNewProjectName_PreviewKeyDown(object sender, KeyEventArgs e)
88+
{
89+
switch (e.Key)
90+
{
91+
case Key.PageUp:
92+
case Key.PageDown:
93+
case Key.Up:
94+
case Key.Down:
95+
Tools.SetFocusToGrid(gridAvailableVersions);
96+
break;
97+
default:
98+
break;
99+
}
100+
}
101+
102+
void GenerateNewName()
103+
{
104+
var newProj = Tools.GetSuggestedProjectName(newVersion, lblNewProjectFolder.Content.ToString());
105+
txtNewProjectName.Text = newProj;
106+
}
107+
108+
private void GridAvailableVersions_SelectionChanged(object sender, SelectionChangedEventArgs e)
109+
{
110+
if (gridAvailableVersions.SelectedItem == null) return;
111+
// new row selected, generate new project name for this version
112+
var k = gridAvailableVersions.SelectedItem as KeyValuePair<string, string>?;
113+
newVersion = k.Value.Key;
114+
GenerateNewName();
115+
}
116+
117+
private void GridAvailableVersions_Loaded(object sender, RoutedEventArgs e)
118+
{
119+
// set initial default row color
120+
DataGridRow row = (DataGridRow)gridAvailableVersions.ItemContainerGenerator.ContainerFromIndex(gridAvailableVersions.SelectedIndex);
121+
//row.Background = Brushes.Green;
122+
row.Foreground = Brushes.White;
123+
row.FontWeight = FontWeights.Bold;
124+
}
57125
}
58126
}

UnityLauncherPro/UpgradeWindow.xaml.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ private void Window_PreviewKeyDown(object sender, System.Windows.Input.KeyEventA
9494
if (e.Key == Key.Return && e.KeyboardDevice.Modifiers == ModifierKeys.None)
9595
{
9696
e.Handled = true;
97-
// TODO do upgrade with selected version
9897
var k = (gridAvailableVersions.SelectedItem) as KeyValuePair<string, string>?;
9998
upgradeVersion = k.Value.Key;
10099
DialogResult = true;
@@ -123,9 +122,6 @@ private void GridAvailableVersions_PreviewKeyDown(object sender, KeyEventArgs e)
123122
private void GridAvailableVersions_Loaded(object sender, RoutedEventArgs e)
124123
{
125124
Tools.SetFocusToGrid(gridAvailableVersions);
126-
// gridAvailableVersions.Focus();
127-
// DataGridRow row = (DataGridRow)gridAvailableVersions.ItemContainerGenerator.ContainerFromIndex(gridAvailableVersions.SelectedIndex);
128-
// row.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
129125
}
130126

131127
private void GridAvailableVersions_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)

0 commit comments

Comments
 (0)