Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/Files.App/Actions/Navigation/NextTabAction.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;

namespace Files.App.Actions
{
internal sealed class NextTabAction : ObservableObject, IAction
Expand All @@ -26,11 +29,15 @@ public NextTabAction()
multitaskingContext.PropertyChanged += MultitaskingContext_PropertyChanged;
}

public Task ExecuteAsync(object? parameter = null)
public async Task ExecuteAsync(object? parameter = null)
{
App.AppModel.TabStripSelectedIndex = (App.AppModel.TabStripSelectedIndex + 1) % multitaskingContext.TabCount;

return Task.CompletedTask;
// Small delay for the UI to load
await Task.Delay(500);

// Refocus on the file list
(multitaskingContext.CurrentTabItem.TabItemContent as Control)?.Focus(FocusState.Programmatic);
}

private void MultitaskingContext_PropertyChanged(object? sender, PropertyChangedEventArgs e)
Expand Down
11 changes: 9 additions & 2 deletions src/Files.App/Actions/Navigation/PreviousTabAction.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;

namespace Files.App.Actions
{
internal sealed class PreviousTabAction : ObservableObject, IAction
Expand All @@ -26,14 +29,18 @@ public PreviousTabAction()
multitaskingContext.PropertyChanged += MultitaskingContext_PropertyChanged;
}

public Task ExecuteAsync(object? parameter = null)
public async Task ExecuteAsync(object? parameter = null)
{
if (App.AppModel.TabStripSelectedIndex is 0)
App.AppModel.TabStripSelectedIndex = multitaskingContext.TabCount - 1;
else
App.AppModel.TabStripSelectedIndex--;

return Task.CompletedTask;
// Small delay for the UI to load
await Task.Delay(500);

// Refocus on the file list
(multitaskingContext.CurrentTabItem.TabItemContent as Control)?.Focus(FocusState.Programmatic);
}

private void MultitaskingContext_PropertyChanged(object? sender, PropertyChangedEventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Data/Models/AppModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public int TabStripSelectedIndex

if (value >= 0 && value < MainPageViewModel.AppInstances.Count)
{
Frame rootFrame = (Frame)MainWindow.Instance.Content;
var rootFrame = (Frame)MainWindow.Instance.Content;
var mainView = (MainPage)rootFrame.Content;
mainView.ViewModel.SelectedTabItem = MainPageViewModel.AppInstances[value];
}
Expand Down
13 changes: 11 additions & 2 deletions src/Files.App/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.UI.Xaml.Navigation;
using System.Windows.Input;
using Windows.System;
using Microsoft.UI.Xaml.Controls;

namespace Files.App.ViewModels
{
Expand Down Expand Up @@ -228,9 +229,9 @@ await Task.WhenAll(

// Command methods

private void ExecuteNavigateToNumberedTabKeyboardAcceleratorCommand(KeyboardAcceleratorInvokedEventArgs? e)
private async void ExecuteNavigateToNumberedTabKeyboardAcceleratorCommand(KeyboardAcceleratorInvokedEventArgs? e)
{
int indexToSelect = e!.KeyboardAccelerator.Key switch
var indexToSelect = e!.KeyboardAccelerator.Key switch
{
VirtualKey.Number1 => 0,
VirtualKey.Number2 => 1,
Expand All @@ -246,8 +247,16 @@ private void ExecuteNavigateToNumberedTabKeyboardAcceleratorCommand(KeyboardAcce

// Only select the tab if it is in the list
if (indexToSelect < AppInstances.Count)
{
App.AppModel.TabStripSelectedIndex = indexToSelect;

// Small delay for the UI to load
await Task.Delay(500);

// Refocus on the file list
(SelectedTabItem?.TabItemContent as Control)?.Focus(FocusState.Programmatic);
}

e.Handled = true;
}

Expand Down