Skip to content

Commit 12a7aca

Browse files
committed
add F5 key to refresh grids, fix nullref on keydown when no search results, add copy unity version to installed grid, add download in browser and release notes button code for updates, add minimize to taskbar option code, add register explorer context menu,
1 parent 074d4c6 commit 12a7aca

File tree

6 files changed

+284
-68
lines changed

6 files changed

+284
-68
lines changed

UnityLauncherPro/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
</ArrayOfString>
2525
</value>
2626
</setting>
27+
<setting name="minimizeToTaskbar" serializeAs="String">
28+
<value>True</value>
29+
</setting>
30+
<setting name="registerExplorerMenu" serializeAs="String">
31+
<value>False</value>
32+
</setting>
2733
</UnityLauncherPro.Properties.Settings>
2834
</userSettings>
2935
</configuration>

UnityLauncherPro/MainWindow.xaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@
417417
</Button>
418418
</Grid>
419419

420-
<Button Style="{StaticResource CustomButton}" ToolTip="Refresh installations (F5)" x:Name="btnRefreshUnityList" 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}"/>
420+
<Button Style="{StaticResource CustomButton}" ToolTip="Refresh installations (F5)" x:Name="btnRefreshUnityList" 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="BtnRefreshUnityList_Click"/>
421421

422422
<DataGrid x:Name="dataGridUnitys" SelectionMode="Single" Margin="4,30,2,42" Background="{x:Null}" BorderBrush="{x:Null}" ColumnHeaderStyle="{StaticResource HeaderStyle}" Padding="0" HorizontalScrollBarVisibility="Disabled" HeadersVisibility="Column" Foreground="#FFD8D8D8" HorizontalGridLinesBrush="#4C000000" VerticalGridLinesBrush="#19000000" AutoGenerateColumns="False" PreviewKeyDown="DataGridUnitys_PreviewKeyDown">
423423

@@ -430,7 +430,7 @@
430430
<!-- right click context menu -->
431431
<DataGrid.ContextMenu>
432432
<ContextMenu>
433-
<MenuItem Header="Copy Unity Version" />
433+
<MenuItem x:Name="menuItemCopyVersionInstalled" Header="Copy Unity Version" Click="MenuItemCopyVersion_Click" />
434434
</ContextMenu>
435435
</DataGrid.ContextMenu>
436436

@@ -505,7 +505,7 @@
505505
<!-- right click context menu -->
506506
<DataGrid.ContextMenu>
507507
<ContextMenu>
508-
<MenuItem Header="Copy Unity Version" />
508+
<MenuItem x:Name="menuItemCopyUpdatesVersion" Header="Copy Unity Version" Click="MenuItemCopyVersion_Click" />
509509
</ContextMenu>
510510
</DataGrid.ContextMenu>
511511
<local:Updates ReleaseDate="2020-10-10" Version="5000.1.2.3"/>
@@ -522,10 +522,10 @@
522522
<Grid.RowDefinitions>
523523
<RowDefinition Height="32" />
524524
</Grid.RowDefinitions>
525-
<Button Grid.Column="0" Style="{StaticResource CustomButton}" x:Name="btnDonwloadInBrowser" Background="{DynamicResource ButtonBackground}" Foreground="{DynamicResource ButtonForeground}" Margin="5,0,0,0" BorderBrush="{x:Null}">
525+
<Button Grid.Column="0" Style="{StaticResource CustomButton}" x:Name="btnDonwloadInBrowser" Background="{DynamicResource ButtonBackground}" Foreground="{DynamicResource ButtonForeground}" Margin="5,0,0,0" BorderBrush="{x:Null}" Click="BtnDonwloadInBrowser_Click">
526526
<Label Foreground="{DynamicResource ButtonForeground}" Content="_Download in browser"/>
527527
</Button>
528-
<Button Grid.Column="1" Style="{StaticResource CustomButton}" x:Name="btnOpenWebsite" Background="{DynamicResource ButtonBackground}" Foreground="{DynamicResource ButtonForeground}" Margin="8,0,0,0" BorderBrush="{x:Null}" >
528+
<Button Grid.Column="1" Style="{StaticResource CustomButton}" x:Name="btnOpenWebsite" Background="{DynamicResource ButtonBackground}" Foreground="{DynamicResource ButtonForeground}" Margin="8,0,0,0" BorderBrush="{x:Null}" Click="BtnOpenWebsite_Click" >
529529
<Label Foreground="{DynamicResource ButtonForeground}" Content="_Release Notes"/>
530530
</Button>
531531
</Grid>
@@ -596,8 +596,8 @@
596596
</StackPanel>
597597
<!-- settings-->
598598
<StackPanel Grid.Row="3" Orientation="Vertical" Margin="5,10,3,3" >
599-
<CheckBox Content="Minimize to taskbar" Foreground="{DynamicResource ButtonForeground}"/>
600-
<CheckBox Content="Register Explorer context menu" Foreground="{DynamicResource ButtonForeground}"/>
599+
<CheckBox x:Name="chkMinimizeToTaskbar" Content="Minimize to taskbar" Foreground="{DynamicResource ButtonForeground}" Checked="ChkMinimizeToTaskbar_CheckedChanged" Unchecked="ChkMinimizeToTaskbar_CheckedChanged"/>
600+
<CheckBox x:Name="chkRegisterExplorerMenu" Content="Register Explorer context menu" Foreground="{DynamicResource ButtonForeground}" Unchecked="ChkRegisterExplorerMenu_CheckedChanged" Checked="ChkRegisterExplorerMenu_CheckedChanged"/>
601601
<CheckBox Content="Close after opening project" Foreground="{DynamicResource ButtonForeground}"/>
602602
<CheckBox Content="Close after launching from Explorer" Foreground="{DynamicResource ButtonForeground}"/>
603603
<CheckBox Content="Show Arguments Column" Foreground="{DynamicResource ButtonForeground}"/>

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 163 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public partial class MainWindow : Window
2020
Updates[] updatesSource;
2121
UnityInstallation[] unityInstallationsSource;
2222
public static Dictionary<string, string> unityInstalledVersions = new Dictionary<string, string>();
23-
23+
const string contextRegRoot = "Software\\Classes\\Directory\\Background\\shell";
2424
string _filterString = null;
2525

