1
1
using System ;
2
+ using System . ComponentModel ;
2
3
using System . Drawing ; // for notifyicon
3
- using System . Linq ;
4
- using System . Threading . Tasks ;
4
+ using System . IO ;
5
5
using System . Windows ;
6
6
using System . Windows . Controls ;
7
+ using System . Windows . Data ;
7
8
using System . Windows . Input ;
8
9
using System . Windows . Shell ;
9
10
10
11
namespace UnityLauncherPro
11
12
{
12
- /// <summary>
13
- /// Interaction logic for MainWindow.xaml
14
- /// </summary>
15
13
public partial class MainWindow : Window
16
14
{
17
15
@@ -21,6 +19,8 @@ public partial class MainWindow : Window
21
19
Updates [ ] updatesSource ;
22
20
UnityInstallation [ ] unityInstallationsSource ;
23
21
22
+ string _filterString = null ;
23
+
24
24
public MainWindow ( )
25
25
{
26
26
InitializeComponent ( ) ;
@@ -29,9 +29,11 @@ public MainWindow()
29
29
30
30
void Start ( )
31
31
{
32
+ LoadSettings ( ) ;
33
+
32
34
// make window resizable (this didnt work when used pure xaml to do this)
33
35
WindowChrome Resizable_BorderLess_Chrome = new WindowChrome ( ) ;
34
- Resizable_BorderLess_Chrome . GlassFrameThickness = new Thickness ( 0 ) ;
36
+ // Resizable_BorderLess_Chrome.GlassFrameThickness = new Thickness(0);
35
37
Resizable_BorderLess_Chrome . CornerRadius = new CornerRadius ( 0 ) ;
36
38
Resizable_BorderLess_Chrome . CaptionHeight = 1.0 ;
37
39
WindowChrome . SetWindowChrome ( this , Resizable_BorderLess_Chrome ) ;
@@ -45,8 +47,8 @@ void Start()
45
47
46
48
//dataGrid.Items.Add(GetProjects.Scan());
47
49
projectsSource = GetProjects . Scan ( ) ;
48
- dataGrid . Items . Clear ( ) ;
49
- dataGrid . ItemsSource = projectsSource ;
50
+ gridRecent . Items . Clear ( ) ;
51
+ gridRecent . ItemsSource = projectsSource ;
50
52
51
53
// updates grid
52
54
dataGridUpdates . Items . Clear ( ) ;
@@ -93,6 +95,7 @@ private void OnRectangleMouseDown(object sender, MouseButtonEventArgs e)
93
95
private void OnSearchTextChanged ( object sender , TextChangedEventArgs e )
94
96
{
95
97
TextBox textbox = ( TextBox ) sender ;
98
+ FilterRecentProjects ( ) ;
96
99
//FilterProjects(textbox.Text);
97
100
}
98
101
@@ -102,13 +105,26 @@ private void OnSearchPreviewKeyDown(object sender, KeyEventArgs e)
102
105
{
103
106
case Key . Escape :
104
107
( ( TextBox ) sender ) . Text = "" ;
105
- //FilterProjects(null);
106
108
break ;
107
109
default :
108
110
break ;
109
111
}
110
112
}
111
113
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
+
112
128
private void BtnAddProjectFolder_Click ( object sender , RoutedEventArgs e )
113
129
{
114
130
// https://stackoverflow.com/a/50261723/5452781
@@ -125,9 +141,9 @@ private void BtnAddProjectFolder_Click(object sender, RoutedEventArgs e)
125
141
path = path . Replace ( "\\ Project.Folder" , "" ) ;
126
142
path = path . Replace ( "Project.Folder" , "" ) ;
127
143
// If user has changed the filename, create the new directory
128
- if ( ! System . IO . Directory . Exists ( path ) )
144
+ if ( ! Directory . Exists ( path ) )
129
145
{
130
- System . IO . Directory . CreateDirectory ( path ) ;
146
+ Directory . CreateDirectory ( path ) ;
131
147
}
132
148
// Our final value is in path
133
149
Console . WriteLine ( path ) ;
@@ -142,7 +158,7 @@ private void BtnClose_Click(object sender, RoutedEventArgs e)
142
158
private void BtnMinimize_Click ( object sender , RoutedEventArgs e )
143
159
{
144
160
// remove focus from minimize button
145
- dataGrid . Focus ( ) ;
161
+ gridRecent . Focus ( ) ;
146
162
notifyIcon . Visible = true ;
147
163
this . Hide ( ) ;
148
164
}
@@ -188,13 +204,15 @@ private void OnWindowKeyDown(object sender, KeyEventArgs e)
188
204
}
189
205
break ;
190
206
default : // any key
207
+
191
208
// activate searchbar if not active and we are in tab#1
192
209
if ( tabControl . SelectedIndex == 0 && txtSearchBox . IsFocused == false )
193
210
{
194
211
// dont write tab key on search field
195
212
if ( e . Key == Key . Tab ) break ;
213
+
196
214
txtSearchBox . Focus ( ) ;
197
- txtSearchBox . Text += e . Key ;
215
+ // txtSearchBox.Text += e.Key;
198
216
txtSearchBox . Select ( txtSearchBox . Text . Length , 0 ) ;
199
217
}
200
218
break ;
@@ -233,5 +251,90 @@ private void OnClearUpdateSearchClick(object sender, RoutedEventArgs e)
233
251
{
234
252
txtSearchBoxUpdates . Text = "" ;
235
253
}
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
+ }
236
339
}
237
340
}
0 commit comments