@@ -16,21 +16,15 @@ class MainWindow : Window
16
16
const string InstallUnityUrl = "https://unity.com/releases/editor/archive" ;
17
17
18
18
public static MainWindow Instance { get ; set ; }
19
+
19
20
static ListBox s_unityInstallationsParent ;
20
21
21
22
static ListBox s_unityInstalltionSearchPathsParent ;
22
23
static Button s_unityInstallationSearchRemoveBtn ;
23
24
24
25
static SubmitableListBox s_unityProjectsParent ;
25
- static Button s_revealBtn ;
26
- static Button s_removeFromListBtn ;
27
- static Button s_openWithBtn ;
28
26
static AutoCompleteBox s_projectSearchBoxAutoComplete ;
29
27
30
- static MenuItem s_removeFromListMenuItem ;
31
- static MenuItem s_revealInFileExplorerMenuItem ;
32
- static MenuItem s_openInDifferentVersionMenuItem ;
33
-
34
28
static DockPanel s_transparentPanel ;
35
29
static Slider s_backgroundBlurIntensitySlider ;
36
30
@@ -94,10 +88,13 @@ public static void ReloadEverything()
94
88
UpdateUnityProjectViews ( ) ;
95
89
}
96
90
97
- public static void OnOpenWithClicked ( )
91
+ public static void OpenSelectedProjectWith ( )
98
92
{
99
- var dialogue = new OpenWithDialogue ( UnityHubUtils . UnityProjects [ GetUnityProjectSelectedIndex ( ) ] ) ;
100
- dialogue . ShowDialog ( Instance ) ;
93
+ if ( TryGetSelectedProject ( out var unityProject ) )
94
+ {
95
+ var dialogue = new OpenWithDialogue ( unityProject ) ;
96
+ dialogue . ShowDialog ( Instance ) ;
97
+ }
101
98
}
102
99
103
100
public static void OnRemoveProjectFromListClicked ( )
@@ -132,9 +129,9 @@ public static void UpdateUnityProjectViews()
132
129
( ( UnityProjectView ) s_unityProjectsParent . Items [ i ] ! ) . Update ( UnityHubUtils . UnityProjects [ i ] ) ;
133
130
}
134
131
135
- public static void MoveUnityProjectUp ( UnityProject unityProject )
132
+ public static void MoveSelectedProjectUp ( )
136
133
{
137
- if ( unityProject is null )
134
+ if ( ! TryGetSelectedProject ( out var unityProject ) || unityProject is null )
138
135
return ;
139
136
var ind = UnityHubUtils . UnityProjects . IndexOf ( unityProject ) ;
140
137
if ( ind == - 1 )
@@ -150,9 +147,9 @@ public static void MoveUnityProjectUp(UnityProject unityProject)
150
147
( ( UnityProjectView ) s_unityProjectsParent . Items [ ind + 1 ] ) . Update ( UnityHubUtils . UnityProjects [ ind + 1 ] ) ;
151
148
}
152
149
153
- public static void MoveUnityProjectDown ( UnityProject unityProject )
150
+ public static void MoveSelectedProjectDown ( )
154
151
{
155
- if ( unityProject is null )
152
+ if ( ! TryGetSelectedProject ( out var unityProject ) || unityProject is null )
156
153
return ;
157
154
var ind = UnityHubUtils . UnityProjects . IndexOf ( unityProject ) ;
158
155
if ( ind == - 1 )
@@ -181,7 +178,7 @@ public static void MoveUnityProjectDown(UnityProject unityProject)
181
178
( [
182
179
new MenuItem
183
180
{
184
- Header = "_Project "
181
+ Header = "_File "
185
182
} . AddItems
186
183
( [
187
184
new MenuItem
@@ -196,25 +193,6 @@ public static void MoveUnityProjectDown(UnityProject unityProject)
196
193
HotKey = new KeyGesture ( Key . N , KeyModifiers . Control | KeyModifiers . Shift ) ,
197
194
InputGesture = new KeyGesture ( Key . N , KeyModifiers . Control | KeyModifiers . Shift )
198
195
} . OnClick ( OnAddExistingProjectClicked ) ,
199
- s_removeFromListMenuItem = new MenuItem
200
- {
201
- Header = "_Remove From List" ,
202
- HotKey = new KeyGesture ( Key . Subtract , KeyModifiers . Control ) ,
203
- InputGesture = new KeyGesture ( Key . Subtract , KeyModifiers . Control )
204
- } . OnClick ( OnRemoveProjectFromListClicked ) ,
205
- new Separator ( ) ,
206
- s_revealInFileExplorerMenuItem = new MenuItem
207
- {
208
- Header = "_Reveal In File Explorer" ,
209
- HotKey = new KeyGesture ( Key . F , KeyModifiers . Control ) ,
210
- InputGesture = new KeyGesture ( Key . F , KeyModifiers . Control ) ,
211
- } . OnClick ( OnRevealProjectClicked ) ,
212
- s_openInDifferentVersionMenuItem = new MenuItem
213
- {
214
- Header = "_Open In Different Version" ,
215
- HotKey = new KeyGesture ( Key . O , KeyModifiers . Control ) ,
216
- InputGesture = new KeyGesture ( Key . O , KeyModifiers . Control ) ,
217
- } . OnClick ( OnOpenWithClicked ) ,
218
196
new MenuItem
219
197
{
220
198
Header = "_Reload Data" ,
@@ -223,6 +201,11 @@ public static void MoveUnityProjectDown(UnityProject unityProject)
223
201
} . OnClick ( ReloadEverything ) ,
224
202
] ) ,
225
203
new MenuItem
204
+ {
205
+ Header = "_Project" ,
206
+ } . AddItems
207
+ ( CreateProjectMenuItems ( ( ) => ( s_unityProjectsParent . SelectedItem as UnityProjectView ) ? . unityProject ?? null ) ) ,
208
+ new MenuItem
226
209
{
227
210
Header = "_Window" ,
228
211
} . AddItems
@@ -271,37 +254,6 @@ public static void MoveUnityProjectDown(UnityProject unityProject)
271
254
u . unityProject . OpenProject ( ) ;
272
255
return ;
273
256
} ) . SetDock ( Dock . Top ) ,
274
- new StackPanel
275
- {
276
- Orientation = Orientation . Horizontal ,
277
- Margin = new ( 0 , 5 ) ,
278
- Spacing = 2 ,
279
- } . SetDock ( Dock . Top ) . AddChildren
280
- ( [
281
- s_revealBtn = new Button
282
- {
283
- Content = "Reveal" ,
284
- IsEnabled = false ,
285
- } . OnClick ( OnRevealProjectClicked ) ,
286
- s_removeFromListBtn = new Button
287
- {
288
- Content = "Remove From List" ,
289
- IsEnabled = false ,
290
- } . OnClick ( OnRemoveProjectFromListClicked ) ,
291
- new Button
292
- {
293
- Content = "Create New"
294
- } . OnClick ( OnCreateNewProjectClicked ) ,
295
- new Button
296
- {
297
- Content = "Add Existing"
298
- } . OnClick ( OnAddExistingProjectClicked ) ,
299
- s_openWithBtn = new Button
300
- {
301
- Content = "Open With" ,
302
- IsEnabled = false ,
303
- } . OnClick ( OnOpenWithClicked ) ,
304
- ] ) ,
305
257
new DockPanel
306
258
{
307
259
Margin = new ( 0 , 10 )
@@ -531,6 +483,52 @@ public static void MoveUnityProjectDown(UnityProject unityProject)
531
483
] )
532
484
] ) ;
533
485
486
+ public static MenuItem [ ] CreateProjectMenuItems ( Func < UnityProject > unityProjectGetter )
487
+ {
488
+ return
489
+ [
490
+ new MenuItem
491
+ {
492
+ Header = "Open" ,
493
+ HotKey = new ( Key . Enter ) ,
494
+ InputGesture = new ( Key . Enter ) ,
495
+ } . OnLayoutUpdate ( ( item ) => item . IsEnabled = unityProjectGetter ( ) ? . unity . HasValue == true )
496
+ . OnClick ( OpenSelectedProject ) ,
497
+ new MenuItem
498
+ {
499
+ Header = "Open With" ,
500
+ HotKey = new ( Key . Enter , KeyModifiers . Alt ) ,
501
+ InputGesture = new ( Key . Enter , KeyModifiers . Alt ) ,
502
+ } . OnClick ( OpenSelectedProjectWith ) ,
503
+ new MenuItem
504
+ {
505
+ Header = "_Reveal In File Explorer" ,
506
+ HotKey = new KeyGesture ( Key . F , KeyModifiers . Control ) ,
507
+ InputGesture = new KeyGesture ( Key . F , KeyModifiers . Control ) ,
508
+ } . OnClick ( RevealSelectedProject ) ,
509
+ new MenuItem
510
+ {
511
+ Header = "Move Up In List" ,
512
+ HotKey = new ( Key . Up , KeyModifiers . Alt | KeyModifiers . Shift ) ,
513
+ InputGesture = new ( Key . Up , KeyModifiers . Alt | KeyModifiers . Shift ) ,
514
+ } . OnLayoutUpdate ( ( item ) => item . IsEnabled = unityProjectGetter is not null && UnityHubUtils . UnityProjects . Skip ( 1 ) . Contains ( unityProjectGetter ( ) ) )
515
+ . OnClick ( MoveSelectedProjectUp ) ,
516
+ new MenuItem
517
+ {
518
+ Header = "Move Down In List" ,
519
+ HotKey = new ( Key . Down , KeyModifiers . Alt | KeyModifiers . Shift ) ,
520
+ InputGesture = new ( Key . Down , KeyModifiers . Alt | KeyModifiers . Shift ) ,
521
+ } . OnLayoutUpdate ( ( item ) => item . IsEnabled = unityProjectGetter is not null && UnityHubUtils . UnityProjects . SkipLast ( 1 ) . Contains ( unityProjectGetter ( ) ) )
522
+ . OnClick ( MoveSelectedProjectDown ) ,
523
+ ] ;
524
+ }
525
+
526
+ static void OpenSelectedProject ( )
527
+ {
528
+ if ( s_unityProjectsParent . SelectedItem is UnityProjectView view )
529
+ view . OpenProject ( ) ;
530
+ }
531
+
534
532
static void OnCloseAfterOpenProjectCheckboxChanged ( )
535
533
{
536
534
UnityHubNativeNetApp . Config . closeAfterProjectOpen = ! UnityHubNativeNetApp . Config . closeAfterProjectOpen ;
@@ -613,12 +611,6 @@ static void UnityProjectSelectedIndexChanged()
613
611
var index = GetUnityProjectSelectedIndex ( ) ;
614
612
Debug . WriteLine ( $ "selection changed to { index } ") ;
615
613
bool isAnySelected = IsAnyProjectSelected ( ) ;
616
-
617
- // menu bar buttons
618
- s_revealBtn . IsEnabled = s_removeFromListBtn . IsEnabled = s_openWithBtn . IsEnabled = isAnySelected ;
619
-
620
- // menu items
621
- s_removeFromListMenuItem . IsEnabled = s_revealInFileExplorerMenuItem . IsEnabled = s_openInDifferentVersionMenuItem . IsEnabled = isAnySelected ;
622
614
}
623
615
624
616
static async void AddNewUnitySearchPath ( )
@@ -661,6 +653,18 @@ static async void AddNewUnitySearchPath()
661
653
662
654
static int GetUnityProjectSelectedIndex ( ) => s_unityProjectsParent . SelectedIndex ;
663
655
656
+ static bool TryGetSelectedProject ( out UnityProject unityProject )
657
+ {
658
+ var ind = GetUnityProjectSelectedIndex ( ) ;
659
+ if ( ind < 0 || ind >= UnityHubUtils . UnityProjects . Count )
660
+ {
661
+ unityProject = default ;
662
+ return false ;
663
+ }
664
+ unityProject = UnityHubUtils . UnityProjects [ ind ] ;
665
+ return true ;
666
+ }
667
+
664
668
static bool IsAnyProjectSelected ( )
665
669
{
666
670
var ind = GetUnityProjectSelectedIndex ( ) ;
@@ -711,7 +715,11 @@ static async void OnAddExistingProjectClicked()
711
715
712
716
static void OnCreateNewProjectClicked ( ) => new CreateNewProjectDialogue ( ) . ShowDialog ( Instance ) ;
713
717
714
- static void OnRevealProjectClicked ( ) => OsUtils . OpenExplorer ( UnityHubUtils . UnityProjects [ GetUnityProjectSelectedIndex ( ) ] . path ) ;
718
+ static void RevealSelectedProject ( )
719
+ {
720
+ if ( TryGetSelectedProject ( out var unityProject ) )
721
+ OsUtils . OpenExplorer ( unityProject . path ) ;
722
+ }
715
723
716
724
static void OnAboutClicked ( MenuItem item , RoutedEventArgs args ) => new AboutDialogue ( ) . ShowDialog ( Instance ) ;
717
725
0 commit comments