2626
public MainWindow()
@@ -47,18 +47,6 @@ void Start()
4747
dataGridUnitys.Items.Clear();
4848
UpdateUnityInstallationsList();
4949

50-
// make dictionary of installed unitys, to search faster
51-
unityInstalledVersions.Clear();
52-
for (int i = 0; i < unityInstallationsSource.Length; i++)
53-
{
54-
var version = unityInstallationsSource[i].Version;
55-
if (unityInstalledVersions.ContainsKey(version) == false)
56-
{
57-
unityInstalledVersions.Add(version, unityInstallationsSource[i].Path);
58-
}
59-
}
60-
61-
//dataGrid.Items.Add(GetProjects.Scan());
6250
projectsSource = GetProjects.Scan();
6351
gridRecent.Items.Clear();
6452
gridRecent.ItemsSource = projectsSource;
@@ -99,9 +87,11 @@ void LoadSettings()
9987
this.Width = Properties.Settings.Default.windowWidth;
10088
this.Height = Properties.Settings.Default.windowHeight;
10189

90+
chkMinimizeToTaskbar.IsChecked = Properties.Settings.Default.minimizeToTaskbar;
91+
chkRegisterExplorerMenu.IsChecked = Properties.Settings.Default.registerExplorerMenu;
92+
10293
/*
10394
// update settings window
104-
chkMinimizeToTaskbar.Checked = Properties.Settings.Default.minimizeToTaskbar;
10595
chkQuitAfterCommandline.Checked = Properties.Settings.Default.closeAfterExplorer;
10696
ChkQuitAfterOpen.Checked = Properties.Settings.Default.closeAfterProject;
10797
chkShowLauncherArgumentsColumn.Checked = Properties.Settings.Default.showArgumentsColumn;
@@ -170,6 +160,17 @@ void UpdateUnityInstallationsList()
170160
{
171161
unityInstallationsSource = GetUnityInstallations.Scan();
172162
dataGridUnitys.ItemsSource = unityInstallationsSource;
163+
164+
// make dictionary of installed unitys, to search faster
165+
unityInstalledVersions.Clear();
166+
for (int i = 0; i < unityInstallationsSource.Length; i++)
167+
{
168+
var version = unityInstallationsSource[i].Version;
169+
if (unityInstalledVersions.ContainsKey(version) == false)
170+
{
171+
unityInstalledVersions.Add(version, unityInstallationsSource[i].Path);
172+
}
173+
}
173174
}
174175

175176
Project GetSelectedProject()
@@ -182,14 +183,18 @@ UnityInstallation GetSelectedUnity()
182183
return (UnityInstallation)dataGridUnitys.SelectedItem;
183184
}
184185

186+
Updates GetSelectedUpdate()
187+
{
188+
return (Updates)dataGridUpdates.SelectedItem;
189+
}
190+
185191
void AddUnityInstallationRootFolder()
186192
{
187193
var dialog = new System.Windows.Forms.FolderBrowserDialog();
188194
dialog.Description = "Select Unity installations root folder";
189195

190196
var result = dialog.ShowDialog();
191197
var newRoot = dialog.SelectedPath;
192-
Console.WriteLine(newRoot);
193198
if (String.IsNullOrWhiteSpace(newRoot) == false && Directory.Exists(newRoot) == true)
194199
{
195200
Properties.Settings.Default.rootFolders.Add(newRoot);
@@ -202,12 +207,24 @@ void AddUnityInstallationRootFolder()
202207
void SetFocusToGrid(DataGrid targetGrid)
203208
{
204209
//e.Handled = true; // if enabled, we enter to first row initially
210+
if (targetGrid.Items.Count < 1) return;
205211
targetGrid.Focus();
206212
targetGrid.SelectedIndex = 0;
207213
DataGridRow row = (DataGridRow)targetGrid.ItemContainerGenerator.ContainerFromIndex(0);
208214
row.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
209215
}
210216

217+
async void CallGetUnityUpdates()
218+
{
219+
dataGridUpdates.ItemsSource = null;
220+
var task = GetUnityUpdates.Scan();
221+
var items = await task;
222+
// TODO handle errors?
223+
if (items == null) return;
224+
updatesSource = GetUnityUpdates.Parse(items);
225+
if (updatesSource == null) return;
226+
dataGridUpdates.ItemsSource = updatesSource;
227+
}
211228

212229
//
213230
//
@@ -297,22 +314,23 @@ private void BtnMinimize_Click(object sender, RoutedEventArgs e)
297314
{
298315
// remove focus from minimize button
299316
gridRecent.Focus();
300-
notifyIcon.Visible = true;
301-
this.Hide();
317+
if (chkMinimizeToTaskbar.IsChecked == true)
318+
{
319+
notifyIcon.Visible = true;
320+
this.Hide();
321+
}
322+
else
323+
{
324+
this.WindowState = WindowState.Minimized;
325+
}
302326
}
303327

304328
private async void OnGetUnityUpdatesClick(object sender, RoutedEventArgs e)
305329
{
306330
var button = (Button)sender;
307331
button.IsEnabled = false;
308332

309-
var task = GetUnityUpdates.Scan();
310-
var items = await task;
311-
// TODO handle errors?
312-
if (items == null) return;
313-
updatesSource = GetUnityUpdates.Parse(items);
314-
if (updatesSource == null) return;
315-
dataGridUpdates.ItemsSource = updatesSource;
333+
CallGetUnityUpdates();
316334

317335
button.IsEnabled = true;
318336
}
@@ -321,33 +339,63 @@ private void OnWindowKeyDown(object sender, KeyEventArgs e)
321339
{
322340
// TODO if editing cells, dont focus on search
323341
//if (gridRecent.IsCurrentCellInEditMode == true) return;
324-
switch (e.Key)
342+
343+
switch (tabControl.SelectedIndex)
325344
{
326-
case Key.Escape: // clear project search
327-
if (tabControl.SelectedIndex == 0 && txtSearchBox.Text != "")
345+
case 0: // Projects
346+
347+
switch (e.Key)
328348
{
329-
txtSearchBox.Text = "";
349+
case Key.F5: // refresh projects
350+
projectsSource = GetProjects.Scan();
351+
gridRecent.ItemsSource = projectsSource;
352+
break;
353+
case Key.Escape: // clear project search
354+
txtSearchBox.Text = "";
355+
break;
356+
default: // any key
357+
// activate searchbar if not active and we are in tab#1
358+
if (txtSearchBox.IsFocused == false)
359+
{
360+
txtSearchBox.Focus();
361+
txtSearchBox.Select(txtSearchBox.Text.Length, 0);
362+
}
363+
break;
330364
}
331-
// clear updates search
332-
else if (tabControl.SelectedIndex == 2 && txtSearchBoxUpdates.Text != "")
365+
366+
break;
367+
case 1: // Unitys
368+
369+
switch (e.Key)
333370
{
334-
txtSearchBoxUpdates.Text = "";
371+
case Key.F5: // refresh unitys
372+
UpdateUnityInstallationsList(); break;
373+
case Key.Escape: // clear project search
374+
txtSearchBoxUnity.Text = "";
375+
break;
376+
default: // any key
377+
break;
335378
}
336379
break;
337-
case Key.Up:
338-
break;
339-
case Key.Down:
340-
break;
341-
default: // any key
342380

343-
// activate searchbar if not active and we are in tab#1
344-
if (tabControl.SelectedIndex == 0 && txtSearchBox.IsFocused == false)
381+
case 2: // Updates
382+
383+
switch (e.Key)
345384
{
346-
txtSearchBox.Focus();
347-
txtSearchBox.Select(txtSearchBox.Text.Length, 0);
385+
case Key.F5: // refresh unitys
386+
CallGetUnityUpdates();
387+
break;
388+
case Key.Escape: // clear project search
389+
txtSearchBoxUpdates.Text = "";
390+
break;
391+
default: // any key
392+
break;
348393
}
349394
break;
395+
default:
396+
break;
350397
}
398+
351399
}
352400

353401
private async void OnTabSelectionChanged(object sender, SelectionChangedEventArgs e)
@@ -412,8 +460,22 @@ private void BtnExplore_Click(object sender, RoutedEventArgs e)
412460
// copy selected row unity version to clipboard
413461
private void MenuItemCopyVersion_Click(object sender, RoutedEventArgs e)
414462
{
415-
var proj = GetSelectedProject();
416-
Clipboard.SetText(proj?.Version);
463+
string copy = null;
464+
if (tabControl.SelectedIndex == 0)
465+
{
466+
var proj = GetSelectedProject();
467+
copy = proj?.Version;
468+
}
469+
else if (tabControl.SelectedIndex == 1)
470+
{
471+
var unity = GetSelectedUnity();
472+
copy = unity?.Version;
473+
}
474+
else if (tabControl.SelectedIndex == 2)
475+
{
476+
//var update = getselect
477+
}
478+
if (copy != null) Clipboard.SetText(copy);
417479
}
418480

419481
private void BtnRefreshProjectList_Click(object sender, RoutedEventArgs e)
@@ -518,10 +580,20 @@ private void BtnRemoveInstallationFolder_Click(object sender, RoutedEventArgs e)
518580
// need to manually move into next/prev rows? https://stackoverflow.com/a/11652175/5452781
519581
private void GridRecent_PreviewKeyDown(object sender, KeyEventArgs e)
520582
{
521-
if (e.Key == Key.Return)
583+
switch (e.Key)
522584
{
523-
e.Handled = true;
524-
Tools.LaunchProject(GetSelectedProject());
585+
case Key.Tab:
586+
if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
587+
{
588+
e.Handled = true;
589+
}
590+
break;
591+
case Key.Return:
592+
e.Handled = true;
593+
Tools.LaunchProject(GetSelectedProject());
594+
break;
595+
default:
596+
break;
525597
}
526598
}
527599

@@ -610,6 +682,52 @@ private void BtnAdbBindWifi_Click(object sender, RoutedEventArgs e)
610682
//// connect device (use your device ip address)
611683
//adb connect IP_HERE:5555
612684
}
685+
686+
private void BtnRefreshUnityList_Click(object sender, RoutedEventArgs e)
687+
{
688+
UpdateUnityInstallationsList();
689+
}
690+
691+
private void BtnDonwloadInBrowser_Click(object sender, RoutedEventArgs e)
692+
{
693+
var unity = GetSelectedUpdate();
694+
string url = Tools.GetUnityReleaseURL(unity?.Version);
695+
if (string.IsNullOrEmpty(url) == false)
696+
{
697+
Tools.DownloadInBrowser(url, unity.Version);
698+
}
699+
else
700+
{
701+
Console.WriteLine("Failed getting Unity Installer URL for " + unity.Version);
702+
}
703+
}
704+
705+
private void BtnOpenWebsite_Click(object sender, RoutedEventArgs e)
706+
{
707+
var unity = GetSelectedUpdate();
708+
Tools.OpenReleaseNotes(unity?.Version);
709+
}
710+
711+
private void ChkMinimizeToTaskbar_CheckedChanged(object sender, RoutedEventArgs e)
712+
{
713+
Properties.Settings.Default.minimizeToTaskbar = (bool)chkMinimizeToTaskbar.IsChecked;
714+
Properties.Settings.Default.Save();
715+
}
716+
717+
private void ChkRegisterExplorerMenu_CheckedChanged(object sender, RoutedEventArgs e)
718+
{
719+
if ((bool)chkRegisterExplorerMenu.IsChecked)
720+
{
721+
Tools.AddContextMenuRegistry(contextRegRoot);
722+
}
723+
else // remove
724+
{
725+
Tools.RemoveContextMenuRegistry(contextRegRoot);
726+
}
727+
728+
Properties.Settings.Default.registerExplorerMenu = (bool)chkRegisterExplorerMenu.IsChecked;
729+
Properties.Settings.Default.Save();
730+
}
613731
} // class
614732
} //namespace
615733

0 commit comments

Comments
 (0)