Skip to content

Commit 404e3bd

Browse files
committed
Updated
1 parent a115149 commit 404e3bd

File tree

7 files changed

+59
-23
lines changed

7 files changed

+59
-23
lines changed

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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@ public partial class Omnibar
1515

1616
[GeneratedDependencyProperty]
1717
public partial Thickness AutoSuggestBoxPadding { get; set; }
18+
19+
[GeneratedDependencyProperty]
20+
public partial bool IsFocused { get; set; }
1821
}
1922
}

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

Lines changed: 11 additions & 10 deletions
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);
@@ -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/OmnibarMode.Properties.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,13 @@ public partial class OmnibarMode
3939

4040
[GeneratedDependencyProperty(DefaultValue = true)]
4141
public partial bool UpdateTextOnSelect { get; set; }
42+
43+
partial void OnTextChanged(string? newValue)
44+
{
45+
if (_ownerRef is null || _ownerRef.TryGetTarget(out var owner) is false)
46+
return;
47+
48+
owner.ChangeTextBoxText(newValue ?? string.Empty);
49+
}
4250
}
4351
}

src/Files.App/UserControls/NavigationToolbar.xaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@
233233
QuerySubmitted="VisiblePath_QuerySubmitted"
234234
ScrollViewer.HorizontalScrollBarVisibility="Auto"
235235
ScrollViewer.VerticalScrollBarVisibility="Hidden"
236-
Text="{x:Bind ViewModel.PathText, Mode=OneWay}"
236+
Text="{x:Bind ViewModel.LegacySharedPathPaletteText, Mode=OneWay}"
237237
TextChanged="{x:Bind ViewModel.VisiblePath_TextChanged, Mode=OneWay}"
238238
TextMemberPath="Text"
239239
Visibility="{x:Bind converters:MultiBooleanConverter.OrNotConvertToVisibility(ShowSearchBox, ViewModel.IsSearchBoxVisible), Mode=OneWay}">
@@ -338,15 +338,16 @@
338338
<controls:Omnibar
339339
x:Name="Omnibar"
340340
Grid.Column="1"
341-
x:Load="{x:Bind ViewModel.EnableOmnibar, Mode=OneWay}">
341+
x:Load="{x:Bind ViewModel.EnableOmnibar, Mode=OneWay}"
342+
IsFocused="{x:Bind ViewModel.IsOmnibarFocused, Mode=TwoWay}">
342343

343344
<controls:OmnibarMode
344345
IconOnActive="{controls:ThemedIconMarkup Style={StaticResource App.ThemedIcons.Omnibar.Path}, IsFilled=True}"
345346
IconOnInactive="{controls:ThemedIconMarkup Style={StaticResource App.ThemedIcons.Omnibar.Path}, IconType=Outline}"
346347
IsDefault="True"
347348
ModeName="{helpers:ResourceString Name=Path}"
348349
PlaceholderText="{helpers:ResourceString Name=OmnibarPathModeTextPlaceholder}"
349-
Text="{x:Bind ViewModel.PathText, Mode=OneWay}">
350+
Text="{x:Bind ViewModel.OmnibarPathModeText, Mode=OneWay}">
350351
<controls:OmnibarMode.ContentOnInactive>
351352
<controls:BreadcrumbBar x:Name="NewBreadcrumbBar" ItemsSource="{x:Bind ViewModel.PathComponents, Mode=OneWay}">
352353
<controls:BreadcrumbBar.RootItem>

src/Files.App/ViewModels/UserControls/NavigationToolbarViewModel.cs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,37 @@ public bool IsSearchBoxVisible
182182
}
183183
}
184184

185-
private string? _PathText;
186-
public string? PathText
185+
private string? _LegacySharedPathPaletteText;
186+
[Obsolete("Remove once Omnibar goes out of experimental.")]
187+
public string? LegacySharedPathPaletteText
187188
{
188-
get => _PathText;
189+
get => _LegacySharedPathPaletteText;
189190
set
190191
{
191-
_PathText = value;
192-
OnPropertyChanged(nameof(PathText));
192+
if (SetProperty(ref _LegacySharedPathPaletteText, value))
193+
OnPropertyChanged(nameof(OmnibarPathModeText));
193194
}
194195
}
195196

197+
private bool _IsOmnibarFocused;
198+
public bool IsOmnibarFocused
199+
{
200+
get => _IsOmnibarFocused;
201+
set
202+
{
203+
if (SetProperty(ref _IsOmnibarFocused, value))
204+
{
205+
if (value)
206+
{
207+
EditModeEnabled?.Invoke(this, EventArgs.Empty);
208+
}
209+
}
210+
}
211+
}
212+
213+
private string _OmnibarPathModeText;
214+
public string OmnibarPathModeText { get => _OmnibarPathModeText; set => SetProperty(ref _OmnibarPathModeText, value); }
215+
196216
private CurrentInstanceViewModel _InstanceViewModel;
197217
public CurrentInstanceViewModel InstanceViewModel
198218
{
@@ -210,6 +230,7 @@ public CurrentInstanceViewModel InstanceViewModel
210230
}
211231
}
212232

233+
[Obsolete("Remove once Omnibar goes out of experimental.")]
213234
public bool IsEditModeEnabled
214235
{
215236
get => ManualEntryBoxLoaded;
@@ -589,7 +610,7 @@ public void PathBoxItem_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
589610

590611
public void OpenCommandPalette()
591612
{
592-
PathText = ">";
613+
LegacySharedPathPaletteText = ">";
593614
IsCommandPaletteOpen = true;
594615
ManualEntryBoxLoaded = true;
595616
ClickablePathLoaded = false;

src/Files.App/Views/Shells/BaseShellPage.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,10 @@ protected void NavigationToolbar_EditModeEnabled(object sender, EventArgs e)
442442
{
443443
ToolbarViewModel.ManualEntryBoxLoaded = true;
444444
ToolbarViewModel.ClickablePathLoaded = false;
445-
ToolbarViewModel.PathText = string.IsNullOrEmpty(ShellViewModel?.WorkingDirectory)
445+
ToolbarViewModel.OmnibarPathModeText = string.IsNullOrEmpty(ShellViewModel?.WorkingDirectory)
446446
? Constants.UserEnvironmentPaths.HomePath
447447
: ShellViewModel.WorkingDirectory;
448+
ToolbarViewModel.LegacySharedPathPaletteText = ToolbarViewModel.OmnibarPathModeText;
448449
}
449450

450451
protected async void DrivesManager_PropertyChanged(object sender, PropertyChangedEventArgs e)

0 commit comments

Comments
 (0)