88 using UnityEngine ;
99 using Util ;
1010
11+ internal enum DropdownWindowType { Dropdown , Popup }
12+
1113 /// <summary>Creates a dropdown window that shows the <see cref="SelectionTree"/> elements.</summary>
1214 internal class DropdownWindow : EditorWindow
1315 {
@@ -19,12 +21,10 @@ internal class DropdownWindow : EditorWindow
1921 private Rect _positionOnCreation ;
2022 private bool _positionWasSetAfterCreation ;
2123
22- public event Action OnClose ;
23-
24- public static DropdownWindow Create ( SelectionTree selectionTree , int windowHeight , Vector2 windowPosition )
24+ public static DropdownWindow Create ( SelectionTree selectionTree , int windowHeight , Vector2 windowPosition , DropdownWindowType windowType )
2525 {
2626 var window = CreateInstance < DropdownWindow > ( ) ;
27- window . OnCreate ( selectionTree , windowHeight , windowPosition ) ;
27+ window . OnCreate ( selectionTree , windowHeight , windowPosition , windowType ) ;
2828 return window ;
2929 }
3030
@@ -35,7 +35,7 @@ public static DropdownWindow Create(SelectionTree selectionTree, int windowHeigh
3535 /// <param name="selectionTree">Tree that contains the dropdown items to show.</param>
3636 /// <param name="windowHeight">Height of the window. If set to 0, it will be auto-adjusted.</param>
3737 /// <param name="windowPosition">Position of the window to set.</param>
38- private void OnCreate ( SelectionTree selectionTree , float windowHeight , Vector2 windowPosition )
38+ private void OnCreate ( SelectionTree selectionTree , float windowHeight , Vector2 windowPosition , DropdownWindowType windowType )
3939 {
4040 ResetControl ( ) ;
4141 wantsMouseMove = true ;
@@ -46,11 +46,22 @@ private void OnCreate(SelectionTree selectionTree, float windowHeight, Vector2 w
4646
4747 _positionOnCreation = GetWindowRect ( windowPosition , windowHeight ) ;
4848
49- // ShowAsDropDown usually shows the window under a button, but since we don't need to align the window to
50- // any button, we set buttonRect.height to 0f.
51- Rect buttonRect = new Rect ( _positionOnCreation ) { height = 0f } ;
52-
53- ShowAsDropDown ( buttonRect , _positionOnCreation . size ) ;
49+ if ( windowType == DropdownWindowType . Dropdown )
50+ {
51+ // ShowAsDropDown usually shows the window under a button, but since we don't need to align the window to
52+ // any button, we set buttonRect.height to 0f.
53+ Rect buttonRect = new Rect ( _positionOnCreation ) { height = 0f } ;
54+ ShowAsDropDown ( buttonRect , _positionOnCreation . size ) ;
55+ }
56+ else if ( windowType == DropdownWindowType . Popup )
57+ {
58+ position = _positionOnCreation ;
59+ ShowPopup ( ) ;
60+ }
61+ else
62+ {
63+ throw new Exception ( "Unknown window type" ) ;
64+ }
5465 }
5566
5667 public static float CalculateOptimalWidth ( string [ ] selectionPaths )
@@ -123,7 +134,7 @@ private void Update()
123134 AdjustSizeIfNeeded ( ) ;
124135 }
125136
126- private void OnDestroy ( ) => OnClose ? . Invoke ( ) ;
137+ private void OnLostFocus ( ) => Close ( ) ;
127138
128139 private void AdjustSizeIfNeeded ( )
129140 {
0 commit comments