Skip to content

Commit 98951ff

Browse files
committed
WIP auto focus impl
1 parent c7e1e19 commit 98951ff

File tree

7 files changed

+49
-61
lines changed

7 files changed

+49
-61
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ partial void OnIsFocusedChanged(bool newValue)
5151
if (CurrentSelectedMode is null || _textBox is null)
5252
return;
5353

54-
_textBox.Focus(FocusState.Keyboard);
55-
5654
if (newValue)
5755
{
5856
VisualStateManager.GoToState(CurrentSelectedMode, "Focused", true);

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ protected void ChangeMode(OmnibarMode? oldMode, OmnibarMode newMode)
114114
// Add the reposition transition to the all modes
115115
mode.Transitions = [new RepositionThemeTransition()];
116116
mode.UpdateLayout();
117-
118-
mode.OnChangingCurrentMode(false);
117+
mode.IsTabStop = true;
119118
}
120119

121120
var index = _modesHostGrid.Children.IndexOf(newMode);
@@ -145,24 +144,30 @@ protected void ChangeMode(OmnibarMode? oldMode, OmnibarMode newMode)
145144
ChangeTextBoxText(newMode.Text ?? string.Empty);
146145

147146
VisualStateManager.GoToState(newMode, "Focused", true);
148-
newMode.OnChangingCurrentMode(true);
149-
150-
if (IsFocused)
151-
{
152-
VisualStateManager.GoToState(newMode, "Focused", true);
153-
VisualStateManager.GoToState(_textBox, "InputAreaVisible", true);
154-
}
155-
else if (newMode?.ContentOnInactive is not null)
147+
newMode.IsTabStop = false;
148+
if (newMode.IsAutoFocusEnabled)
156149
{
157-
VisualStateManager.GoToState(newMode, "CurrentUnfocused", true);
158-
VisualStateManager.GoToState(_textBox, "InputAreaCollapsed", true);
150+
_textBox.Focus(FocusState.Pointer);
159151
}
160152
else
161153
{
162-
VisualStateManager.GoToState(_textBox, "InputAreaVisible", true);
163-
}
154+
if (IsFocused)
155+
{
156+
VisualStateManager.GoToState(newMode, "Focused", true);
157+
VisualStateManager.GoToState(_textBox, "InputAreaVisible", true);
158+
}
159+
else if (newMode?.ContentOnInactive is not null)
160+
{
161+
VisualStateManager.GoToState(newMode, "CurrentUnfocused", true);
162+
VisualStateManager.GoToState(_textBox, "InputAreaCollapsed", true);
163+
}
164+
else
165+
{
166+
VisualStateManager.GoToState(_textBox, "InputAreaVisible", true);
167+
}
164168

165-
TryToggleIsSuggestionsPopupOpen(IsFocused && newMode?.SuggestionItemsSource is not null);
169+
TryToggleIsSuggestionsPopupOpen(true);
170+
}
166171

167172
// Remove the reposition transition from the all modes
168173
foreach (var mode in Modes)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public partial class OmnibarMode
4343
[GeneratedDependencyProperty(DefaultValue = true)]
4444
public partial bool UpdateTextOnSelect { get; set; }
4545

46+
[GeneratedDependencyProperty]
47+
public partial bool IsAutoFocusEnabled { get; set; }
48+
4649
partial void OnTextChanged(string? newValue)
4750
{
4851
if (_ownerRef is null || _ownerRef.TryGetTarget(out var owner) is false)

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ public void SetOwner(Omnibar owner)
7878
_ownerRef = new(owner);
7979
}
8080

