Skip to content

Commit dc2399d

Browse files
committed
Init
1 parent 15e864a commit dc2399d

14 files changed

+560
-98
lines changed

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ private void Omnibar_SizeChanged(object sender, SizeChangedEventArgs e)
1616

1717
private void AutoSuggestBox_GotFocus(object sender, RoutedEventArgs e)
1818
{
19-
_isFocused = true;
19+
IsFocused = true;
2020

2121
VisualStateManager.GoToState(CurrentSelectedMode, "Focused", true);
2222
VisualStateManager.GoToState(_textBox, "InputAreaVisible", true);
@@ -30,7 +30,7 @@ private void AutoSuggestBox_LostFocus(object sender, RoutedEventArgs e)
3030
if (_textBox.ContextFlyout.IsOpen)
3131
return;
3232

33-
_isFocused = false;
33+
IsFocused = false;
3434

3535
if (CurrentSelectedMode?.ContentOnInactive is not null)
3636
{
@@ -92,7 +92,8 @@ private void AutoSuggestBox_KeyDown(object sender, KeyRoutedEventArgs e)
9292

9393
private void AutoSuggestBox_TextChanged(object sender, TextChangedEventArgs e)
9494
{
95-
CurrentSelectedMode!.Text = _textBox.Text;
95+
if (string.Compare(_textBox.Text, CurrentSelectedMode!.Text, StringComparison.OrdinalIgnoreCase) is not 0)
96+
CurrentSelectedMode!.Text = _textBox.Text;
9697

9798
// UpdateSuggestionListView();
9899

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

+16
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,23 @@ public partial class Omnibar
1313
[GeneratedDependencyProperty]
1414
public partial OmnibarMode? CurrentSelectedMode { get; set; }
1515

16+
[GeneratedDependencyProperty]
17+
public partial string? CurrentSelectedModeName { get; set; }
18+
1619
[GeneratedDependencyProperty]
1720
public partial Thickness AutoSuggestBoxPadding { get; set; }
21+
22+
[GeneratedDependencyProperty]
23+
public partial bool IsFocused { get; set; }
24+
25+
partial void OnCurrentSelectedModeChanged(OmnibarMode? newValue)
26+
{
27+
CurrentSelectedModeName = newValue?.ModeName;
28+
}
29+
30+
partial void OnIsFocusedChanged(bool newValue)
31+
{
32+
//_textBox?.Focus(newValue ? FocusState.Programmatic : FocusState.Unfocused);
33+
}
1834
}
1935
}

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

+12-11
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public partial class Omnibar : Control
2828
private Border _textBoxSuggestionsContainerBorder = null!;
2929
private ListView _textBoxSuggestionsListView = null!;
3030

31-
private bool _isFocused;
3231
private string _userInput = string.Empty;
3332
private OmnibarTextChangeReason _textChangeReason = OmnibarTextChangeReason.None;
3433

@@ -148,15 +147,15 @@ public void ChangeMode(OmnibarMode modeToExpand, bool shouldFocus = false, bool
148147
CurrentSelectedMode = modeToExpand;
149148

150149
_textChangeReason = OmnibarTextChangeReason.ProgrammaticChange;
151-
_textBox.Text = CurrentSelectedMode.Text ?? string.Empty;
150+
ChangeTextBoxText(CurrentSelectedMode.Text ?? string.Empty);
152151

153152
// Move cursor of the TextBox to the tail
154153
_textBox.Select(_textBox.Text.Length, 0);
155154

156155
VisualStateManager.GoToState(CurrentSelectedMode, "Focused", true);
157156
CurrentSelectedMode.OnChangingCurrentMode(true);
158157

159-
if (_isFocused)
158+
if (IsFocused)
160159
{
161160
VisualStateManager.GoToState(CurrentSelectedMode, "Focused", true);
162161
VisualStateManager.GoToState(_textBox, "InputAreaVisible", true);
@@ -174,7 +173,7 @@ public void ChangeMode(OmnibarMode modeToExpand, bool shouldFocus = false, bool
174173
if (shouldFocus)
175174
_textBox.Focus(FocusState.Keyboard);
176175

177-
TryToggleIsSuggestionsPopupOpen(_isFocused && CurrentSelectedMode?.SuggestionItemsSource is not null);
176+
TryToggleIsSuggestionsPopupOpen(IsFocused && CurrentSelectedMode?.SuggestionItemsSource is not null);
178177

179178
// Remove the reposition transition from the all modes
180179
if (useTransition)
@@ -189,7 +188,7 @@ public void ChangeMode(OmnibarMode modeToExpand, bool shouldFocus = false, bool
189188

190189
public bool TryToggleIsSuggestionsPopupOpen(bool wantToOpen)
191190
{
192-
if (wantToOpen && (!_isFocused || CurrentSelectedMode?.SuggestionItemsSource is null))
191+
if (wantToOpen && (!IsFocused || CurrentSelectedMode?.SuggestionItemsSource is null))
193192
return false;
194193

195194
_textBoxSuggestionsPopup.IsOpen = wantToOpen;
@@ -205,10 +204,15 @@ public void ChooseSuggestionItem(object obj)
205204
if (CurrentSelectedMode.UpdateTextOnSelect)
206205
{
207206
_textChangeReason = OmnibarTextChangeReason.SuggestionChosen;
208-
_textBox.Text = GetObjectText(obj);
207+
ChangeTextBoxText(GetObjectText(obj));
209208
}
210209

211210
SuggestionChosen?.Invoke(this, new(CurrentSelectedMode, obj));
211+
}
212+
213+
internal protected void ChangeTextBoxText(string text)
214+
{
215+
_textBox.Text = text;
212216

213217
// Move the cursor to the end of the TextBox
214218
_textBox?.Select(_textBox.Text.Length, 0);
@@ -233,7 +237,7 @@ private string GetObjectText(object obj)
233237
return obj is string text
234238
? text
235239
: obj is IOmnibarTextMemberPathProvider textMemberPathProvider
236-
? textMemberPathProvider.GetTextMemberPath(CurrentSelectedMode.DisplayMemberPath ?? string.Empty)
240+
? textMemberPathProvider.GetTextMemberPath(CurrentSelectedMode.TextMemberPath ?? string.Empty)
237241
: obj.ToString() ?? string.Empty;
238242
}
239243

@@ -245,10 +249,7 @@ private void RevertTextToUserInput()
245249
_textBoxSuggestionsListView.SelectedIndex = -1;
246250
_textChangeReason = OmnibarTextChangeReason.ProgrammaticChange;
247251

248-
_textBox.Text = _userInput ?? "";
249-
250-
// Move the cursor to the end of the TextBox
251-
_textBox?.Select(_textBox.Text.Length, 0);
252+
ChangeTextBoxText(_userInput ?? "");
252253
}
253254
}
254255
}

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

-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@
133133
Height="{TemplateBinding Height}"
134134
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
135135
Background="{TemplateBinding Background}"
136-
CornerRadius="{TemplateBinding CornerRadius}"
137136
TabFocusNavigation="Local">
138137
<!-- Mode Button -->
139138
<Border

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,20 @@ public partial class OmnibarMode
3535
public partial DataTemplate? SuggestionItemTemplate { get; set; }
3636

3737
[GeneratedDependencyProperty]
38-
public partial string? DisplayMemberPath { get; set; }
38+
/// <remark>
39+
/// Implement <see cref="IOmnibarTextMemberPathProvider"/> in <see cref="SuggestionItemsSource"/> to get the text member path from the suggestion item correctly.
40+
/// </remark>
41+
public partial string? TextMemberPath { get; set; }
3942

4043
[GeneratedDependencyProperty(DefaultValue = true)]
4144
public partial bool UpdateTextOnSelect { get; set; }
45+
46+
partial void OnTextChanged(string? newValue)
47+
{
48+
if (_ownerRef is null || _ownerRef.TryGetTarget(out var owner) is false)
49+
return;
50+
51+
owner.ChangeTextBoxText(newValue ?? string.Empty);
52+
}
4253
}
4354
}

