@@ -18,12 +18,13 @@ namespace Files.App.Controls
1818 [ TemplatePart ( Name = "PART_ModesHostGrid" , Type = typeof ( Grid ) ) ]
1919 // Visual states
2020 [ TemplateVisualState ( Name = "Focused" , GroupName = "FocusStates" ) ]
21- [ TemplateVisualState ( Name = "Unfocused " , GroupName = "FocusStates" ) ]
21+ [ TemplateVisualState ( Name = "Normal " , GroupName = "FocusStates" ) ]
2222 public partial class Omnibar : Control
2323 {
2424 private const string ModesHostGrid = "PART_ModesHostGrid" ;
2525
2626 private Grid ? _modesHostGrid ;
27+ private bool _wasAscendantFocused ;
2728 private bool _isFocused ;
2829
2930 public Omnibar ( )
@@ -64,13 +65,12 @@ protected override void OnApplyTemplate()
6465 _modesHostGrid . ColumnDefinitions . Add ( new ( ) { Width = GridLength . Auto } ) ;
6566 Grid . SetColumn ( mode , _modesHostGrid . Children . Count ) ;
6667 _modesHostGrid . Children . Add ( mode ) ;
67- mode . Host = _modesHostGrid ;
68+ mode . Host = this ;
6869 }
6970
7071 var parentElement = this . FindAscendant < FrameworkElement > ( ) ! ;
71- parentElement . GettingFocus += ParentElement_GettingFocus ;
72- parentElement . GotFocus += ParentElement_GotFocus ;
73- GettingFocus += Omnibar_GettingFocus ;
72+ parentElement . PointerPressed += ParentElement_PointerPressed ;
73+
7474 GotFocus += Omnibar_GotFocus ;
7575 LostFocus += Omnibar_LostFocus ;
7676
@@ -79,7 +79,23 @@ protected override void OnApplyTemplate()
7979 base . OnApplyTemplate ( ) ;
8080 }
8181
82- // Private methods
82+ // Methods
83+
84+ internal void ChangeExpandedMode ( OmnibarMode modeToExpand )
85+ {
86+ if ( _modesHostGrid is null || Modes is null )
87+ throw new NullReferenceException ( ) ;
88+
89+ // Reset
90+ foreach ( var column in _modesHostGrid . ColumnDefinitions )
91+ column . Width = GridLength . Auto ;
92+ foreach ( var mode in Modes )
93+ VisualStateManager . GoToState ( mode , "Collapsed" , true ) ;
94+
95+ // Expand the given mode
96+ VisualStateManager . GoToState ( modeToExpand , "Visible" , true ) ;
97+ _modesHostGrid . ColumnDefinitions [ _modesHostGrid . Children . IndexOf ( modeToExpand ) ] . Width = new ( 1 , GridUnitType . Star ) ;
98+ }
8399
84100 private void UpdateVisualStates ( )
85101 {
@@ -91,27 +107,35 @@ private void UpdateVisualStates()
91107
92108 // Events
93109
94- private void Omnibar_GettingFocus ( UIElement sender , GettingFocusEventArgs args )
110+ private void ParentElement_PointerPressed ( object sender , PointerRoutedEventArgs e )
95111 {
96- }
112+ // Lost focus
113+ if ( _isFocused )
114+ {
115+ _isFocused = _wasAscendantFocused = false ;
116+ UpdateVisualStates ( ) ;
97117
98- private void ParentElement_GettingFocus ( UIElement sender , GettingFocusEventArgs args )
99- {
100- }
118+ return ;
119+ }
101120
102- private void ParentElement_GotFocus ( object sender , RoutedEventArgs e )
103- {
121+ _wasAscendantFocused = true ;
104122 }
105123
106124 private void Omnibar_GotFocus ( object sender , RoutedEventArgs e )
107125 {
126+ if ( _wasAscendantFocused )
127+ {
128+ _isFocused = _wasAscendantFocused = false ;
129+ return ;
130+ }
131+
108132 _isFocused = true ;
109133 UpdateVisualStates ( ) ;
110134 }
111135
112136 private void Omnibar_LostFocus ( object sender , RoutedEventArgs e )
113137 {
114- _isFocused = false ;
138+ _isFocused = _wasAscendantFocused = false ;
115139 UpdateVisualStates ( ) ;
116140 }
117141 }
0 commit comments