Skip to content

Commit 06da9f9

Browse files
committed
fix unknown unity version starting (expermental versions dont have dictionary key), adding preferred version option, move SetFocusToGrid in tools,
1 parent ac025a0 commit 06da9f9

File tree

7 files changed

+60
-27
lines changed

7 files changed

+60
-27
lines changed

UnityLauncherPro/App.config

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
<setting name="AllowSingleInstanceOnly" serializeAs="String">
4949
<value>False</value>
5050
</setting>
51+
<setting name="preferredVersion" serializeAs="String">
52+
<value />
53+
</setting>
5154
</UnityLauncherPro.Properties.Settings>
5255
</userSettings>
5356
</configuration>

UnityLauncherPro/MainWindow.xaml

+1
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@
437437
<ContextMenu>
438438
<MenuItem x:Name="menuItemCopyVersionInstalled" Header="Copy Unity Version" Click="MenuItemCopyVersion_Click" />
439439
<MenuItem x:Name="menuItemShowUnityInExplorer" Header="Show in Explorer" Click="MenuItemShowProjectInExplorer_Click" />
440+
<MenuItem x:Name="menuItemSetPreferredUnityVersion" Header="Set as Preferred Version" Click="MenuItemSetPreferredUnityVersion_Click"/>
440441
</ContextMenu>
441442
</DataGrid.ContextMenu>
442443

UnityLauncherPro/MainWindow.xaml.cs

+18-22
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ void UpdateUnityInstallationsList()
300300
for (int i = 0, len = unityInstallationsSource.Length; i < len; i++)
301301
{
302302
var version = unityInstallationsSource[i].Version;
303-
if (unityInstalledVersions.ContainsKey(version) == false)
303+
if (string.IsNullOrEmpty(version)==false && unityInstalledVersions.ContainsKey(version) == false)
304304
{
305305
unityInstalledVersions.Add(version, unityInstallationsSource[i].Path);
306306
}
@@ -339,21 +339,7 @@ void AddUnityInstallationRootFolder()
339339
}
340340
}
341341

342-
void SetFocusToGrid(DataGrid targetGrid, int index = 0)
343-
{
344-
//e.Handled = true; // if enabled, we enter to first row initially
345-
if (targetGrid.Items.Count < 1) return;
346-
targetGrid.Focus();
347-
DataGridRow row = (DataGridRow)targetGrid.ItemContainerGenerator.ContainerFromIndex(index);
348-
if (row == null)
349-
{
350-
gridRecent.UpdateLayout();
351-
gridRecent.ScrollIntoView(gridRecent.Items[index]);
352-
row = (DataGridRow)gridRecent.ItemContainerGenerator.ContainerFromIndex(index);
353-
}
354-
row.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
355-
targetGrid.SelectedIndex = index;
356-
}
342+
357343

358344
async void CallGetUnityUpdates()
359345
{
@@ -499,7 +485,7 @@ private void OnWindowKeyDown(object sender, KeyEventArgs e)
499485
case Key.Escape: // clear project search
500486
if (txtSearchBox.Text == "")
501487
{
502-
SetFocusToGrid(gridRecent);
488+
Tools.SetFocusToGrid(gridRecent);
503489
}
504490
txtSearchBox.Text = "";
505491
break;
@@ -671,7 +657,7 @@ private void BtnUpgradeProject_Click(object sender, RoutedEventArgs e)
671657
private void GridRecent_Loaded(object sender, RoutedEventArgs e)
672658
{
673659
//Console.WriteLine("GridRecent_Loaded");
674-
SetFocusToGrid(gridRecent);
660+
Tools.SetFocusToGrid(gridRecent);
675661
}
676662

677663
private void BtnExploreUnity_Click(object sender, RoutedEventArgs e)
@@ -732,7 +718,7 @@ private void TxtSearchBox_PreviewKeyDown(object sender, KeyEventArgs e)
732718
case Key.Tab:
733719
case Key.Up:
734720
case Key.Down:
735-
SetFocusToGrid(gridRecent);
721+
Tools.SetFocusToGrid(gridRecent);
736722
break;
737723
default:
738724
break;
@@ -745,7 +731,7 @@ private void TxtSearchBoxUnity_PreviewKeyDown(object sender, KeyEventArgs e)
745731
{
746732
case Key.Up:
747733
case Key.Down:
748-
SetFocusToGrid(dataGridUnitys);
734+
Tools.SetFocusToGrid(dataGridUnitys);
749735
break;
750736
default:
751737
break;
@@ -782,7 +768,7 @@ private void GridRecent_PreviewKeyDown(object sender, KeyEventArgs e)
782768
lastSelectedProjectIndex = gridRecent.SelectedIndex;
783769
projectsSource = GetProjects.Scan(getGitBranch: (bool)chkShowGitBranchColumn.IsChecked, getArguments: (bool)chkShowLauncherArgumentsColumn.IsChecked, showMissingFolders: (bool)chkShowMissingFolderProjects.IsChecked);
784770
gridRecent.ItemsSource = projectsSource;
785-
SetFocusToGrid(gridRecent, lastSelectedProjectIndex);
771+
Tools.SetFocusToGrid(gridRecent, lastSelectedProjectIndex);
786772
break;
787773
case Key.Tab:
788774
if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
@@ -827,7 +813,7 @@ private void TxtSearchBoxUpdates_PreviewKeyDown(object sender, KeyEventArgs e)
827813
{
828814
case Key.Up:
829815
case Key.Down:
830-
SetFocusToGrid(dataGridUpdates);
816+
Tools.SetFocusToGrid(dataGridUpdates);
831817
break;
832818
default:
833819
break;
@@ -1116,5 +1102,15 @@ private void BtnAssetPackages_Click(object sender, RoutedEventArgs e)
11161102
Console.WriteLine("Cannot open folder.." + folder);
11171103
}
11181104
}
1105+
1106+
// sets selected unity version as preferred main unity version (to be preselected in case of unknown version projects, when creating new empty project, etc)
1107+
private void MenuItemSetPreferredUnityVersion_Click(object sender, RoutedEventArgs e)
1108+
{
1109+
Properties.Settings.Default.preferredVersion = GetSelectedUnity().Version;
1110+
Properties.Settings.Default.Save();
1111+
1112+
// TODO set star icon
1113+
1114+
}
11191115
} // class
11201116
} //namespace