src/Files.App/Data/Items/NavigationBarSuggestionItem.cs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace Files.App.Data.Items
55
{
6+
[Obsolete("Remove once Omnibar goes out of experimental.")]
67
public sealed partial class NavigationBarSuggestionItem : ObservableObject
78
{
89
private string? _Text;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
namespace Files.App.Data.Models
5+
{
6+
internal record BreadcrumbBarItemModel(string Text);
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
using Files.App.Controls;
5+
6+
namespace Files.App.Data.Models
7+
{
8+
internal record OmnibarPathModeSuggestionModel(string Path, string DisplayName) : IOmnibarTextMemberPathProvider
9+
{
10+
public string GetTextMemberPath(string textMemberPath)
11+
{
12+
return textMemberPath switch
13+
{
14+
nameof(Path) => Path,
15+
nameof(DisplayName) => DisplayName,
16+
_ => string.Empty
17+
};
18+
}
19+
}
20+
}

src/Files.App/Strings/en-US/Resources.resw

+3
Original file line numberDiff line numberDiff line change
@@ -4199,4 +4199,7 @@
41994199
<data name="SectionsHiddenMessage" xml:space="preserve">
42004200
<value>You can add sections to the sidebar by right-clicking and selecting the sections you want to add.</value>
42014201
</data>
4202+
<data name="OmnibarPathModeTextPlaceholder" xml:space="preserve">
4203+
<value>Enter a path to navigate to...</value>
4204+
</data>
42024205
</root>

src/Files.App/UserControls/NavigationToolbar.xaml

+110-14
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
xmlns:converters="using:Files.App.Converters"
1010
xmlns:converters1="using:CommunityToolkit.WinUI.Converters"
1111
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
12+
xmlns:dataitems="using:Files.App.Data.Items"
13+
xmlns:datamodels="using:Files.App.Data.Models"
1214
xmlns:helpers="using:Files.App.Helpers"
1315
xmlns:items="using:Files.App.Data.Items"
1416
xmlns:keyboard="using:Files.App.UserControls.KeyboardShortcut"
@@ -211,6 +213,7 @@
211213
<Grid.ColumnDefinitions>
212214
<ColumnDefinition Width="*" />
213215
<ColumnDefinition Width="Auto" />
216+
<ColumnDefinition Width="Auto" />
214217
</Grid.ColumnDefinitions>
215218
<!-- Path Box -->
216219
<AutoSuggestBox
@@ -231,7 +234,7 @@
231234
QuerySubmitted="VisiblePath_QuerySubmitted"
232235
ScrollViewer.HorizontalScrollBarVisibility="Auto"
233236
ScrollViewer.VerticalScrollBarVisibility="Hidden"
234-
Text="{x:Bind ViewModel.PathText, Mode=OneWay}"
237+
Text="{x:Bind ViewModel.LegacySharedPathPaletteText, Mode=OneWay}"
235238
TextChanged="{x:Bind ViewModel.VisiblePath_TextChanged, Mode=OneWay}"
236239
TextMemberPath="Text"
237240
Visibility="{x:Bind converters:MultiBooleanConverter.OrNotConvertToVisibility(ShowSearchBox, ViewModel.IsSearchBoxVisible), Mode=OneWay}">
@@ -314,23 +317,11 @@
314317
LostFocus="SearchRegion_LostFocus"
315318
SearchBoxViewModel="{x:Bind ViewModel.SearchBoxViewModel, Mode=OneWay}"
316319
Visibility="{x:Bind converters:MultiBooleanConverter.OrConvertToVisibility(ShowSearchBox, ViewModel.IsSearchBoxVisible), Mode=OneWay}" />
317-
</Grid>
318-
319-
<!-- Omnibar -->
320-
<controls:Omnibar
321-
x:Name="Omnibar"
322-
Grid.Column="1"
323-
x:Load="{x:Bind ViewModel.EnableOmnibar, Mode=OneWay}" />
324-
325-
<!-- Right Side Action Buttons -->
326-
<StackPanel
327-
Grid.Column="2"
328-
Orientation="Horizontal"
329-
Spacing="4">
330320

331321
<!-- Mini Search Button -->
332322
<Button
333323
x:Name="ShowSearchButton"
324+
Grid.Column="2"
334325
AccessKey="I"
335326
AccessKeyInvoked="Button_AccessKeyInvoked"
336327
AutomationProperties.Name="{x:Bind Commands.Search.Label, Mode=OneWay}"
@@ -342,6 +333,111 @@
342333
<FontIcon FontSize="14" Glyph="{x:Bind ViewModel.SearchButtonGlyph, Mode=OneWay}" />
343334
</Button>
344335

336+
</Grid>
337+
338+
<!-- Omnibar -->
339+
<controls:Omnibar
340+
x:Name="Omnibar"
341+
Grid.Column="1"
342+
x:Load="{x:Bind ViewModel.EnableOmnibar, Mode=OneWay}"
343+
CurrentSelectedModeName="{x:Bind ViewModel.OmnibarCurrentSelectedModeName, Mode=TwoWay}"
344+
IsFocused="{x:Bind ViewModel.IsOmnibarFocused, Mode=TwoWay}"
345+
QuerySubmitted="Omnibar_QuerySubmitted"
346+
SuggestionChosen="Omnibar_SuggestionChosen"
347+
TextChanged="Omnibar_TextChanged">
348+
349+
<controls:OmnibarMode
350+
IconOnActive="{controls:ThemedIconMarkup Style={StaticResource App.ThemedIcons.Omnibar.Path}, IsFilled=True}"
351+
IconOnInactive="{controls:ThemedIconMarkup Style={StaticResource App.ThemedIcons.Omnibar.Path}, IconType=Outline}"
352+
IsDefault="True"
353+
ModeName="Path"
354+
PlaceholderText="{helpers:ResourceString Name=OmnibarPathModeTextPlaceholder}"
355+
SuggestionItemsSource="{x:Bind ViewModel.PathModeSuggestionItems, Mode=OneWay}"
356+
Text="{x:Bind ViewModel.OmnibarPathModeText, Mode=TwoWay}"
357+
TextMemberPath="Path">
358+
<controls:OmnibarMode.ContentOnInactive>
359+
<controls:BreadcrumbBar
360+
x:Name="BreadcrumbBar"
361+
ItemClicked="BreadcrumbBar_ItemClicked"
362+
ItemDropDownFlyoutClosed="BreadcrumbBar_ItemDropDownFlyoutClosed"
363+
ItemDropDownFlyoutOpening="BreadcrumbBar_ItemDropDownFlyoutOpening"
364+
ItemsSource="{x:Bind ViewModel.PathComponents, Mode=OneWay}">
365+
<controls:BreadcrumbBar.RootItem>
366+
<Image
367+
Width="16"
368+
Height="16"
369+
Source="/Assets/FluentIcons/Home.png" />
370+
</controls:BreadcrumbBar.RootItem>
371+
<controls:BreadcrumbBar.ItemTemplate>
372+
<DataTemplate x:DataType="dataitems:PathBoxItem">
373+
<controls:BreadcrumbBarItem Content="{x:Bind Title, Mode=OneWay}" />
374+
</DataTemplate>
375+
</controls:BreadcrumbBar.ItemTemplate>
376+
</controls:BreadcrumbBar>
377+
</controls:OmnibarMode.ContentOnInactive>
378+
<controls:OmnibarMode.SuggestionItemTemplate>
379+
<DataTemplate x:DataType="datamodels:OmnibarPathModeSuggestionModel">
380+
<TextBlock Text="{x:Bind DisplayName, Mode=OneWay}" />
381+
</DataTemplate>
382+
</controls:OmnibarMode.SuggestionItemTemplate>
383+
</controls:OmnibarMode>
384+
385+
<controls:OmnibarMode
386+
IconOnActive="{controls:ThemedIconMarkup Style={StaticResource App.ThemedIcons.Omnibar.Commands}, IsFilled=True}"
387+
IconOnInactive="{controls:ThemedIconMarkup Style={StaticResource App.ThemedIcons.Omnibar.Commands}, IconType=Outline}"
388+
ModeName="Palette"
389+
PlaceholderText="Enter a palette command...">
390+
<!--<controls:OmnibarMode.SuggestionItemTemplate>
391+
<DataTemplate x:DataType="data:OmnibarPaletteSuggestionItem">
392+
<Grid Height="48" ColumnSpacing="12">
393+
<Grid.ColumnDefinitions>
394+
<ColumnDefinition Width="Auto" />
395+
<ColumnDefinition Width="*" />
396+
<ColumnDefinition Width="Auto" />
397+
</Grid.ColumnDefinitions>
398+
<controls:ThemedIcon
399+
Width="20"
400+
Height="20"
401+
VerticalAlignment="Center"
402+
Style="{StaticResource App.ThemedIcons.Actions.Copying}" />
403+
<StackPanel Grid.Column="1" VerticalAlignment="Center">
404+
<TextBlock
405+
Style="{StaticResource BodyStrongTextBlockStyle}"
406+
Text="{x:Bind Title}"
407+
TextTrimming="CharacterEllipsis"
408+
TextWrapping="NoWrap" />
409+
<TextBlock
410+
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
411+
Style="{StaticResource CaptionTextBlockStyle}"
412+
Text="{x:Bind Description}"
413+
TextTrimming="CharacterEllipsis"
414+
TextWrapping="NoWrap" />
415+
</StackPanel>
416+
<StackPanel Grid.Column="2" VerticalAlignment="Center">
417+
<TextBlock
418+
Text="{x:Bind HotKeys}"
419+
TextTrimming="CharacterEllipsis"
420+
TextWrapping="NoWrap" />
421+
</StackPanel>
422+
</Grid>
423+
</DataTemplate>
424+
</controls:OmnibarMode.SuggestionItemTemplate>-->
425+
</controls:OmnibarMode>
426+
427+
<controls:OmnibarMode
428+
IconOnActive="{controls:ThemedIconMarkup Style={StaticResource App.ThemedIcons.Omnibar.Search}, IsFilled=True}"
429+
IconOnInactive="{controls:ThemedIconMarkup Style={StaticResource App.ThemedIcons.Omnibar.Search}, IconType=Outline}"
430+
ModeName="Search"
431+
PlaceholderText="Enter a search query..." />
432+
433+
</controls:Omnibar>
434+
435+
<!-- Right Side Action Buttons -->
436+
<StackPanel
437+
Grid.Column="2"
438+
Orientation="Horizontal"
439+
Spacing="4">
440+
345441
<!-- Shelf Pane -->
346442
<ToggleButton
347443
x:Name="ShelfPaneToggleButton"

0 commit comments

Comments
 (0)