Skip to content

Commit fd698ef

Browse files
committed
adding persistent sort column and sort direction #123
1 parent 6ab2f98 commit fd698ef

File tree

4 files changed

+58
-4
lines changed

4 files changed

+58
-4
lines changed

Diff for: UnityLauncherPro/MainWindow.xaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
</DataGridTextColumn.HeaderTemplate>
9090
</DataGridTextColumn>
9191

92-
<DataGridTextColumn Binding="{Binding Version}" ClipboardContentBinding="{x:Null}" Header="Version" IsReadOnly="True" Width="72">
92+
<DataGridTextColumn Header="Version" Binding="{Binding Version}" ClipboardContentBinding="{x:Null}" IsReadOnly="True" Width="72">
9393
<DataGridTextColumn.HeaderTemplate>
9494
<DataTemplate>
9595
<TextBlock Text="Version" IsHitTestVisible="False" />
@@ -107,7 +107,7 @@
107107
</DataGridTextColumn.CellStyle>
108108
</DataGridTextColumn>
109109
<!--CellStyle="{StaticResource NoFocusCellStyle"}-->
110-
<DataGridTextColumn Header="Path" x:Name="txtColumnName" Binding="{Binding Path}" ClipboardContentBinding="{x:Null}" IsReadOnly="True" Width="185">
110+
<DataGridTextColumn Header="Path" x:Name="txtColumnPath" Binding="{Binding Path}" ClipboardContentBinding="{x:Null}" IsReadOnly="True" Width="185">
111111
<DataGridTextColumn.HeaderTemplate>
112112
<DataTemplate>
113113
<TextBlock Text="Path" IsHitTestVisible="False" />

Diff for: UnityLauncherPro/MainWindow.xaml.cs

+26-2
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,22 @@ private void GridRecent_Loaded(object sender, RoutedEventArgs e)
10941094
Tools.SetFocusToGrid(gridRecent);
10951095
// if coming from explorer launch, and missing unity version, projectsource is still null?
10961096
if (projectsSource != null) SetStatus("Ready (" + projectsSource.Count + " projects)");
1097+
1098+
// use saved sort columns
1099+
if (string.IsNullOrEmpty(Settings.Default.currentSortColumn) == false)
1100+
{
1101+
// check if that column exists in headers
1102+
foreach (DataGridColumn column in gridRecent.Columns)
1103+
{
1104+
if (column.Header.ToString() == Settings.Default.currentSortColumn)
1105+
{
1106+
// TODO Project binding is to Title, not project
1107+
Settings.Default.currentSortColumn = Settings.Default.currentSortColumn.Replace("Project", "Title");
1108+
gridRecent.Items.SortDescriptions.Add(new SortDescription(Settings.Default.currentSortColumn, Settings.Default.currentSortDirectionAscending ? ListSortDirection.Ascending : ListSortDirection.Descending));
1109+
break;
1110+
}
1111+
}
1112+
}
10971113
}
10981114

10991115
private void BtnExploreUnity_Click(object sender, RoutedEventArgs e)
@@ -1885,7 +1901,7 @@ private void ChkStreamerMode_Checked(object sender, RoutedEventArgs e)
18851901
Style cellStyle = new Style(typeof(DataGridCell));
18861902
cellStyle.Setters.Add(new Setter(FontSizeProperty, 1.0));
18871903
txtColumnTitle.CellStyle = isChecked ? cellStyle : null;
1888-
txtColumnName.CellStyle = isChecked ? cellStyle : null;
1904+
txtColumnPath.CellStyle = isChecked ? cellStyle : null;
18891905
txtColumnGitBranch.CellStyle = isChecked ? cellStyle : null;
18901906

18911907
Style txtBoxStyle = new Style(typeof(TextBox));
@@ -2915,7 +2931,6 @@ void SortHandlerUpdates(object sender, DataGridSortingEventArgs e)
29152931
{
29162932
DataGridColumn column = e.Column;
29172933

2918-
//Console.WriteLine("Sorted by " + column.Header);
29192934

29202935
IComparer comparer = null;
29212936

@@ -2981,13 +2996,22 @@ void SortHandlerRecentProjects(object sender, DataGridSortingEventArgs e)
29812996

29822997
//Console.WriteLine("Sorted by " + column.Header);
29832998

2999+
// save current sort to prefs
3000+
Settings.Default.currentSortColumn = column.Header.ToString();
3001+
29843002
IComparer comparer = null;
29853003

29863004
// prevent the built-in sort from sorting
29873005
e.Handled = true;
29883006

3007+
// load sort dir
3008+
column.SortDirection = Settings.Default.currentSortDirectionAscending ? ListSortDirection.Ascending : ListSortDirection.Descending;
3009+
29893010
ListSortDirection direction = (column.SortDirection != ListSortDirection.Ascending) ? ListSortDirection.Ascending : ListSortDirection.Descending;
29903011

3012+
// save
3013+
Settings.Default.currentSortDirectionAscending = direction == ListSortDirection.Ascending;
3014+
29913015
//set the sort order on the column
29923016
column.SortDirection = direction;
29933017

Diff for: UnityLauncherPro/Properties/Settings.Designer.cs

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

Diff for: UnityLauncherPro/Properties/Settings.settings

+6
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,11 @@
132132
<Setting Name="customInitFileURL" Type="System.String" Scope="User">
133133
<Value Profile="(Default)">https://raw.githubusercontent.com/unitycoder/UnityInitializeProject/main/Assets/Editor/InitializeProject.cs</Value>
134134
</Setting>
135+
<Setting Name="currentSortColumn" Type="System.String" Scope="User">
136+
<Value Profile="(Default)" />
137+
</Setting>
138+
<Setting Name="currentSortDirectionAscending" Type="System.Boolean" Scope="User">
139+
<Value Profile="(Default)">True</Value>
140+
</Setting>
135141
</Settings>
136142
</SettingsFile>

0 commit comments

Comments
 (0)