Skip to content

Commit 5e9afc3

Browse files
committed
Init
1 parent 72c3faf commit 5e9afc3

23 files changed

+1037
-589
lines changed

Settings.XamlStyler

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"IndentWithTabs": true
2+
"IndentWithTabs": true,
3+
"NoNewLineMarkupExtensions": "x:Bind, Binding, controls:ThemedIconMarkup",
34
}

src/Files.App.Controls/BreadcrumbBar/BreadcrumbBar.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public BreadcrumbBar()
4242
{
4343
DefaultStyleKey = typeof(BreadcrumbBar);
4444

45-
_itemsRepeaterLayout = new(this, 2d);
45+
_itemsRepeaterLayout = new(this);
4646
}
4747

4848
// Methods
@@ -87,12 +87,13 @@ internal protected virtual void RaiseItemDropDownFlyoutClosed(BreadcrumbBarItem
8787

8888
internal protected virtual void OnLayoutUpdated()
8989
{
90-
if (_itemsRepeater is null)
90+
if (_itemsRepeater is null || (_itemsRepeaterLayout.IndexAfterEllipsis > _itemsRepeaterLayout.VisibleItemsCount && _isEllipsisRendered))
9191
return;
9292

93+
if (_ellipsisBreadcrumbBarItem is not null && _isEllipsisRendered != _itemsRepeaterLayout.EllipsisIsRendered)
94+
_ellipsisBreadcrumbBarItem.Visibility = _itemsRepeaterLayout.EllipsisIsRendered ? Visibility.Visible : Visibility.Collapsed;
95+
9396
_isEllipsisRendered = _itemsRepeaterLayout.EllipsisIsRendered;
94-
if (_ellipsisBreadcrumbBarItem is not null)
95-
_ellipsisBreadcrumbBarItem.Visibility = _isEllipsisRendered ? Visibility.Visible : Visibility.Collapsed;
9697

9798
for (int accessibilityIndex = 0, collectionIndex = _itemsRepeaterLayout.IndexAfterEllipsis;
9899
accessibilityIndex < _itemsRepeaterLayout.VisibleItemsCount;

src/Files.App.Controls/BreadcrumbBar/BreadcrumbBar.xaml

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
xmlns:animatedvisuals="using:Microsoft.UI.Xaml.Controls.AnimatedVisuals"
66
xmlns:local="using:Files.App.Controls">
77

8-
<x:Double x:Key="BreadcrumbBarHeight">32</x:Double>
8+
<x:Double x:Key="BreadcrumbBarHeight">34</x:Double>
99
<x:Double x:Key="BreadcrumbBarMinWidth">120</x:Double>
1010
<x:Double x:Key="BreadcrumbBarEllipsisFontSize">16</x:Double>
1111

1212
<Thickness x:Key="BreadcrumbBarChevronPadding">4,0</Thickness>
1313
<Thickness x:Key="BreadcrumbBarItemPadding">8,0</Thickness>
1414
<Thickness x:Key="BreadcrumbBarRootItemPadding">16,0,8,0</Thickness>
15+
<Thickness x:Key="BreadcrumbBarItemMargin">2,0,0,0</Thickness>
1516

1617
<CornerRadius x:Key="BreadcrumbBarItemCornerRadius">2,2,2,2</CornerRadius>
1718
<CornerRadius x:Key="BreadcrumbBarChevronCornerRaduis">2,2,2,2</CornerRadius>
@@ -21,21 +22,33 @@
2122
<Style BasedOn="{StaticResource DefaultBreadcrumbBarItemStyle}" TargetType="local:BreadcrumbBarItem" />
2223

2324
<Style x:Key="DefaultBreadcrumbBarStyle" TargetType="local:BreadcrumbBar">
25+
2426
<Setter Property="MinWidth" Value="{StaticResource BreadcrumbBarMinWidth}" />
27+
28+
<Setter Property="HorizontalAlignment" Value="Stretch" />
29+
<Setter Property="HorizontalContentAlignment" Value="Center" />
30+
<Setter Property="VerticalAlignment" Value="Stretch" />
31+
<Setter Property="VerticalContentAlignment" Value="Center" />
32+
2533
<Setter Property="AutomationProperties.LandmarkType" Value="Navigation" />
34+
2635
<Setter Property="IsTabStop" Value="False" />
36+
2737
<Setter Property="Template">
2838
<Setter.Value>
2939
<ControlTemplate TargetType="local:BreadcrumbBar">
3040
<Grid
3141
MinWidth="{TemplateBinding MinWidth}"
32-
ColumnSpacing="2"
42+
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
43+
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
44+
Background="{TemplateBinding Background}"
3345
TabFocusNavigation="Once"
3446
XYFocusKeyboardNavigation="Enabled">
3547
<Grid.ColumnDefinitions>
3648
<ColumnDefinition Width="Auto" />
3749
<ColumnDefinition Width="Auto" />
3850
<ColumnDefinition Width="*" />
51+
<ColumnDefinition Width="Auto" />
3952
</Grid.ColumnDefinitions>
4053

4154
<local:BreadcrumbBarItem
@@ -50,6 +63,7 @@
5063
<local:BreadcrumbBarItem
5164
x:Name="PART_EllipsisBreadcrumbBarItem"
5265
Grid.Column="1"
66+
Margin="{StaticResource BreadcrumbBarItemMargin}"
5367
AutomationProperties.AccessibilityView="Content"
5468
IsEllipsis="True"
5569
Visibility="Collapsed">
@@ -59,6 +73,8 @@
5973
<ItemsRepeater
6074
x:Name="PART_MainItemsRepeater"
6175
Grid.Column="2"
76+
Margin="{StaticResource BreadcrumbBarItemMargin}"
77+
HorizontalAlignment="Left"
6278
ItemTemplate="{Binding ItemTemplate, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
6379
ItemsSource="{Binding ItemsSource, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" />
6480

@@ -85,17 +101,17 @@
85101
<Setter Property="HorizontalAlignment" Value="Stretch" />
86102
<Setter Property="HorizontalContentAlignment" Value="Center" />
87103
<Setter Property="VerticalAlignment" Value="Stretch" />
88-
<Setter Property="VerticalContentAlignment" Value="Center" />
104+
<Setter Property="VerticalContentAlignment" Value="Stretch" />
89105

90106
<Setter Property="FocusVisualMargin" Value="1" />
91107
<Setter Property="IsTabStop" Value="False" />
92108
<Setter Property="UseSystemFocusVisuals" Value="{StaticResource UseSystemFocusVisuals}" />
109+
93110
<Setter Property="Template">
94111
<Setter.Value>
95112
<ControlTemplate TargetType="local:BreadcrumbBarItem">
96113
<Grid
97114
x:Name="PART_LayoutRoot"
98-
ColumnSpacing="2"
99115
TabFocusNavigation="Once"
100116
XYFocusKeyboardNavigation="Enabled">
101117
<Grid.ColumnDefinitions>
@@ -107,14 +123,21 @@
107123
<Button
108124
x:Name="PART_ItemContentButton"
109125
Padding="{TemplateBinding Padding}"
110-
VerticalAlignment="Stretch"
126+
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
111127
AutomationProperties.AccessibilityView="Raw"
112128
Background="{TemplateBinding Background}"
113129
BorderBrush="{TemplateBinding BorderBrush}"
114130
BorderThickness="{TemplateBinding BorderThickness}"
115131
Control.IsTemplateFocusTarget="True"
116132
CornerRadius="{TemplateBinding CornerRadius}"
117133
UseSystemFocusVisuals="True">
134+
<Button.Resources>
135+
<ResourceDictionary>
136+
<StaticResource x:Key="ButtonBackgroundPointerOver" ResourceKey="SubtleFillColorTertiaryBrush" />
137+
<StaticResource x:Key="ButtonBackgroundPressed" ResourceKey="SubtleFillColorSecondaryBrush" />
138+
</ResourceDictionary>
139+
</Button.Resources>
140+
118141
<FlyoutBase.AttachedFlyout>
119142
<MenuFlyout
120143
x:Name="PART_ItemEllipsisDropDownMenuFlyout"
@@ -151,15 +174,23 @@
151174
<Button
152175
x:Name="PART_ItemChevronButton"
153176
Grid.Column="1"
177+
Margin="{StaticResource BreadcrumbBarItemMargin}"
154178
Padding="{StaticResource BreadcrumbBarChevronPadding}"
155-
VerticalAlignment="Stretch"
179+
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
156180
AutomationProperties.AccessibilityView="Content"
157181
Background="{TemplateBinding Background}"
158182
BorderBrush="{TemplateBinding BorderBrush}"
159183
BorderThickness="{TemplateBinding BorderThickness}"
160184
CornerRadius="{StaticResource BreadcrumbBarChevronCornerRaduis}"
161185
Style="{StaticResource BreadcrumbBarItemChevronButtonStyle}"
162186
UseSystemFocusVisuals="True">
187+
<Button.Resources>
188+
<ResourceDictionary>
189+
<StaticResource x:Key="ButtonBackgroundPointerOver" ResourceKey="SubtleFillColorTertiaryBrush" />
190+
<StaticResource x:Key="ButtonBackgroundPressed" ResourceKey="SubtleFillColorSecondaryBrush" />
191+
</ResourceDictionary>
192+
</Button.Resources>
193+
163194
<FlyoutBase.AttachedFlyout>
164195
<MenuFlyout
165196
x:Name="PART_ItemChevronDropDownMenuFlyout"

src/Files.App.Controls/BreadcrumbBar/BreadcrumbBarLayout.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public partial class BreadcrumbBarLayout : NonVirtualizingLayout
1313
// Fields
1414

1515
private readonly WeakReference<BreadcrumbBar>? _ownerRef;
16-
private readonly double _spacing = 0d;
1716

1817
private Size _availableSize;
1918
private BreadcrumbBarItem? _ellipsisButton = null;
@@ -24,10 +23,9 @@ public partial class BreadcrumbBarLayout : NonVirtualizingLayout
2423
public int IndexAfterEllipsis { get; private set; }
2524
public int VisibleItemsCount { get; private set; }
2625

27-
public BreadcrumbBarLayout(BreadcrumbBar breadcrumb, double spacing)
26+
public BreadcrumbBarLayout(BreadcrumbBar breadcrumb)
2827
{
2928
_ownerRef = new(breadcrumb);
30-
_spacing = spacing;
3129
}
3230

3331
protected override Size MeasureOverride(NonVirtualizingLayoutContext context, Size availableSize)
@@ -79,7 +77,6 @@ protected override Size ArrangeOverride(NonVirtualizingLayoutContext context, Si
7977
breadcrumbItem.Arrange(new Rect(accumulatedWidths, 0, breadcrumbItem.DesiredSize.Width, breadcrumbItem.DesiredSize.Height));
8078

8179
accumulatedWidths += breadcrumbItem.DesiredSize.Width;
82-
accumulatedWidths += _spacing;
8380

8481
VisibleItemsCount++;
8582
}
@@ -89,15 +86,17 @@ protected override Size ArrangeOverride(NonVirtualizingLayoutContext context, Si
8986
if (_ownerRef?.TryGetTarget(out var breadcrumbBar) ?? false)
9087
breadcrumbBar.OnLayoutUpdated();
9188

89+
finalSize.Width = accumulatedWidths;
90+
9291
return finalSize;
9392
}
9493

9594
private int GetFirstIndexToRender(NonVirtualizingLayoutContext context)
9695
{
9796
var itemCount = context.Children.Count;
98-
var accumulatedWidth = _spacing;
97+
var accumulatedWidth = 0d;
9998

100-
// Go through all items from the end
99+
// Go through all items from the last item
101100
for (int index = itemCount - 1; index >= 0; index--)
102101
{
103102
var newAccumulatedWidth = accumulatedWidth + context.Children[index].DesiredSize.Width;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
namespace Files.App.Controls
5+
{
6+
public record class OmnibarQuerySubmittedEventArgs(OmnibarMode Mode, object? Item, string Text);
7+
8+
public record class OmnibarSuggestionChosenEventArgs(OmnibarMode Mode, object SelectedItem);
9+
10+
public record class OmnibarTextChangedEventArgs(OmnibarMode Mode, OmnibarTextChangeReason Reason);
11+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
using Microsoft.UI.Xaml.Input;
5+
using Windows.System;
6+
7+
namespace Files.App.Controls
8+
{
9+
public partial class Omnibar
10+
{
11+
private void Omnibar_SizeChanged(object sender, SizeChangedEventArgs e)
12+
{
13+
// Popup width has to be set manually because it doesn't stretch with the parent
14+
_textBoxSuggestionsContainerBorder.Width = ActualWidth;
15+
}
16+
17+
private void AutoSuggestBox_GotFocus(object sender, RoutedEventArgs e)
18+
{
19+
_isFocused = true;
20+
21+
VisualStateManager.GoToState(CurrentSelectedMode, "Focused", true);
22+
VisualStateManager.GoToState(_textBox, "InputAreaVisible", true);
23+
24+
TryToggleIsSuggestionsPopupOpen(true);
25+
}
26+
27+
private void AutoSuggestBox_LostFocus(object sender, RoutedEventArgs e)
28+
{
29+
// TextBox still has focus if the context menu for selected text is open
30+
if (_textBox.ContextFlyout.IsOpen)
31+
return;
32+
33+
_isFocused = false;
34+
35+
if (CurrentSelectedMode?.ContentOnInactive is not null)
36+
{
37+
VisualStateManager.GoToState(CurrentSelectedMode, "CurrentUnfocused", true);
38+
VisualStateManager.GoToState(_textBox, "InputAreaCollapsed", true);
39+
}
40+
41+
TryToggleIsSuggestionsPopupOpen(false);
42+
}
43+
44+
private void AutoSuggestBox_KeyDown(object sender, KeyRoutedEventArgs e)
45+
{
46+
if (e.Key is VirtualKey.Enter)
47+
{
48+
e.Handled = true;
49+
50+
SubmitQuery(_textBoxSuggestionsPopup.IsOpen && _textBoxSuggestionsListView.SelectedIndex is not -1 ? _textBoxSuggestionsListView.SelectedItem : null);
51+
}
52+
else if ((e.Key == VirtualKey.Up || e.Key == VirtualKey.Down) && _textBoxSuggestionsPopup.IsOpen)
53+
{
54+
e.Handled = true;
55+
56+
var currentIndex = _textBoxSuggestionsListView.SelectedIndex;
57+
var nextIndex = currentIndex;
58+
var suggestionsCount = _textBoxSuggestionsListView.Items.Count;
59+
60+
if (e.Key is VirtualKey.Up)
61+
{
62+
nextIndex--;
63+
}
64+
else if (e.Key is VirtualKey.Down)
65+
{
66+
nextIndex++;
67+
}
68+
69+
if (0 > nextIndex || nextIndex >= suggestionsCount)
70+
{
71+
RevertTextToUserInput();
72+
}
73+
else
74+
{
75+
_textBoxSuggestionsListView.SelectedIndex = nextIndex;
76+
77+
ChooseSuggestionItem(_textBoxSuggestionsListView.SelectedItem);
78+
}
79+
}
80+
else if (e.Key == VirtualKey.Escape && _textBoxSuggestionsPopup.IsOpen)
81+
{
82+
e.Handled = true;
83+
84+
RevertTextToUserInput();
85+
_textBoxSuggestionsPopup.IsOpen = false;
86+
}
87+
else
88+
{
89+
_textChangeReason = OmnibarTextChangeReason.UserInput;
90+
}
91+
}
92+
93+
private void AutoSuggestBox_TextChanged(object sender, TextChangedEventArgs e)
94+
{
95+
CurrentSelectedMode!.Text = _textBox.Text;
96+
97+
// UpdateSuggestionListView();
98+
99+
if (_textChangeReason is not OmnibarTextChangeReason.SuggestionChosen and
100+
not OmnibarTextChangeReason.ProgrammaticChange)
101+
{
102+
_textChangeReason = OmnibarTextChangeReason.UserInput;
103+
_userInput = _textBox.Text;
104+
}
105+
106+
TextChanged?.Invoke(this, new(CurrentSelectedMode, _textChangeReason));
107+
108+
// Reset
109+
_textChangeReason = OmnibarTextChangeReason.None;
110+
}
111+
112+
private void AutoSuggestBoxSuggestionsPopup_GettingFocus(UIElement sender, GettingFocusEventArgs args)
113+
{
114+
args.TryCancel();
115+
}
116+
117+
private void AutoSuggestBoxSuggestionsListView_ItemClick(object sender, ItemClickEventArgs e)
118+
{
119+
if (CurrentSelectedMode is null)
120+
return;
121+
122+
ChooseSuggestionItem(e.ClickedItem);
123+
SubmitQuery(e.ClickedItem);
124+
}
125+
}
126+
}

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
// Licensed under the MIT License.
33

44
using CommunityToolkit.WinUI;
5-
using Microsoft.UI.Xaml;
6-
using Microsoft.UI.Xaml.Controls;
7-
using Microsoft.UI.Xaml.Media;
8-
using Microsoft.UI.Xaml.Markup;
9-
using Microsoft.UI.Xaml.Shapes;
10-
using System.Linq;
11-
using System.Collections.Generic;
125

136
namespace Files.App.Controls
147
{
@@ -19,5 +12,8 @@ public partial class Omnibar
1912

2013
[GeneratedDependencyProperty]
2114
public partial OmnibarMode? CurrentSelectedMode { get; set; }
15+
16+
[GeneratedDependencyProperty]
17+
public partial Thickness AutoSuggestBoxPadding { get; set; }
2218
}
2319
}

0 commit comments

Comments
 (0)