Skip to content

Commit 2cdbf6c

Browse files
fixed new project dialogue & updated avalonia to 11.3.0-beta1 & updated FluentAvaloniaUI to 2.4.0-preview1 & added remove menu item
1 parent 6dd8b09 commit 2cdbf6c

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

UnityHubNative.Net/CreateNewProjectDialogue.cs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using Avalonia.Media;
88
using Avalonia.Platform.Storage;
99
using MsBox.Avalonia;
10-
using MsBox.Avalonia.Enums;
1110

1211
namespace UnityHubNative.Net;
1312

@@ -17,14 +16,15 @@ sealed class CreateNewProjectDialogue : Window
1716
TextBox _nameTextBox;
1817
ComboBox _versionSelector;
1918
ListBox _templatesParent;
20-
private Button _createButton;
19+
Button _createButton;
2120

2221
public CreateNewProjectDialogue()
2322
{
2423
Title = "Create a New Unity Project";
2524
Content = CreateContent();
2625
UpdateVersionSelectionViews();
2726
UpdateTemplateViews();
27+
UpdateCreateButtonView();
2828

2929
SizeToContent = SizeToContent.WidthAndHeight;
3030
WindowStartupLocation = WindowStartupLocation.CenterOwner;
@@ -77,7 +77,7 @@ protected override async void OnOpened(EventArgs e)
7777
MaxLines = 1,
7878
VerticalAlignment = VerticalAlignment.Center,
7979
Watermark = "New Unity Project"
80-
},
80+
}.OnTextChanged(UpdateCreateButtonView),
8181
]).SetDock(Dock.Top),
8282
new DockPanel
8383
{
@@ -100,7 +100,7 @@ protected override async void OnOpened(EventArgs e)
100100
MaxLines = 1,
101101
VerticalAlignment = VerticalAlignment.Center,
102102
Watermark = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
103-
},
103+
}.OnTextChanged(UpdateCreateButtonView),
104104
]).SetDock(Dock.Top),
105105
new Separator
106106
{
@@ -153,33 +153,48 @@ protected override async void OnOpened(EventArgs e)
153153
]);
154154
}
155155

156-
void OnCreateClicked()
156+
async void OnCreateClicked()
157157
{
158158
if (TryGetSelectedUnityInstallation(out var installation))
159159
{
160160
try
161161
{
162-
Task.Run(() => Process.Start(new ProcessStartInfo
162+
var unityInstallation = UnityHubUtils.UnityInstallations[_versionSelector.SelectedIndex];
163+
string templatePath = unityInstallation.GetTemplatePaths()[_templatesParent.SelectedIndex];
164+
string projectPath = Path.Combine(_pathTextBox.Text!, _nameTextBox.Text!);
165+
string args = $"-createProject \"{projectPath}\" -cloneFromTemplate \"{templatePath}\"";
166+
var startInfo = new ProcessStartInfo
163167
{
164168
FileName = installation.path,
165-
Arguments = $"-createProject \"{_pathTextBox}\" -cloneFromTemplate \"{UnityHubUtils.UnityInstallations[_templatesParent.SelectedIndex].path}\"",
169+
Arguments = args,
166170
UseShellExecute = false,
167171
RedirectStandardOutput = true,
168172
RedirectStandardError = true,
169173
CreateNoWindow = true
170-
}));
171-
Close();
174+
};
175+
176+
_ = Task.Run(() => Process.Start(startInfo));
177+
178+
UnityHubUtils.UnityProjects.Add(new(projectPath, DateTime.UtcNow, unityInstallation));
179+
UnityHubUtils.SaveUnityProjects();
180+
MainWindow.UpdateUnityProjectViews();
172181
}
173-
catch (Exception ex)
182+
catch (Exception exception)
174183
{
175-
MessageBoxManager.GetMessageBoxStandard("Cannot Create Project", $"Cannot create project at {_pathTextBox} because an error occurred: {ex.Message}", ButtonEnum.Ok, MsBox.Avalonia.Enums.Icon.Error).ShowAsync();
184+
Debug.WriteLine(exception.Message);
176185
}
186+
187+
Close();
177188
}
178189
}
179190

180191
void OnCancelClicked() => Close();
181192

182-
void OnVersionSelectionChanged() => UpdateTemplateViews();
193+
void OnVersionSelectionChanged()
194+
{
195+
UpdateTemplateViews();
196+
UpdateCreateButtonView();
197+
}
183198

184199
void UpdateVersionSelectionViews()
185200
{
@@ -196,7 +211,6 @@ void UpdateTemplateViews()
196211
if (TryGetSelectedUnityInstallation(out var installation))
197212
foreach (var path in installation.GetTemplatePaths())
198213
_templatesParent.Items.Add(Path.GetFileName(path));
199-
UpdateCreateButtonView();
200214
}
201215

202216
void UpdateCreateButtonView() => _createButton.IsEnabled = _templatesParent.Items.Count > 0 && Directory.Exists(_pathTextBox.Text) && _nameTextBox.Text?.Length > 0;

UnityHubNative.Net/MainWindow.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,12 @@ public static MenuItem[] CreateProjectMenuItems(Func<UnityProject> unityProjectG
674674
InputGesture = new(Key.Enter, KeyModifiers.Alt | KeyModifiers.Shift),
675675
}.OnClick(OpenSelectedProjectInTerminal),
676676
new MenuItem
677+
{
678+
Header = "R_emove From List",
679+
HotKey = new(Key.Delete),
680+
InputGesture = new(Key.Delete)
681+
}.OnClick(OnRemoveProjectFromListClicked),
682+
new MenuItem
677683
{
678684
Header = "_Reveal In File Explorer",
679685
HotKey = new KeyGesture(Key.F, KeyModifiers.Control),

UnityHubNative.Net/UnityHubNative.Net.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
</PropertyGroup>
3636

3737
<ItemGroup>
38-
<PackageReference Include="Avalonia" Version="11.2.5" />
39-
<PackageReference Include="Avalonia.Desktop" Version="11.2.5" />
40-
<PackageReference Include="FluentAvaloniaUI" Version="2.3.0" />
38+
<PackageReference Include="Avalonia" Version="11.3.0-beta1" />
39+
<PackageReference Include="Avalonia.Desktop" Version="11.3.0-beta1" />
40+
<PackageReference Include="FluentAvaloniaUI" Version="2.4.0-preview1" />
4141
<PackageReference Include="MessageBox.Avalonia" Version="3.2.0" />
42-
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.2.5" />
42+
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.3.0-beta1" />
4343
<!--<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.2.4" />-->
4444
<!--<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.5" />-->
4545
<!--<PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.4" />-->

0 commit comments

Comments
 (0)