Skip to content

Commit 25309d8

Browse files
authored
Feature: Introduced Omnibar 1 (#17023)
1 parent 06489eb commit 25309d8

14 files changed

+607
-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 || (CurrentSelectedMode?.SuggestionItemsSource is IList collection && collection.Count is 0)))
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

+10-1
Original file line numberDiff line numberDiff line change
@@ -4202,4 +4202,13 @@
42024202
<data name="EmptyShelfText" xml:space="preserve">
42034203
<value>Drag files or folders here to interact with them across different tabs</value>
42044204
</data>
4205-
</root>
4205+
<data name="OmnibarPathModeTextPlaceholder" xml:space="preserve">
4206+
<value>Enter a path to navigate to...</value>
4207+
</data>
4208+
<data name="OmnibarCommandPaletteModeTextPlaceholder" xml:space="preserve">
4209+
<value>Find features and commands...</value>
4210+
</data>
4211+
<data name="OmnibarSearchModeTextPlaceholder" xml:space="preserve">
4212+
<value>Search for files and folders...</value>
4213+
</data>
4214+
</root>

0 commit comments

Comments
 (0)