Skip to content

Commit b435c9e

Browse files
committed
Improved the popup visibility management
1 parent bdf0973 commit b435c9e

File tree

5 files changed

+46
-26
lines changed

5 files changed

+46
-26
lines changed

src/Files.App.Controls/Omnibar/Omnibar.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ protected override void OnApplyTemplate()
8282
// mode.ContentOnInactive = DefaultInactiveMode;
8383
}
8484

85-
_modesHostGrid.SizeChanged += _modesHostGrid_SizeChanged;
85+
_modesHostGrid.SizeChanged += ModesHostGrid_SizeChanged;
8686

8787
GotFocus += Omnibar_GotFocus;
8888
LostFocus += Omnibar_LostFocus;
@@ -94,7 +94,7 @@ protected override void OnApplyTemplate()
9494

9595
// Methods
9696

97-
internal void ChangeExpandedMode(OmnibarMode modeToExpand)
97+
internal void ChangeMode(OmnibarMode modeToExpand)
9898
{
9999
if (_modesHostGrid is null || Modes is null)
100100
throw new NullReferenceException();
@@ -103,15 +103,15 @@ internal void ChangeExpandedMode(OmnibarMode modeToExpand)
103103
foreach (var column in _modesHostGrid.ColumnDefinitions)
104104
column.Width = GridLength.Auto;
105105
foreach (var mode in Modes)
106-
{
107106
VisualStateManager.GoToState(mode, "Unfocused", true);
108-
}
109107

110108
// Expand the given mode
111109
VisualStateManager.GoToState(modeToExpand, "Focused", true);
112110
_modesHostGrid.ColumnDefinitions[_modesHostGrid.Children.IndexOf(modeToExpand)].Width = new(1, GridUnitType.Star);
113111

114112
CurrentActiveMode = modeToExpand;
113+
114+
UpdateVisualStates();
115115
}
116116

117117
private void UpdateVisualStates()
@@ -121,13 +121,16 @@ private void UpdateVisualStates()
121121
_isFocused ? "Focused" : "Normal",
122122
true);
123123

124+
if (CurrentActiveMode is not null && _autoSuggestPopup is not null)
125+
VisualStateManager.GoToState(this, _isFocused && CurrentActiveMode.SuggestionItemsSource is not null ? "PopupOpened" : "PopupClosed", true);
126+
124127
if (CurrentActiveMode is not null)
125128
VisualStateManager.GoToState(CurrentActiveMode, _isFocused ? "Focused" : "CurrentUnfocused", true);
126129
}
127130

128131
// Events
129132

130-
private void _modesHostGrid_SizeChanged(object sender, SizeChangedEventArgs e)
133+
private void ModesHostGrid_SizeChanged(object sender, SizeChangedEventArgs e)
131134
{
132135
_autoSuggestBoxBorder!.Width = _modesHostGrid!.ActualWidth;
133136
}
@@ -136,16 +139,12 @@ private void Omnibar_GotFocus(object sender, RoutedEventArgs e)
136139
{
137140
_isFocused = true;
138141
UpdateVisualStates();
139-
140-
_autoSuggestPopup!.IsOpen = true;
141142
}
142143

143144
private void Omnibar_LostFocus(object sender, RoutedEventArgs e)
144145
{
145146
_isFocused = false;
146147
UpdateVisualStates();
147-
148-
_autoSuggestPopup!.IsOpen = false;
149148
}
150149
}
151150
}

src/Files.App.Controls/Omnibar/Omnibar.xaml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@
6060
x:Name="PART_AutoSuggestPopup"
6161
Grid.Row="1"
6262
HorizontalAlignment="Stretch"
63+
IsOpen="False"
6364
ShouldConstrainToRootBounds="False">
6465

6566
<Border
6667
x:Name="PART_AutoSuggestBoxBorder"
67-
Padding="8"
68+
MaxHeight="200"
6869
Background="{ThemeResource AcrylicBackgroundFillColorDefaultBrush}"
6970
BorderBrush="{ThemeResource SurfaceStrokeColorFlyoutBrush}"
7071
BorderThickness="1"
@@ -74,10 +75,12 @@
7475
</Border.Shadow>
7576

7677
<ListView
78+
Padding="4"
7779
HorizontalAlignment="Stretch"
7880
IsItemClickEnabled="True"
7981
ItemTemplate="{Binding CurrentActiveMode.SuggestionItemTemplate, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
80-
ItemsSource="{Binding CurrentActiveMode.SuggestionItemsSource, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" />
82+
ItemsSource="{Binding CurrentActiveMode.SuggestionItemsSource, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
83+
SelectionMode="None" />
8184

