@@ -20,7 +20,7 @@ public partial class MainWindow : Window
20
20
Updates [ ] updatesSource ;
21
21
UnityInstallation [ ] unityInstallationsSource ;
22
22
public static Dictionary < string , string > unityInstalledVersions = new Dictionary < string , string > ( ) ;
23
-
23
+ const string contextRegRoot = "Software \\ Classes \\ Directory \\ Background \\ shell" ;
24
24
string _filterString = null ;
25
25
26
26
public MainWindow ( )
@@ -47,18 +47,6 @@ void Start()
47
47
dataGridUnitys . Items . Clear ( ) ;
48
48
UpdateUnityInstallationsList ( ) ;
49
49
50
- // make dictionary of installed unitys, to search faster
51
- unityInstalledVersions . Clear ( ) ;
52
- for ( int i = 0 ; i < unityInstallationsSource . Length ; i ++ )
53
- {
54
- var version = unityInstallationsSource [ i ] . Version ;
55
- if ( unityInstalledVersions . ContainsKey ( version ) == false )
56
- {
57
- unityInstalledVersions . Add ( version , unityInstallationsSource [ i ] . Path ) ;
58
- }
59
- }
60
-
61
- //dataGrid.Items.Add(GetProjects.Scan());
62
50
projectsSource = GetProjects . Scan ( ) ;
63
51
gridRecent . Items . Clear ( ) ;
64
52
gridRecent . ItemsSource = projectsSource ;
@@ -99,9 +87,11 @@ void LoadSettings()
99
87
this . Width = Properties . Settings . Default . windowWidth ;
100
88
this . Height = Properties . Settings . Default . windowHeight ;
101
89
90
+ chkMinimizeToTaskbar . IsChecked = Properties . Settings . Default . minimizeToTaskbar ;
91
+ chkRegisterExplorerMenu . IsChecked = Properties . Settings . Default . registerExplorerMenu ;
92
+
102
93
/*
103
94
// update settings window
104
- chkMinimizeToTaskbar.Checked = Properties.Settings.Default.minimizeToTaskbar;
105
95
chkQuitAfterCommandline.Checked = Properties.Settings.Default.closeAfterExplorer;
106
96
ChkQuitAfterOpen.Checked = Properties.Settings.Default.closeAfterProject;
107
97
chkShowLauncherArgumentsColumn.Checked = Properties.Settings.Default.showArgumentsColumn;
@@ -170,6 +160,17 @@ void UpdateUnityInstallationsList()
170
160
{
171
161
unityInstallationsSource = GetUnityInstallations . Scan ( ) ;
172
162
dataGridUnitys . ItemsSource = unityInstallationsSource ;
163
+
164
+ // make dictionary of installed unitys, to search faster
165
+ unityInstalledVersions . Clear ( ) ;
166
+ for ( int i = 0 ; i < unityInstallationsSource . Length ; i ++ )
167
+ {
168
+ var version = unityInstallationsSource [ i ] . Version ;
169
+ if ( unityInstalledVersions . ContainsKey ( version ) == false )
170
+ {
171
+ unityInstalledVersions . Add ( version , unityInstallationsSource [ i ] . Path ) ;
172
+ }
173
+ }
173
174
}
174
175
175
176
Project GetSelectedProject ( )
@@ -182,14 +183,18 @@ UnityInstallation GetSelectedUnity()
182
183
return ( UnityInstallation ) dataGridUnitys . SelectedItem ;
183
184
}
184
185
186
+ Updates GetSelectedUpdate ( )
187
+ {
188
+ return ( Updates ) dataGridUpdates . SelectedItem ;
189
+ }
190
+
185
191
void AddUnityInstallationRootFolder ( )
186
192
{
187
193
var dialog = new System . Windows . Forms . FolderBrowserDialog ( ) ;
188
194
dialog . Description = "Select Unity installations root folder" ;
189
195
190
196
var result = dialog . ShowDialog ( ) ;
191
197
var newRoot = dialog . SelectedPath ;
192
- Console . WriteLine ( newRoot ) ;
193
198
if ( String . IsNullOrWhiteSpace ( newRoot ) == false && Directory . Exists ( newRoot ) == true )
194
199
{
195
200
Properties . Settings . Default . rootFolders . Add ( newRoot ) ;
@@ -202,12 +207,24 @@ void AddUnityInstallationRootFolder()
202
207
void SetFocusToGrid ( DataGrid targetGrid )
203
208
{
204
209
//e.Handled = true; // if enabled, we enter to first row initially
210
+ if ( targetGrid . Items . Count < 1 ) return ;
205
211
targetGrid . Focus ( ) ;
206
212
targetGrid . SelectedIndex = 0 ;
207
213
DataGridRow row = ( DataGridRow ) targetGrid . ItemContainerGenerator . ContainerFromIndex ( 0 ) ;
208
214
row . MoveFocus ( new TraversalRequest ( FocusNavigationDirection . Next ) ) ;
209
215
}
210
216
217
+ async void CallGetUnityUpdates ( )
218
+ {
219
+ dataGridUpdates . ItemsSource = null ;
220
+ var task = GetUnityUpdates . Scan ( ) ;
221
+ var items = await task ;
222
+ // TODO handle errors?
223
+ if ( items == null ) return ;
224
+ updatesSource = GetUnityUpdates . Parse ( items ) ;
225
+ if ( updatesSource == null ) return ;
226
+ dataGridUpdates . ItemsSource = updatesSource ;
227
+ }
211
228
212
229
//
213
230
//
@@ -297,22 +314,23 @@ private void BtnMinimize_Click(object sender, RoutedEventArgs e)
297
314
{
298
315
// remove focus from minimize button
299
316
gridRecent . Focus ( ) ;
300
- notifyIcon . Visible = true ;
301
- this . Hide ( ) ;
317
+ if ( chkMinimizeToTaskbar . IsChecked == true )
318
+ {
319
+ notifyIcon . Visible = true ;
320
+ this . Hide ( ) ;
321
+ }
322
+ else
323
+ {
324
+ this . WindowState = WindowState . Minimized ;
325
+ }
302
326
}
303
327
304
328
private async void OnGetUnityUpdatesClick ( object sender , RoutedEventArgs e )
305
329
{
306
330
var button = ( Button ) sender ;
307
331
button . IsEnabled = false ;
308
332
309
- var task = GetUnityUpdates . Scan ( ) ;
310
- var items = await task ;
311
- // TODO handle errors?
312
- if ( items == null ) return ;
313
- updatesSource = GetUnityUpdates . Parse ( items ) ;
314
- if ( updatesSource == null ) return ;
315
- dataGridUpdates . ItemsSource = updatesSource ;
333
+ CallGetUnityUpdates ( ) ;
316
334
317
335
button . IsEnabled = true ;
318
336
}
@@ -321,33 +339,63 @@ private void OnWindowKeyDown(object sender, KeyEventArgs e)
321
339
{
322
340
// TODO if editing cells, dont focus on search
323
341
//if (gridRecent.IsCurrentCellInEditMode == true) return;
324
- switch ( e . Key )
342
+
343
+ switch ( tabControl . SelectedIndex )
325
344
{
326
- case Key . Escape : // clear project search
327
- if ( tabControl . SelectedIndex == 0 && txtSearchBox . Text != "" )
345
+ case 0 : // Projects
346
+
347
+ switch ( e . Key )
328
348
{
329
- txtSearchBox . Text = "" ;
349
+ case Key . F5 : // refresh projects
350
+ projectsSource = GetProjects . Scan ( ) ;
351
+ gridRecent . ItemsSource = projectsSource ;
352
+ break ;
353
+ case Key . Escape : // clear project search
354
+ txtSearchBox . Text = "" ;
355
+ break ;
356
+ default : // any key
357
+ // activate searchbar if not active and we are in tab#1
358
+ if ( txtSearchBox . IsFocused == false )
359
+ {
360
+ txtSearchBox . Focus ( ) ;
361
+ txtSearchBox . Select ( txtSearchBox . Text . Length , 0 ) ;
362
+ }
363
+ break ;
330
364
}
331
- // clear updates search
332
- else if ( tabControl . SelectedIndex == 2 && txtSearchBoxUpdates . Text != "" )
365
+
366
+ break ;
367
+ case 1 : // Unitys
368
+
369
+ switch ( e . Key )
333
370
{
334
- txtSearchBoxUpdates . Text = "" ;
371
+ case Key . F5 : // refresh unitys
372
+ UpdateUnityInstallationsList ( ) ; break ;
373
+ case Key . Escape : // clear project search
374
+ txtSearchBoxUnity . Text = "" ;
375
+ break ;
376
+ default : // any key
377
+ break ;
335
378
}
336
379
break ;
337
- case Key . Up :
338
- break ;
339
- case Key . Down :
340
- break ;
341
- default : // any key
342
380
343
- // activate searchbar if not active and we are in tab#1
344
- if ( tabControl . SelectedIndex == 0 && txtSearchBox . IsFocused == false )
381
+ case 2 : // Updates
382
+
383
+ switch ( e . Key )
345
384
{
346
- txtSearchBox . Focus ( ) ;
347
- txtSearchBox . Select ( txtSearchBox . Text . Length , 0 ) ;
385
+ case Key . F5 : // refresh unitys
386
+ CallGetUnityUpdates ( ) ;
387
+ break ;
388
+ case Key . Escape : // clear project search
389
+ txtSearchBoxUpdates . Text = "" ;
390
+ break ;
391
+ default : // any key
392
+ break ;
348
393
}
349
394
break ;
395
+ default :
396
+ break ;
350
397
}
398
+
351
399
}
352
400
353
401
private async void OnTabSelectionChanged ( object sender , SelectionChangedEventArgs e )
@@ -412,8 +460,22 @@ private void BtnExplore_Click(object sender, RoutedEventArgs e)
412
460
// copy selected row unity version to clipboard
413
461
private void MenuItemCopyVersion_Click ( object sender , RoutedEventArgs e )
414
462
{
415
- var proj = GetSelectedProject ( ) ;
416
- Clipboard . SetText ( proj ? . Version ) ;
463
+ string copy = null ;
464
+ if ( tabControl . SelectedIndex == 0 )
465
+ {
466
+ var proj = GetSelectedProject ( ) ;
467
+ copy = proj ? . Version ;
468
+ }
469
+ else if ( tabControl . SelectedIndex == 1 )
470
+ {
471
+ var unity = GetSelectedUnity ( ) ;
472
+ copy = unity ? . Version ;
473
+ }
474
+ else if ( tabControl . SelectedIndex == 2 )
475
+ {
476
+ //var update = getselect
477
+ }
478
+ if ( copy != null ) Clipboard . SetText ( copy ) ;
417
479
}
418
480
419
481
private void BtnRefreshProjectList_Click ( object sender , RoutedEventArgs e )
@@ -518,10 +580,20 @@ private void BtnRemoveInstallationFolder_Click(object sender, RoutedEventArgs e)
518
580
// need to manually move into next/prev rows? https://stackoverflow.com/a/11652175/5452781
519
581
private void GridRecent_PreviewKeyDown ( object sender , KeyEventArgs e )
520
582
{
521
- if ( e . Key == Key . Return )
583
+ switch ( e . Key )
522
584
{
523
- e . Handled = true ;
524
- Tools . LaunchProject ( GetSelectedProject ( ) ) ;
585
+ case Key . Tab :
586
+ if ( ( Keyboard . Modifiers & ModifierKeys . Control ) == ModifierKeys . Control )
587
+ {
588
+ e . Handled = true ;
589
+ }
590
+ break ;
591
+ case Key . Return :
592
+ e . Handled = true ;
593
+ Tools . LaunchProject ( GetSelectedProject ( ) ) ;
594
+ break ;
595
+ default :
596
+ break ;
525
597
}
526
598
}
527
599
@@ -610,6 +682,52 @@ private void BtnAdbBindWifi_Click(object sender, RoutedEventArgs e)
610
682
//// connect device (use your device ip address)
611
683
//adb connect IP_HERE:5555
612
684
}
685
+
686
+ private void BtnRefreshUnityList_Click ( object sender , RoutedEventArgs e )
687
+ {
688
+ UpdateUnityInstallationsList ( ) ;
689
+ }
690
+
691
+ private void BtnDonwloadInBrowser_Click ( object sender , RoutedEventArgs e )
692
+ {
693
+ var unity = GetSelectedUpdate ( ) ;
694
+ string url = Tools . GetUnityReleaseURL ( unity ? . Version ) ;
695
+ if ( string . IsNullOrEmpty ( url ) == false )
696
+ {
697
+ Tools . DownloadInBrowser ( url , unity . Version ) ;
698
+ }
699
+ else
700
+ {
701
+ Console . WriteLine ( "Failed getting Unity Installer URL for " + unity . Version ) ;
702
+ }
703
+ }
704
+
705
+ private void BtnOpenWebsite_Click ( object sender , RoutedEventArgs e )
706
+ {
707
+ var unity = GetSelectedUpdate ( ) ;
708
+ Tools . OpenReleaseNotes ( unity ? . Version ) ;
709
+ }
710
+
711
+ private void ChkMinimizeToTaskbar_CheckedChanged ( object sender , RoutedEventArgs e )
712
+ {
713
+ Properties . Settings . Default . minimizeToTaskbar = ( bool ) chkMinimizeToTaskbar . IsChecked ;
714
+ Properties . Settings . Default . Save ( ) ;
715
+ }
716
+
717
+ private void ChkRegisterExplorerMenu_CheckedChanged ( object sender , RoutedEventArgs e )
718
+ {
719
+ if ( ( bool ) chkRegisterExplorerMenu . IsChecked )
720
+ {
721
+ Tools . AddContextMenuRegistry ( contextRegRoot ) ;
722
+ }
723
+ else // remove
724
+ {
725
+ Tools . RemoveContextMenuRegistry ( contextRegRoot ) ;
726
+ }
727
+
728
+ Properties . Settings . Default . registerExplorerMenu = ( bool ) chkRegisterExplorerMenu . IsChecked ;
729
+ Properties . Settings . Default . Save ( ) ;
730
+ }
613
731
} // class
614
732
} //namespace
615
733
0 commit comments