UnityLauncherPro/Properties/Settings.Designer.cs

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnityLauncherPro/Properties/Settings.settings

+3
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,8 @@
4141
<Setting Name="AllowSingleInstanceOnly" Type="System.Boolean" Scope="User">
4242
<Value Profile="(Default)">False</Value>
4343
</Setting>
44+
<Setting Name="preferredVersion" Type="System.String" Scope="User">
45+
<Value Profile="(Default)" />
46+
</Setting>
4447
</Settings>
4548
</SettingsFile>

UnityLauncherPro/Tools.cs

+19-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Text;
99
using System.Text.RegularExpressions;
1010
using System.Windows;
11+
using System.Windows.Controls;
1112
using System.Windows.Input;
1213

1314
namespace UnityLauncherPro
@@ -107,6 +108,7 @@ public static string GetProjectVersion(string path)
107108
}
108109
}
109110
}
111+
110112
return version;
111113
}
112114

@@ -138,7 +140,7 @@ public static void LaunchProject(Project proj)
138140
if (proj == null) return;
139141
if (Directory.Exists(proj.Path) == false) return;
140142

141-
Console.WriteLine("launch project " + proj.Title);
143+
Console.WriteLine("launch project " + proj.Title+" "+proj.Version);
142144

143145
// there is no assets path, probably we want to create new project then
144146
var assetsFolder = Path.Combine(proj.Path, "Assets");
@@ -158,7 +160,6 @@ public static void LaunchProject(Project proj)
158160
var unityExePath = GetUnityExePath(proj.Version);
159161
if (unityExePath == null)
160162
{
161-
//Console.WriteLine("Missing unity version " + proj.Version);
162163
DisplayUpgradeDialog(proj, null);
163164
return;
164165
}
@@ -662,5 +663,21 @@ public static string ReadCustomLaunchArguments(string projectPath, string launch
662663
return results;
663664
}
664665

666+
public static void SetFocusToGrid(DataGrid targetGrid, int index = 0)
667+
{
668+
//e.Handled = true; // if enabled, we enter to first row initially
669+
if (targetGrid.Items.Count < 1) return;
670+
targetGrid.Focus();
671+
DataGridRow row = (DataGridRow)targetGrid.ItemContainerGenerator.ContainerFromIndex(index);
672+
if (row == null)
673+
{
674+
targetGrid.UpdateLayout();
675+
targetGrid.ScrollIntoView(targetGrid.Items[index]);
676+
row = (DataGridRow)targetGrid.ItemContainerGenerator.ContainerFromIndex(index);
677+
}
678+
row.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
679+
targetGrid.SelectedIndex = index;
680+
}
681+
665682
} // class
666683
} // namespace

UnityLauncherPro/UpgradeWindow.xaml.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,10 @@ private void GridAvailableVersions_PreviewKeyDown(object sender, KeyEventArgs e)
124124

125125
private void GridAvailableVersions_Loaded(object sender, RoutedEventArgs e)
126126
{
127-
gridAvailableVersions.Focus();
128-
DataGridRow row = (DataGridRow)gridAvailableVersions.ItemContainerGenerator.ContainerFromIndex(gridAvailableVersions.SelectedIndex);
129-
row.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
127+
Tools.SetFocusToGrid(gridAvailableVersions);
128+
// gridAvailableVersions.Focus();
129+
// DataGridRow row = (DataGridRow)gridAvailableVersions.ItemContainerGenerator.ContainerFromIndex(gridAvailableVersions.SelectedIndex);
130+
// row.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
130131
}
131132

132133
}

0 commit comments

Comments
 (0)