Skip to content

Commit 0ed611a

Browse files
committed
WIP auto focus impl
1 parent 7951949 commit 0ed611a

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
@@ -228,29 +228,29 @@ public bool IsOmnibarFocused
228228
get => _IsOmnibarFocused;
229229
set
230230
{
231-
if (SetProperty(ref _IsOmnibarFocused, value))
231+
// NOTE: Don't call ObservableObject.SetProperty() here since we don't want to change focus logic outside of the control.
232+
233+
_IsOmnibarFocused = value;
234+
235+
if (value)
232236
{
233-
if (value)
237+
switch (OmnibarCurrentSelectedMode.Name)
234238
{
235-
switch (OmnibarCurrentSelectedMode.Name)
236-
{
237-
case OmnibarPathModeName:
238-
PathText =
239-
string.IsNullOrEmpty(ContentPageContext.ShellPage?.ShellViewModel?.WorkingDirectory)
240-
? Constants.UserEnvironmentPaths.HomePath
241-
: ContentPageContext.ShellPage.ShellViewModel.WorkingDirectory;
242-
_ = PopulateOmnibarSuggestionsForPathMode();
243-
break;
244-
case OmnibarPaletteModeName:
245-
if (OmnibarCommandPaletteModeSuggestionItems.Count is 0)
246-
PopulateOmnibarSuggestionsForCommandPaletteMode();
247-
break;
248-
case OmnibarSearchModeName:
249-
break;
250-
default:
251-
break;
252-
}
253-
239+
case OmnibarPathModeName:
240+
PathText =
241+
string.IsNullOrEmpty(ContentPageContext.ShellPage?.ShellViewModel?.WorkingDirectory)
242+
? Constants.UserEnvironmentPaths.HomePath
243+
: ContentPageContext.ShellPage.ShellViewModel.WorkingDirectory;
244+
_ = PopulateOmnibarSuggestionsForPathMode();
245+
break;
246+
case OmnibarPaletteModeName:
247+
if (OmnibarCommandPaletteModeSuggestionItems.Count is 0)
248+
PopulateOmnibarSuggestionsForCommandPaletteMode();
249+
break;
250+
case OmnibarSearchModeName:
251+
break;
252+
default:
253+
break;
254254
}
255255
}
256256
}

0 commit comments

Comments
 (0)