@@ -20,7 +20,7 @@ public partial class MainWindow : Window
2020 Updates [ ] updatesSource ;
2121 UnityInstallation [ ] unityInstallationsSource ;
2222 public static Dictionary < string , string > unityInstalledVersions = new Dictionary < string , string > ( ) ;
23-
23+ const string contextRegRoot = "Software \\ Classes \\ Directory \\ Background \\ shell" ;
2424 string _filterString = null ;
2525
2626 public MainWindow ( )
@@ -47,18 +47,6 @@ void Start()
4747 dataGridUnitys . Items . Clear ( ) ;
4848 UpdateUnityInstallationsList ( ) ;
4949
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());
6250 projectsSource = GetProjects . Scan ( ) ;
6351 gridRecent . Items . Clear ( ) ;
6452 gridRecent . ItemsSource = projectsSource ;
@@ -99,9 +87,11 @@ void LoadSettings()
9987 this . Width = Properties . Settings . Default . windowWidth ;
10088 this . Height = Properties . Settings . Default . windowHeight ;
10189
90+ chkMinimizeToTaskbar . IsChecked = Properties . Settings . Default . minimizeToTaskbar ;
91+ chkRegisterExplorerMenu . IsChecked = Properties . Settings . Default . registerExplorerMenu ;
92+
10293 /*
10394 // update settings window
104- chkMinimizeToTaskbar.Checked = Properties.Settings.Default.minimizeToTaskbar;
10595 chkQuitAfterCommandline.Checked = Properties.Settings.Default.closeAfterExplorer;
10696 ChkQuitAfterOpen.Checked = Properties.Settings.Default.closeAfterProject;
10797 chkShowLauncherArgumentsColumn.Checked = Properties.Settings.Default.showArgumentsColumn;
@@ -170,6 +160,17 @@ void UpdateUnityInstallationsList()
170160 {
171161 unityInstallationsSource = GetUnityInstallations . Scan ( ) ;
172162 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+ }
173174 }
174175
175176 Project GetSelectedProject ( )
@@ -182,14 +183,18 @@ UnityInstallation GetSelectedUnity()
182183 return ( UnityInstallation ) dataGridUnitys . SelectedItem ;
183184 }
184185
186+ Updates GetSelectedUpdate ( )
187+ {
188+ return ( Updates ) dataGridUpdates . SelectedItem ;
189+ }
190+
185191 void AddUnityInstallationRootFolder ( )
186192 {
187193 var dialog = new System . Windows . Forms . FolderBrowserDialog ( ) ;
188194 dialog . Description = "Select Unity installations root folder" ;
189195
190196 var result = dialog . ShowDialog ( ) ;
191197 var newRoot = dialog . SelectedPath ;
192- Console . WriteLine ( newRoot ) ;
193198 if ( String . IsNullOrWhiteSpace ( newRoot ) == false && Directory . Exists ( newRoot ) == true )
194199 {
195200 Properties . Settings . Default . rootFolders . Add ( newRoot ) ;
@@ -202,12 +207,24 @@ void AddUnityInstallationRootFolder()
202207 void SetFocusToGrid ( DataGrid targetGrid )
203208 {
204209 //e.Handled = true; // if enabled, we enter to first row initially
210+ if ( targetGrid . Items . Count < 1 ) return ;
205211 targetGrid . Focus ( ) ;
206212 targetGrid . SelectedIndex = 0 ;
207213 DataGridRow row = ( DataGridRow ) targetGrid . ItemContainerGenerator . ContainerFromIndex ( 0 ) ;
208214 row . MoveFocus ( new TraversalRequest ( FocusNavigationDirection . Next ) ) ;
209215 }
210216
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+ }
211228
212229 //
213230 //
@@ -297,22 +314,23 @@ private void BtnMinimize_Click(object sender, RoutedEventArgs e)
297314 {
298315 // remove focus from minimize button
299316 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+ }
302326 }
303327
304328 private async void OnGetUnityUpdatesClick ( object sender , RoutedEventArgs e )
305329 {
306330 var button = ( Button ) sender ;
307331 button . IsEnabled = false ;
308332
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 ( ) ;
316334
317335 button . IsEnabled = true ;
318336 }
@@ -321,33 +339,63 @@ private void OnWindowKeyDown(object sender, KeyEventArgs e)
321339 {
322340 // TODO if editing cells, dont focus on search
323341 //if (gridRecent.IsCurrentCellInEditMode == true) return;
324- switch ( e . Key )
342+
343+ switch ( tabControl . SelectedIndex )
325344 {
326- case Key . Escape : // clear project search
327- if ( tabControl . SelectedIndex == 0 && txtSearchBox . Text != "" )
345+ case 0 : // Projects
346+
347+ switch ( e . Key )
328348 {
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 ;
330364 }
331- // clear updates search
332- else if ( tabControl . SelectedIndex == 2 && txtSearchBoxUpdates . Text != "" )
365+
366+ break ;
367+ case 1 : // Unitys
368+
369+ switch ( e . Key )
333370 {
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 ;
335378 }
336379 break ;
337- case Key . Up :
338- break ;
339- case Key . Down :
340- break ;
341- default : // any key
342380
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 )
345384 {
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 ;
348393 }
349394 break ;
395+ default :
396+ break ;
350397 }
398+
351399 }
352400
353401 private async void OnTabSelectionChanged ( object sender , SelectionChangedEventArgs e )
@@ -412,8 +460,22 @@ private void BtnExplore_Click(object sender, RoutedEventArgs e)
412460 // copy selected row unity version to clipboard
413461 private void MenuItemCopyVersion_Click ( object sender , RoutedEventArgs e )
414462 {
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 ) ;
417479 }
418480
419481 private void BtnRefreshProjectList_Click ( object sender , RoutedEventArgs e )
@@ -518,10 +580,20 @@ private void BtnRemoveInstallationFolder_Click(object sender, RoutedEventArgs e)
518580 // need to manually move into next/prev rows? https://stackoverflow.com/a/11652175/5452781
519581 private void GridRecent_PreviewKeyDown ( object sender , KeyEventArgs e )
520582 {
521- if ( e . Key == Key . Return )
583+ switch ( e . Key )
522584 {
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 ;
525597 }
526598 }
527599
@@ -610,6 +682,52 @@ private void BtnAdbBindWifi_Click(object sender, RoutedEventArgs e)
610682 //// connect device (use your device ip address)
611683 //adb connect IP_HERE:5555
612684 }
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+ }
613731 } // class
614732} //namespace
615733
0 commit comments