Skip to content

Commit 7c0da0d

Browse files
committed
add project list search filtering, add window size usersettings, rename dataGrid to gridRecent
1 parent dfe3337 commit 7c0da0d

File tree

5 files changed

+176
-33
lines changed

5 files changed

+176
-33
lines changed

UnityLauncherPro/App.config

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<configuration>
3+
<configSections>
4+
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
5+
<section name="UnityLauncherPro.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
6+
</sectionGroup>
7+
</configSections>
38
<startup>
49
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
510
</startup>
11+
<userSettings>
12+
<UnityLauncherPro.Properties.Settings>
13+
<setting name="windowWidth" serializeAs="String">
14+
<value>600</value>
15+
</setting>
16+
<setting name="windowHeight" serializeAs="String">
17+
<value>650</value>
18+
</setting>
19+
</UnityLauncherPro.Properties.Settings>
20+
</userSettings>
621
</configuration>

UnityLauncherPro/MainWindow.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:local="clr-namespace:UnityLauncherPro"
77
mc:Ignorable="d"
8-
Title="UnityLauncherPro" Height="650" Width="600" WindowStartupLocation="CenterScreen" Background="{DynamicResource DarkestBackground}" MinWidth="600" MinHeight="650" AllowsTransparency="True" WindowStyle="None" Margin="0" KeyDown="OnWindowKeyDown" >
8+
Title="UnityLauncherPro" Height="650" Width="600" WindowStartupLocation="CenterScreen" Background="{DynamicResource DarkestBackground}" MinWidth="600" MinHeight="650" AllowsTransparency="True" WindowStyle="None" Margin="0" KeyDown="OnWindowKeyDown" Closing="Window_Closing" SizeChanged="Window_SizeChanged" >
99

1010
<Window.Resources>
1111
<!-- tabs -->
@@ -287,7 +287,7 @@
287287
<Button Style="{StaticResource CustomButton}" ToolTip="Add existing project" x:Name="btnAddProjectFolder" Content="Add Project.." Height="22" Width="78" HorizontalAlignment="Right" VerticalAlignment="Top" Background="#FF3F3F46" Foreground="#FFC1C1C1" Margin="0,4,34,0" Click="BtnAddProjectFolder_Click" BorderBrush="{x:Null}" />
288288
<Button Style="{StaticResource CustomButton}" ToolTip="Refresh list (F5)" x:Name="btnRefreshProjectList" 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}"/>
289289

290-
<DataGrid x:Name="dataGrid" 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">
290+
<DataGrid x:Name="gridRecent" 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">
291291

292292
<DataGrid.Columns>
293293
<DataGridTextColumn Binding="{Binding Title}" ClipboardContentBinding="{x:Null}" Header="Project" IsReadOnly="True" Width="150"/>

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 116 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
using System;
2+
using System.ComponentModel;
23
using System.Drawing; // for notifyicon
3-
using System.Linq;
4-
using System.Threading.Tasks;
4+
using System.IO;
55
using System.Windows;
66
using System.Windows.Controls;
7+
using System.Windows.Data;
78
using System.Windows.Input;
89
using System.Windows.Shell;
910

