Skip to content

Commit d37fba5

Browse files
committed
add star icon for preferred unity, fix update list downloading, add preferredversion string to compare with, improve focus on search results and after clearning search (keeps previous item if didnt change it, on keydown move to first item (not 2nd)
1 parent 06da9f9 commit d37fba5

File tree

5 files changed

+47
-18
lines changed

5 files changed

+47
-18
lines changed

Diff for: UnityLauncherPro/Data/UnityInstallation.cs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class UnityInstallation : IValueConverter
99
public string Path { set; get; }
1010
public DateTime? Installed { set; get; }
1111
public string Platforms { set; get; }
12+
public bool IsPreferred { set; get; }
1213

1314
// color project unity version cells, depending if have that version installed
1415
// https://stackoverflow.com/a/5551986/5452781

Diff for: UnityLauncherPro/GetUnityInstallations.cs

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public static UnityInstallation[] Scan()
4848
unity.Version = version;
4949
unity.Path = exePath;
5050
unity.Installed = installDate;
51+
unity.IsPreferred = (version == MainWindow.preferredVersion);
5152

5253
// TEST get platforms, NOTE if this is slow, do it later, or skip for commandline
5354
var platforms = GetPlatforms(dataFolder);

Diff for: UnityLauncherPro/GetUnityUpdates.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static async Task<string> Scan()
1515
{
1616
if (isDownloadingUnityList == true)
1717
{
18-
//SetStatus("We are already downloading ...");
18+
Console.WriteLine("We are already downloading ...");
1919
return null;
2020
}
2121

@@ -28,8 +28,8 @@ public static async Task<string> Scan()
2828

2929
Task<string> downloadStringTask = webClient.DownloadStringTaskAsync(new Uri(unityVersionsURL));
3030
result = await downloadStringTask;
31+
isDownloadingUnityList = false;
3132
}
32-
3333
return result;
3434
}
3535

Diff for: UnityLauncherPro/MainWindow.xaml

+13-1
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,19 @@
426426
<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" PreviewMouseDoubleClick="DataGridUnitys_PreviewMouseDoubleClick">
427427

428428
<DataGrid.Columns>
429+
<DataGridTextColumn ClipboardContentBinding="{x:Null}" IsReadOnly="True" MinWidth="16">
430+
<DataGridTextColumn.ElementStyle>
431+
<Style TargetType="{x:Type TextBlock}">
432+
<Style.Triggers>
433+
<DataTrigger Binding="{Binding IsPreferred}" Value="true">
434+
<Setter Property="Text" Value="" />
435+
<Setter Property="TextAlignment" Value="Center" />
436+
</DataTrigger>
437+
</Style.Triggers>
438+
</Style>
439+
</DataGridTextColumn.ElementStyle>
440+
</DataGridTextColumn>
441+
429442
<DataGridTextColumn Binding="{Binding Version}" ClipboardContentBinding="{x:Null}" Header="Version" IsReadOnly="True" MinWidth="123"/>
430443
<DataGridTextColumn Binding="{Binding Path}" ClipboardContentBinding="{x:Null}" Header="Path" IsReadOnly="True"/>
431444
<DataGridTextColumn Binding="{Binding Installed, StringFormat=\{0:dd/MM/yyyy HH:mm:ss\}}" ClipboardContentBinding="{x:Null}" Header="Installed" IsReadOnly="True"/>
@@ -503,7 +516,6 @@
503516
<Button Style="{StaticResource CustomButton}" ToolTip="Fetch released versions" x:Name="btnRefreshUpdatesList" 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="OnGetUnityUpdatesClick"/>
504517

505518
<DataGrid x:Name="dataGridUpdates" 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="DataGridUpdates_PreviewKeyDown" PreviewMouseDoubleClick="DataGridUpdates_PreviewMouseDoubleClick">
506-
507519
<DataGrid.Columns>
508520
<DataGridTextColumn Binding="{Binding ReleaseDate, StringFormat=\{0:dd/MM/yyyy\}}" ClipboardContentBinding="{x:Null}" MinWidth="100" Header="ReleaseDate" IsReadOnly="True"/>
509521
<DataGridTextColumn Binding="{Binding Version}" ClipboardContentBinding="{x:Null}" Header="Version" IsReadOnly="True" MinWidth="123">

Diff for: UnityLauncherPro/MainWindow.xaml.cs

+30-15
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public partial class MainWindow : Window
4040
string _filterString = null;
4141
const string githubURL = "https://github.com/unitycoder/UnityLauncherPro";
4242
int lastSelectedProjectIndex = 0;
43+
public static string preferredVersion = "none";
4344
Mutex myMutex;
4445

4546
public MainWindow()
@@ -174,11 +175,11 @@ void FilterRecentProjects()
174175
_filterString = txtSearchBox.Text;
175176
ICollectionView collection = CollectionViewSource.GetDefaultView(projectsSource);
176177
collection.Filter = ProjectFilter;
177-
// set first row selected
178-
if (gridRecent.Items.Count > 0)
179-
{
180-
gridRecent.SelectedIndex = 0;
181-
}
178+
// set first row selected, if only 1 row
179+
//if (gridRecent.Items.Count == 1)
180+
//{
181+
// gridRecent.SelectedIndex = 0;
182+
//}
182183
}
183184

184185
void FilterUpdates()
@@ -242,7 +243,6 @@ void LoadSettings()
242243
gridRecent.Columns[4].Visibility = (bool)chkShowLauncherArgumentsColumn.IsChecked ? Visibility.Visible : Visibility.Collapsed;
243244
gridRecent.Columns[5].Visibility = (bool)chkShowGitBranchColumn.IsChecked ? Visibility.Visible : Visibility.Collapsed;
244245

