11using System ;
2+ using System . ComponentModel ;
23using System . Drawing ; // for notifyicon
3- using System . Linq ;
4- using System . Threading . Tasks ;
4+ using System . IO ;
55using System . Windows ;
66using System . Windows . Controls ;
7+ using System . Windows . Data ;
78using System . Windows . Input ;
89using System . Windows . Shell ;
910
1011namespace 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}
0 commit comments