1011
namespace UnityLauncherPro
1112
{
12-
/// <summary>
13-
/// Interaction logic for MainWindow.xaml
14-
/// </summary>
1513
public partial class MainWindow : Window
1614
{
1715

@@ -21,6 +19,8 @@ public partial class MainWindow : Window
2119
Updates[] updatesSource;
2220
UnityInstallation[] unityInstallationsSource;
2321

22+
string _filterString = null;
23+
2424
public MainWindow()
2525
{
2626
InitializeComponent();
@@ -29,9 +29,11 @@ public MainWindow()
2929

3030
void Start()
3131
{
32+
LoadSettings();
33+
3234
// make window resizable (this didnt work when used pure xaml to do this)
3335
WindowChrome Resizable_BorderLess_Chrome = new WindowChrome();
34-
Resizable_BorderLess_Chrome.GlassFrameThickness = new Thickness(0);
36+
//Resizable_BorderLess_Chrome.GlassFrameThickness = new Thickness(0);
3537
Resizable_BorderLess_Chrome.CornerRadius = new CornerRadius(0);
3638
Resizable_BorderLess_Chrome.CaptionHeight = 1.0;
3739
WindowChrome.SetWindowChrome(this, Resizable_BorderLess_Chrome);
@@ -45,8 +47,8 @@ void Start()
4547

4648
//dataGrid.Items.Add(GetProjects.Scan());
4749
projectsSource = GetProjects.Scan();
48-
dataGrid.Items.Clear();
49-
dataGrid.ItemsSource = projectsSource;
50+
gridRecent.Items.Clear();
51+
gridRecent.ItemsSource = projectsSource;
5052

5153
// updates grid
5254
dataGridUpdates.Items.Clear();
@@ -93,6 +95,7 @@ private void OnRectangleMouseDown(object sender, MouseButtonEventArgs e)
9395
private void OnSearchTextChanged(object sender, TextChangedEventArgs e)
9496
{
9597
TextBox textbox = (TextBox)sender;
98+
FilterRecentProjects();
9699
//FilterProjects(textbox.Text);
97100
}
98101

@@ -102,13 +105,26 @@ private void OnSearchPreviewKeyDown(object sender, KeyEventArgs e)
102105
{
103106
case Key.Escape:
104107
((TextBox)sender).Text = "";
105-
//FilterProjects(null);
106108
break;
107109
default:
108110
break;
109111
}
110112
}
111113

114+
void FilterRecentProjects()
115+
{
116+
// https://www.wpftutorial.net/DataViews.html
117+
_filterString = txtSearchBox.Text;
118+
ICollectionView collection = CollectionViewSource.GetDefaultView(projectsSource);
119+
collection.Filter = ProjectFilter;
120+
}
121+
122+
private bool ProjectFilter(object item)
123+
{
124+
Project proj = item as Project;
125+
return (proj.Title.IndexOf(_filterString, 0, StringComparison.CurrentCultureIgnoreCase) != -1);
126+
}
127+
112128
private void BtnAddProjectFolder_Click(object sender, RoutedEventArgs e)
113129
{
114130
// https://stackoverflow.com/a/50261723/5452781
@@ -125,9 +141,9 @@ private void BtnAddProjectFolder_Click(object sender, RoutedEventArgs e)
125141
path = path.Replace("\\Project.Folder", "");
126142
path = path.Replace("Project.Folder", "");
127143
// If user has changed the filename, create the new directory
128-
if (!System.IO.Directory.Exists(path))
144+
if (!Directory.Exists(path))
129145
{
130-
System.IO.Directory.CreateDirectory(path);
146+
Directory.CreateDirectory(path);
131147
}
132148
// Our final value is in path
133149
Console.WriteLine(path);
@@ -142,7 +158,7 @@ private void BtnClose_Click(object sender, RoutedEventArgs e)
142158
private void BtnMinimize_Click(object sender, RoutedEventArgs e)
143159
{
144160
// remove focus from minimize button
145-
dataGrid.Focus();
161+
gridRecent.Focus();
146162
notifyIcon.Visible = true;
147163
this.Hide();
148164
}
@@ -188,13 +204,15 @@ private void OnWindowKeyDown(object sender, KeyEventArgs e)
188204
}
189205
break;
190206
default: // any key
207+
191208
// activate searchbar if not active and we are in tab#1
192209
if (tabControl.SelectedIndex == 0 && txtSearchBox.IsFocused == false)
193210
{
194211
// dont write tab key on search field
195212
if (e.Key == Key.Tab) break;
213+
196214
txtSearchBox.Focus();
197-
txtSearchBox.Text += e.Key;
215+
//txtSearchBox.Text += e.Key;
198216
txtSearchBox.Select(txtSearchBox.Text.Length, 0);
199217
}
200218
break;
@@ -233,5 +251,90 @@ private void OnClearUpdateSearchClick(object sender, RoutedEventArgs e)
233251
{
234252
txtSearchBoxUpdates.Text = "";
235253
}
254+
255+
void LoadSettings()
256+
{
257+
// form size
258+
this.Width = Properties.Settings.Default.windowWidth;
259+
this.Height = Properties.Settings.Default.windowHeight;
260+
261+
/*
262+
// update settings window
263+
chkMinimizeToTaskbar.Checked = Properties.Settings.Default.minimizeToTaskbar;
264+
chkQuitAfterCommandline.Checked = Properties.Settings.Default.closeAfterExplorer;
265+
ChkQuitAfterOpen.Checked = Properties.Settings.Default.closeAfterProject;
266+
chkShowLauncherArgumentsColumn.Checked = Properties.Settings.Default.showArgumentsColumn;
267+
chkShowGitBranchColumn.Checked = Properties.Settings.Default.showGitBranchColumn;
268+
chkDarkSkin.Checked = Properties.Settings.Default.useDarkSkin;
269+
270+
// update optional grid columns, hidden or visible
271+
gridRecent.Columns["_launchArguments"].Visible = chkShowLauncherArgumentsColumn.Checked;
272+
gridRecent.Columns["_gitBranch"].Visible = chkShowGitBranchColumn.Checked;
273+
274+
// update installations folder listbox
275+
lstRootFolders.Items.Clear();
276+
lstRootFolders.Items.AddRange(Properties.Settings.Default.rootFolders.Cast<string>().ToArray());
277+
// update packages folder listbox
278+
lstPackageFolders.Items.AddRange(Properties.Settings.Default.packageFolders.Cast<string>().ToArray());
279+
280+
// restore datagrid column widths
281+
int[] gridColumnWidths = Properties.Settings.Default.gridColumnWidths;
282+
if (gridColumnWidths != null)
283+
{
284+
for (int i = 0; i < gridColumnWidths.Length; ++i)
285+
{
286+
gridRecent.Columns[i].Width = gridColumnWidths[i];
287+
}
288+
}
289+
*/
290+
291+
292+
} // LoadSettings()
293+
294+
private void Window_Closing(object sender, CancelEventArgs e)
295+
{
296+
SaveSettingsOnExit();
297+
}
298+
299+
private void SaveSettingsOnExit()
300+
{
301+
/*
302+
// save list column widths
303+
List<int> gridWidths;
304+
if (Properties.Settings.Default.gridColumnWidths != null)
305+
{
306+
gridWidths = new List<int>(Properties.Settings.Default.gridColumnWidths);
307+
}
308+
else
309+
{
310+
gridWidths = new List<int>();
311+
}
312+
313+
// restore data grid view widths
314+
var colum = gridRecent.Columns[0];
315+
for (int i = 0; i < gridRecent.Columns.Count; ++i)
316+
{
317+
if (Properties.Settings.Default.gridColumnWidths != null && Properties.Settings.Default.gridColumnWidths.Length > i)
318+
{
319+
gridWidths[i] = gridRecent.Columns[i].Width;
320+
}
321+
else
322+
{
323+
gridWidths.Add(gridRecent.Columns[i].Width);
324+
}
325+
}
326+
Properties.Settings.Default.gridColumnWidths = gridWidths.ToArray();
327+
Properties.Settings.Default.Save();
328+
*/
329+
}
330+
331+
// save window size after resize
332+
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
333+
{
334+
var win = (Window)sender;
335+
Properties.Settings.Default.windowWidth = (int)win.Width;
336+
Properties.Settings.Default.windowHeight = (int)win.Height;
337+
Properties.Settings.Default.Save();
338+
}
236339
}
237340
}

UnityLauncherPro/Properties/Settings.Designer.cs

Lines changed: 33 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
<?xml version='1.0' encoding='utf-8'?>
2-
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
3-
<Profiles>
4-
<Profile Name="(Default)" />
5-
</Profiles>
6-
<Settings />
2+
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="UnityLauncherPro.Properties" GeneratedClassName="Settings">
3+
<Profiles />
4+
<Settings>
5+
<Setting Name="windowWidth" Type="System.Int32" Scope="User">
6+
<Value Profile="(Default)">600</Value>
7+
</Setting>
8+
<Setting Name="windowHeight" Type="System.Int32" Scope="User">
9+
<Value Profile="(Default)">650</Value>
10+
</Setting>
11+
</Settings>
712
</SettingsFile>

0 commit comments

Comments
 (0)