Skip to content

Commit 9f521ff

Browse files
committed
Initial popup impl for auto-suggestion
1 parent 647129d commit 9f521ff

File tree

3 files changed

+68
-12
lines changed

3 files changed

+68
-12
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ namespace Files.App.Controls
2222
public partial class Omnibar : Control
2323
{
2424
private const string ModesHostGrid = "PART_ModesHostGrid";
25+
private const string AutoSuggestPopup = "PART_AutoSuggestPopup";
26+
private const string AutoSuggestBoxBorder = "PART_AutoSuggestBoxBorder";
2527

2628
private Grid? _modesHostGrid;
29+
private Popup? _autoSuggestPopup;
30+
private Border? _autoSuggestBoxBorder;
2731
private bool _wasAscendantFocused;
2832
private bool _isFocused;
2933

@@ -38,6 +42,10 @@ protected override void OnApplyTemplate()
3842
{
3943
_modesHostGrid = GetTemplateChild(ModesHostGrid) as Grid
4044
?? throw new MissingFieldException($"Could not find {ModesHostGrid} in the given {nameof(Omnibar)}'s style.");
45+
_autoSuggestPopup = GetTemplateChild(AutoSuggestPopup) as Popup
46+
?? throw new MissingFieldException($"Could not find {AutoSuggestPopup} in the given {nameof(Omnibar)}'s style.");
47+
_autoSuggestBoxBorder = GetTemplateChild(AutoSuggestBoxBorder) as Border
48+
?? throw new MissingFieldException($"Could not find {AutoSuggestBoxBorder} in the given {nameof(Omnibar)}'s style.");
4149

4250
if (Modes is null)
4351
return;
@@ -68,9 +76,10 @@ protected override void OnApplyTemplate()
6876
mode.Host = this;
6977
}
7078

79+
_modesHostGrid.SizeChanged += _modesHostGrid_SizeChanged;
80+
7181
var parentElement = this.FindAscendant<FrameworkElement>()!;
7282
parentElement.PointerPressed += ParentElement_PointerPressed;
73-
7483
GotFocus += Omnibar_GotFocus;
7584
LostFocus += Omnibar_LostFocus;
7685

@@ -113,6 +122,11 @@ private void UpdateVisualStates()
113122

114123
// Events
115124

125+
private void _modesHostGrid_SizeChanged(object sender, SizeChangedEventArgs e)
126+
{
127+
_autoSuggestBoxBorder!.Width = _modesHostGrid!.ActualWidth;
128+
}
129+
116130
private void ParentElement_PointerPressed(object sender, PointerRoutedEventArgs e)
117131
{
118132
// Lost focus
@@ -137,12 +151,16 @@ private void Omnibar_GotFocus(object sender, RoutedEventArgs e)
137151

138152
_isFocused = true;
139153
UpdateVisualStates();
154+
155+
_autoSuggestPopup!.IsOpen = true;
140156
}
141157

142158
private void Omnibar_LostFocus(object sender, RoutedEventArgs e)
143159
{
144160
_isFocused = _wasAscendantFocused = false;
145161
UpdateVisualStates();
162+
163+
_autoSuggestPopup!.IsOpen = false;
146164
}
147165
}
148166
}

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

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,57 @@
4040
<Setter Property="Template">
4141
<Setter.Value>
4242
<ControlTemplate TargetType="local:Omnibar">
43-
<Grid
44-
x:Name="PART_RootGrid"
45-
Padding="{TemplateBinding Padding}"
46-
Background="{TemplateBinding Background}"
47-
BorderBrush="{TemplateBinding BorderBrush}"
48-
BorderThickness="{TemplateBinding BorderThickness}"
49-
CornerRadius="{TemplateBinding CornerRadius}">
50-
<Grid x:Name="PART_ModesHostGrid" />
43+
<Grid x:Name="PART_RootGrid">
44+
<Grid.RowDefinitions>
45+
<RowDefinition Height="Auto" />
46+
<RowDefinition Height="Auto" />
47+
</Grid.RowDefinitions>
48+
<!-- input area -->
49+
<Grid
50+
x:Name="PART_ModesHostGrid"
51+
Grid.Row="0"
52+
Margin="{TemplateBinding Padding}"
53+
Background="{TemplateBinding Background}"
54+
BorderBrush="{TemplateBinding BorderBrush}"
55+
BorderThickness="{TemplateBinding BorderThickness}"
56+
CornerRadius="{TemplateBinding CornerRadius}" />
57+
58+
<!-- Auto-suggest box area -->
59+
<Popup
60+
x:Name="PART_AutoSuggestPopup"
61+
Grid.Row="1"
62+
HorizontalAlignment="Stretch"
63+
ShouldConstrainToRootBounds="False">
64+
65+
<Border
66+
x:Name="PART_AutoSuggestBoxBorder"
67+
Width="460"
68+
Padding="8"
69+
HorizontalAlignment="Stretch"
70+
Background="{ThemeResource AcrylicBackgroundFillColorDefaultBrush}"
71+
BorderBrush="{ThemeResource SurfaceStrokeColorFlyoutBrush}"
72+
BorderThickness="1"
73+
CornerRadius="{ThemeResource OverlayCornerRadius}">
74+
<Border.Shadow>
75+
<ThemeShadow />
76+
</Border.Shadow>
77+
78+
<ListView HorizontalAlignment="Stretch">
79+
<ListViewItem />
80+
<ListViewItem />
81+
</ListView>
82+
</Border>
83+
</Popup>
5184

5285
<VisualStateManager.VisualStateGroups>
5386

5487
<VisualStateGroup x:Name="PointerStates">
5588
<VisualState x:Name="Normal" />
5689
<VisualState x:Name="Focused">
5790
<VisualState.Setters>
58-
<Setter Target="PART_RootGrid.BorderBrush" Value="{ThemeResource AccentFillColorDefaultBrush}" />
59-
<Setter Target="PART_RootGrid.BorderThickness" Value="{StaticResource OmnibarFocusedBorderThickness}" />
60-
<Setter Target="PART_RootGrid.Margin" Value="-1" />
91+
<Setter Target="PART_ModesHostGrid.BorderBrush" Value="{ThemeResource AccentFillColorDefaultBrush}" />
92+
<Setter Target="PART_ModesHostGrid.BorderThickness" Value="{StaticResource OmnibarFocusedBorderThickness}" />
93+
<Setter Target="PART_ModesHostGrid.Margin" Value="-1" />
6194
</VisualState.Setters>
6295
</VisualState>
6396
</VisualStateGroup>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@
7777
<controls:OmnibarMode.IconOnInactive>
7878
<controls:ThemedIcon Style="{StaticResource App.ThemedIcons.Omnibar.Path}" />
7979
</controls:OmnibarMode.IconOnInactive>
80+
<controls:OmnibarMode.SuggestionItemTemplate>
81+
<DataTemplate>
82+
<TextBlock Text="Text here..." />
83+
</DataTemplate>
84+
</controls:OmnibarMode.SuggestionItemTemplate>
8085
</controls:OmnibarMode>
8186

8287
<controls:OmnibarMode

0 commit comments

Comments
 (0)