245-
246246
// update installations folder listbox
247247
lstRootFolders.Items.Clear();
248248
lstRootFolders.ItemsSource = Properties.Settings.Default.rootFolders;
@@ -256,6 +256,10 @@ void LoadSettings()
256256
gridRecent.Columns[i].Width = gridColumnWidths[i];
257257
}
258258
}
259+
260+
// other setting vars
261+
preferredVersion = Properties.Settings.Default.preferredVersion;
262+
259263
} // LoadSettings()
260264

261265
private void SaveSettingsOnExit()
@@ -292,6 +296,9 @@ private void SaveSettingsOnExit()
292296

293297
void UpdateUnityInstallationsList()
294298
{
299+
// reset preferred string, if user changed it
300+
//preferredVersion = "none";
301+
295302
unityInstallationsSource = GetUnityInstallations.Scan();
296303
dataGridUnitys.ItemsSource = unityInstallationsSource;
297304

@@ -300,7 +307,7 @@ void UpdateUnityInstallationsList()
300307
for (int i = 0, len = unityInstallationsSource.Length; i < len; i++)
301308
{
302309
var version = unityInstallationsSource[i].Version;
303-
if (string.IsNullOrEmpty(version)==false && unityInstalledVersions.ContainsKey(version) == false)
310+
if (string.IsNullOrEmpty(version) == false && unityInstalledVersions.ContainsKey(version) == false)
304311
{
305312
unityInstalledVersions.Add(version, unityInstallationsSource[i].Path);
306313
}
@@ -339,13 +346,13 @@ void AddUnityInstallationRootFolder()
339346
}
340347
}
341348

342-
343-
349+
// waits for unity update results and assigns to datagrid
344350
async void CallGetUnityUpdates()
345351
{
346352
dataGridUpdates.ItemsSource = null;
347353
var task = GetUnityUpdates.Scan();
348354
var items = await task;
355+
Console.WriteLine(items == null);
349356
if (items == null) return;
350357
updatesSource = GetUnityUpdates.Parse(items);
351358
if (updatesSource == null) return;
@@ -485,7 +492,7 @@ private void OnWindowKeyDown(object sender, KeyEventArgs e)
485492
case Key.Escape: // clear project search
486493
if (txtSearchBox.Text == "")
487494
{
488-
Tools.SetFocusToGrid(gridRecent);
495+
if (txtSearchBox.IsFocused) Tools.SetFocusToGrid(gridRecent);
489496
}
490497
txtSearchBox.Text = "";
491498
break;
@@ -555,11 +562,12 @@ private async void OnTabSelectionChanged(object sender, SelectionChangedEventArg
555562
// if going into updates tab, fetch list (first time only)
556563
if (((TabControl)sender).SelectedIndex == (int)Tabs.Updates)
557564
{
565+
// if we dont have previous results yet, TODO scan again if previous was 24hrs ago
558566
if (updatesSource == null)
559567
{
560568
var task = GetUnityUpdates.Scan();
561-
if (task.IsCompleted == false) return;
562569
var items = await task;
570+
if (task.IsCompleted == false || task.IsFaulted == true) return;
563571
if (items == null) return;
564572
updatesSource = GetUnityUpdates.Parse(items);
565573
if (updatesSource == null) return;
@@ -601,12 +609,14 @@ private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
601609
private void BtnLaunchProject_Click(object sender, RoutedEventArgs e)
602610
{
603611
Tools.LaunchProject(GetSelectedProject());
612+
Tools.SetFocusToGrid(gridRecent);
604613
}
605614

606615
private void BtnExplore_Click(object sender, RoutedEventArgs e)
607616
{
608617
var proj = GetSelectedProject();
609618
Tools.ExploreProjectFolder(proj);
619+
Tools.SetFocusToGrid(gridRecent);
610620
}
611621

612622
// copy selected row unity version to clipboard
@@ -719,6 +729,7 @@ private void TxtSearchBox_PreviewKeyDown(object sender, KeyEventArgs e)
719729
case Key.Up:
720730
case Key.Down:
721731
Tools.SetFocusToGrid(gridRecent);
732+
e.Handled = true; // to stay in first row
722733
break;
723734
default:
724735
break;
@@ -814,6 +825,7 @@ private void TxtSearchBoxUpdates_PreviewKeyDown(object sender, KeyEventArgs e)
814825
case Key.Up:
815826
case Key.Down:
816827
Tools.SetFocusToGrid(dataGridUpdates);
828+
e.Handled = true;
817829
break;
818830
default:
819831
break;
@@ -935,7 +947,7 @@ private void BtnDonwloadInBrowser_Click(object sender, RoutedEventArgs e)
935947
}
936948
else
937949
{
938-
Console.WriteLine("Failed getting Unity Installer URL for " + unity.Version);
950+
Console.WriteLine("Failed getting Unity Installer URL for " + unity?.Version);
939951
}
940952
}
941953

@@ -1106,10 +1118,13 @@ private void BtnAssetPackages_Click(object sender, RoutedEventArgs e)
11061118
// sets selected unity version as preferred main unity version (to be preselected in case of unknown version projects, when creating new empty project, etc)
11071119
private void MenuItemSetPreferredUnityVersion_Click(object sender, RoutedEventArgs e)
11081120
{
1109-
Properties.Settings.Default.preferredVersion = GetSelectedUnity().Version;
1121+
var ver = GetSelectedUnity().Version;
1122+
Properties.Settings.Default.preferredVersion = ver;
11101123
Properties.Settings.Default.Save();
1111-
1112-
// TODO set star icon
1124+
1125+
preferredVersion = ver;
1126+
// TODO update unity list or just set value?
1127+
UpdateUnityInstallationsList();
11131128

11141129
}
11151130
} // class

0 commit comments

Comments
 (0)