81-
public void OnChangingCurrentMode(bool isCurrentMode)
82-
{
83-
_modeButton.IsTabStop = !isCurrentMode;
84-
}
85-
8681
public override string ToString()
8782
{
8883
return ModeName ?? string.Empty;

src/Files.App/UserControls/NavigationToolbar.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@
324324
CurrentSelectedModeName="{x:Bind ViewModel.OmnibarCurrentSelectedModeName, Mode=TwoWay}"
325325
IsFocused="{x:Bind ViewModel.IsOmnibarFocused, Mode=TwoWay}"
326326
QuerySubmitted="Omnibar_QuerySubmitted"
327-
SuggestionChosen="Omnibar_SuggestionChosen"
328327
TextChanged="Omnibar_TextChanged">
329328

330329
<controls:OmnibarMode
@@ -368,6 +367,7 @@
368367
x:Name="OmnibarCommandPaletteMode"
369368
IconOnActive="{controls:ThemedIconMarkup Style={StaticResource App.ThemedIcons.Omnibar.Commands}, IsFilled=True}"
370369
IconOnInactive="{controls:ThemedIconMarkup Style={StaticResource App.ThemedIcons.Omnibar.Commands}, IconType=Outline}"
370+
IsAutoFocusEnabled="True"
371371
ModeName="{x:Bind Commands.OpenCommandPalette.LabelWithHotKey, Mode=OneWay}"
372372
PlaceholderText="{helpers:ResourceString Name=OmnibarCommandPaletteModeTextPlaceholder}"
373373
SuggestionItemsSource="{x:Bind ViewModel.OmnibarCommandPaletteModeSuggestionItems, Mode=OneWay}"

src/Files.App/UserControls/NavigationToolbar.xaml.cs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -262,23 +262,7 @@ private async void Omnibar_QuerySubmitted(Omnibar sender, OmnibarQuerySubmittedE
262262
}
263263
else if (Omnibar.CurrentSelectedMode == OmnibarCommandPaletteMode)
264264
{
265-
}
266-
else if (Omnibar.CurrentSelectedMode == OmnibarSearchMode)
267-
{
268-
}
269-
}
270-
271-
private async void Omnibar_SuggestionChosen(Omnibar sender, OmnibarSuggestionChosenEventArgs args)
272-
{
273-
if (Omnibar.CurrentSelectedMode == OmnibarPathMode)
274-
{
275-
if (args.SelectedItem is OmnibarPathModeSuggestionModel item &&
276-
!string.IsNullOrEmpty(item.Path))
277-
await ViewModel.HandleItemNavigationAsync(item.Path);
278-
}
279-
else if (Omnibar.CurrentSelectedMode == OmnibarCommandPaletteMode)
280-
{
281-
if (args.SelectedItem is not NavigationBarSuggestionItem item || item.Text is not { } commandText)
265+
if (args.Item is not NavigationBarSuggestionItem item || item.Text is not { } commandText)
282266
return;
283267

284268
var command = Commands[commandText];
@@ -300,6 +284,9 @@ await DialogDisplayHelper.ShowDialogAsync(Strings.CommandNotExecutable.GetLocali
300284

301285
private async void Omnibar_TextChanged(Omnibar sender, OmnibarTextChangedEventArgs args)
302286
{
287+
if (args.Reason is not OmnibarTextChangeReason.UserInput)
288+
return;
289+
303290
if (Omnibar.CurrentSelectedMode == OmnibarPathMode)
304291
{
305292
await ViewModel.PopulateOmnibarSuggestionsForPathMode();

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -232,29 +232,29 @@ public bool IsOmnibarFocused
232232
get => _IsOmnibarFocused;
233233
set
234234
{
235-
if (SetProperty(ref _IsOmnibarFocused, value))
235+
// NOTE: Don't call ObservableObject.SetProperty() here since we don't want to change focus logic outside of the control.
236+
237+
_IsOmnibarFocused = value;
238+
239+
if (value)
236240
{
237-
if (value)
241+
switch (OmnibarCurrentSelectedMode.Name)
238242
{
239-
switch (OmnibarCurrentSelectedMode.Name)
240-
{
241-
case OmnibarPathModeName:
242-
PathText =
243-
string.IsNullOrEmpty(ContentPageContext.ShellPage?.ShellViewModel?.WorkingDirectory)
244-
? Constants.UserEnvironmentPaths.HomePath
245-
: ContentPageContext.ShellPage.ShellViewModel.WorkingDirectory;
246-
_ = PopulateOmnibarSuggestionsForPathMode();
247-
break;
248-
case OmnibarPaletteModeName:
249-
if (OmnibarCommandPaletteModeSuggestionItems.Count is 0)
250-
PopulateOmnibarSuggestionsForCommandPaletteMode();
251-
break;
252-
case OmnibarSearchModeName:
253-
break;
254-
default:
255-
break;
256-
}
257-
243+
case OmnibarPathModeName:
244+
PathText =
245+
string.IsNullOrEmpty(ContentPageContext.ShellPage?.ShellViewModel?.WorkingDirectory)
246+
? Constants.UserEnvironmentPaths.HomePath
247+
: ContentPageContext.ShellPage.ShellViewModel.WorkingDirectory;
248+
_ = PopulateOmnibarSuggestionsForPathMode();
249+
break;
250+
case OmnibarPaletteModeName:
251+
if (OmnibarCommandPaletteModeSuggestionItems.Count is 0)
252+
PopulateOmnibarSuggestionsForCommandPaletteMode();
253+
break;
254+
case OmnibarSearchModeName:
255+
break;
256+
default:
257+
break;
258258
}
259259
}
260260
}

0 commit comments

Comments
 (0)