8285
</Border>
8386
</Popup>
@@ -88,20 +91,18 @@
8891
<VisualState x:Name="Normal" />
8992
<VisualState x:Name="Focused">
9093
<VisualState.Setters>
91-
<Setter Target="PART_ModesHostGrid.BorderBrush" Value="{ThemeResource AccentFillColorDefaultBrush}" />
92-
<Setter Target="PART_ModesHostGrid.BorderThickness" Value="{StaticResource OmnibarFocusedBorderThickness}" />
9394
<Setter Target="PART_ModesHostGrid.Margin" Value="-1" />
95+
<Setter Target="PART_ModesHostGrid.BorderThickness" Value="{StaticResource OmnibarFocusedBorderThickness}" />
96+
<Setter Target="PART_ModesHostGrid.BorderBrush" Value="{ThemeResource AccentFillColorDefaultBrush}" />
9497
</VisualState.Setters>
9598
</VisualState>
9699
</VisualStateGroup>
97100

98101
<VisualStateGroup x:Name="PopupVisibilityStates">
99-
<VisualState x:Name="Closed" />
100-
<VisualState x:Name="Opened">
102+
<VisualState x:Name="PopupClosed" />
103+
<VisualState x:Name="PopupOpened">
101104
<VisualState.Setters>
102-
<Setter Target="PART_ModesHostGrid.BorderBrush" Value="{ThemeResource AccentFillColorDefaultBrush}" />
103-
<Setter Target="PART_ModesHostGrid.BorderThickness" Value="{StaticResource OmnibarFocusedBorderThickness}" />
104-
<Setter Target="PART_ModesHostGrid.Margin" Value="-1" />
105+
<Setter Target="PART_AutoSuggestPopup.IsOpen" Value="True" />
105106
</VisualState.Setters>
106107
</VisualState>
107108
</VisualStateGroup>

src/Files.App.Controls/Omnibar/OmnibarMode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected override void OnApplyTemplate()
4747
?? throw new MissingFieldException($"Could not find {InputTextBox} in the given {nameof(OmnibarMode)}'s style.");
4848

4949
if (IsDefault)
50-
Host!.ChangeExpandedMode(this);
50+
Host!.ChangeMode(this);
5151

5252
UpdateVisualStates();
5353

@@ -97,7 +97,7 @@ private void OmnibarMode_PointerReleased(object sender, PointerRoutedEventArgs e
9797
_isHoveredOver = true;
9898
_isPressed = false;
9999
UpdateVisualStates();
100-
Host.ChangeExpandedMode(this);
100+
Host.ChangeMode(this);
101101
}
102102

103103
private void OmnibarMode_PointerExited(object sender, PointerRoutedEventArgs e)

tests/Files.App.UITests/Views/OmnibarPage.xaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,22 @@
8787
</controls:OmnibarMode.IconOnInactive>
8888
<controls:OmnibarMode.SuggestionItemTemplate>
8989
<DataTemplate x:DataType="data:DummyItem1">
90-
<TextBlock Text="{x:Bind Title}" />
90+
<Grid Height="48">
91+
<Grid.ColumnDefinitions>
92+
<ColumnDefinition Width="*" />
93+
<ColumnDefinition Width="Auto" />
94+
</Grid.ColumnDefinitions>
95+
<StackPanel Grid.Column="0" VerticalAlignment="Center">
96+
<TextBlock Style="{StaticResource BodyStrongTextBlockStyle}" Text="{x:Bind Title}" />
97+
<TextBlock
98+
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
99+
Style="{StaticResource CaptionTextBlockStyle}"
100+
Text="{x:Bind Description}" />
101+
</StackPanel>
102+
<StackPanel Grid.Column="1" VerticalAlignment="Center">
103+
<TextBlock Text="{x:Bind HotKeys}" />
104+
</StackPanel>
105+
</Grid>
91106
</DataTemplate>
92107
</controls:OmnibarMode.SuggestionItemTemplate>
93108
</controls:OmnibarMode>

tests/Files.App.UITests/Views/OmnibarPage.xaml.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,23 @@ namespace Files.App.UITests.Views
1010
{
1111
public sealed partial class OmnibarPage : Page
1212
{
13-
private ObservableCollection<DummyItem1> DummyItems1 = [];
13+
private readonly ObservableCollection<DummyItem1> DummyItems1;
1414

1515
public OmnibarPage()
1616
{
1717
InitializeComponent();
1818

1919
DummyItems1 =
2020
[
21-
new("Title", "Description", "HotKeys"),
22-
new("Title", "Description", "HotKeys"),
23-
new("Title", "Description", "HotKeys"),
24-
new("Title", "Description", "HotKeys"),
21+
new("Open online help page in browser", "Open online help page in browser", "Control + H"),
22+
new("Toggle full screen", "Toggle full screen", "Control + H"),
23+
new("Enter compact overlay", "Enter compact overlay", "Control + H"),
24+
new("Toggle compact overlay", "Toggle compact overlay", "Control + H"),
25+
new("Go to search box", "Go to search box", "Control + H"),
26+
new("Focus path bar", "Focus path bar", "Control + H"),
27+
new("Redo the last file operation", "Redo the last file operation", "Control + H"),
28+
new("Undo the last file operation", "Undo the last file operation", "Control + H"),
29+
new("Toggle whether to show hidden items", "Toggle whether to show hidden items", "Control + H"),
2530
];
2631
}
2732
}

0 commit comments

Comments
 (0)