Skip to content

Commit

Permalink
Fix: Fixed issue where new tab was selected
Browse files Browse the repository at this point in the history
  • Loading branch information
yaira2 committed Mar 4, 2024
1 parent 3b59c34 commit 2460818
Show file tree
Hide file tree
Showing 18 changed files with 33 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/Files.App/Actions/Content/Tags/OpenAllTaggedActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task ExecuteAsync()
await Task.WhenAll(files.Select(file
=> NavigationHelpers.OpenPath(file.path, _pageContext.ShellPage!)));

folders.ForEach(async folder => await NavigationHelpers.OpenPathInNewTab(folder.path));
folders.ForEach(async folder => await NavigationHelpers.OpenPathInNewTab(folder.path, false));
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task ExecuteAsync()

if (arguments is null)
{
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), "Home");
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), "Home", true);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task ExecuteAsync()

if (arguments is null)
{
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), "Home");
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), "Home", true);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () =>
{
await NavigationHelpers.AddNewTabByPathAsync(
typeof(PaneHolderPage),
(listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath);
(listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath,
false);
},
Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);
}
Expand Down
16 changes: 8 additions & 8 deletions src/Files.App/Helpers/Navigation/NavigationHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License. See the LICENSE.

using Files.Shared.Helpers;
using Microsoft.Extensions.Logging;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media.Imaging;
using Windows.Storage;
Expand All @@ -17,17 +16,17 @@ public static class NavigationHelpers
private static DrivesViewModel DrivesViewModel { get; } = Ioc.Default.GetRequiredService<DrivesViewModel>();
private static NetworkDrivesViewModel NetworkDrivesViewModel { get; } = Ioc.Default.GetRequiredService<NetworkDrivesViewModel>();

public static Task OpenPathInNewTab(string? path)
public static Task OpenPathInNewTab(string? path, bool focusNewTab)
{
return AddNewTabByPathAsync(typeof(PaneHolderPage), path);
return AddNewTabByPathAsync(typeof(PaneHolderPage), path, focusNewTab);
}

public static Task AddNewTabAsync()
{
return AddNewTabByPathAsync(typeof(PaneHolderPage), "Home");
return AddNewTabByPathAsync(typeof(PaneHolderPage), "Home", true);
}

public static async Task AddNewTabByPathAsync(Type type, string? path, int atIndex = -1)
public static async Task AddNewTabByPathAsync(Type type, string? path, bool focusNewTab, int atIndex = -1)
{
if (string.IsNullOrEmpty(path))
{
Expand Down Expand Up @@ -60,7 +59,8 @@ public static async Task AddNewTabByPathAsync(Type type, string? path, int atInd

MainPageViewModel.AppInstances.Insert(index, tabItem);

App.AppModel.TabStripSelectedIndex = index;
if (focusNewTab)
App.AppModel.TabStripSelectedIndex = index;
}

public static async Task AddNewTabByParamAsync(Type type, object tabViewItemArgs, int atIndex = -1)
Expand Down Expand Up @@ -358,7 +358,7 @@ public static async Task<bool> OpenPath(string path, IShellPage associatedInstan
}
else
{
await NavigationHelpers.OpenPathInNewTab(path);
await NavigationHelpers.OpenPathInNewTab(path, true);
}

return true;
Expand Down Expand Up @@ -651,7 +651,7 @@ private static async Task OpenPathAsync(bool forceOpenInNewTab, bool openFolderI
{
if (forceOpenInNewTab || openFolderInNewTabSetting)
{
await OpenPathInNewTab(text);
await OpenPathInNewTab(text, true);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public async Task InitializeApplicationAsync(object activatedEventArgs)
else if (!(string.IsNullOrEmpty(launchArgs.Arguments) && MainPageViewModel.AppInstances.Count > 0))
{
InteropHelpers.SwitchToThisWindow(WindowHandle, true);
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), launchArgs.Arguments);
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), launchArgs.Arguments, true);
}
else
{
Expand Down Expand Up @@ -174,7 +174,7 @@ public async Task InitializeApplicationAsync(object activatedEventArgs)
InteropHelpers.SwitchToThisWindow(WindowHandle, true);
for (; index < fileArgs.Files.Count; index++)
{
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), fileArgs.Files[index].Path);
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), fileArgs.Files[index].Path, true);
}
break;

Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/UserControls/Widgets/BaseWidgetViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void Button_RightTapped(object sender, RightTappedRoutedEventArgs e)

public async Task OpenInNewTabAsync(WidgetCardItem item)
{
await NavigationHelpers.OpenPathInNewTab(item.Path);
await NavigationHelpers.OpenPathInNewTab(item.Path, false);
}

public async Task OpenInNewWindowAsync(WidgetCardItem item)
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/UserControls/Widgets/DrivesWidget.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private async void Button_Click(object sender, RoutedEventArgs e)
var ctrlPressed = Microsoft.UI.Input.InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
if (ctrlPressed)
{
await NavigationHelpers.OpenPathInNewTab(NavigationPath);
await NavigationHelpers.OpenPathInNewTab(NavigationPath, false);
return;
}

Expand All @@ -283,7 +283,7 @@ private async void Button_PointerPressed(object sender, PointerRoutedEventArgs e
string navigationPath = (sender as Button).Tag.ToString();
if (await DriveHelpers.CheckEmptyDrive(navigationPath))
return;
await NavigationHelpers.OpenPathInNewTab(navigationPath);
await NavigationHelpers.OpenPathInNewTab(navigationPath, false);
}

public class DrivesWidgetInvokedEventArgs : EventArgs
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/UserControls/Widgets/QuickAccessWidget.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ private async void Button_PointerPressed(object sender, PointerRoutedEventArgs e
if (e.GetCurrentPoint(null).Properties.IsMiddleButtonPressed) // check middle click
{
string navigationPath = ((Button)sender).Tag.ToString()!;
await NavigationHelpers.OpenPathInNewTab(navigationPath);
await NavigationHelpers.OpenPathInNewTab(navigationPath, false);
}
}

Expand Down Expand Up @@ -337,7 +337,7 @@ private async void Button_Click(object sender, RoutedEventArgs e)
var ctrlPressed = Microsoft.UI.Input.InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
if (ctrlPressed)
{
await NavigationHelpers.OpenPathInNewTab(NavigationPath);
await NavigationHelpers.OpenPathInNewTab(NavigationPath, false);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/ViewModels/Layouts/BaseLayoutViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ private async Task ItemPointerPressedAsync(PointerRoutedEventArgs e)
_associatedInstance.SlimContentPage.IsMiddleClickToScrollEnabled = true;

if (Item.IsShortcut)
await NavigationHelpers.OpenPathInNewTab(((e.OriginalSource as FrameworkElement)?.DataContext as ShortcutItem)?.TargetPath ?? Item.ItemPath);
await NavigationHelpers.OpenPathInNewTab(((e.OriginalSource as FrameworkElement)?.DataContext as ShortcutItem)?.TargetPath ?? Item.ItemPath, false);
else
await NavigationHelpers.OpenPathInNewTab(Item.ItemPath);
await NavigationHelpers.OpenPathInNewTab(Item.ItemPath, false);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Files.App/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public async Task OnNavigatedToAsync(NavigationEventArgs e)
UserSettingsService.GeneralSettingsService.TabsOnStartupList is not null)
{
foreach (string path in UserSettingsService.GeneralSettingsService.TabsOnStartupList)
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), path);
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), path, true);
}
else if (UserSettingsService.GeneralSettingsService.ContinueLastSessionOnStartUp &&
UserSettingsService.GeneralSettingsService.LastSessionTabList is not null)
Expand Down Expand Up @@ -155,7 +155,7 @@ public async Task OnNavigatedToAsync(NavigationEventArgs e)
UserSettingsService.GeneralSettingsService.TabsOnStartupList is not null)
{
foreach (string path in UserSettingsService.GeneralSettingsService.TabsOnStartupList)
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), path);
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), path, true);
}
else if (UserSettingsService.GeneralSettingsService.ContinueLastSessionOnStartUp &&
UserSettingsService.GeneralSettingsService.LastSessionTabList is not null)
Expand All @@ -175,7 +175,7 @@ public async Task OnNavigatedToAsync(NavigationEventArgs e)
}

if (parameter is string navArgs)
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), navArgs);
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), navArgs, true);
else if (parameter is PaneNavigationArguments paneArgs)
await NavigationHelpers.AddNewTabByParamAsync(typeof(PaneHolderPage), paneArgs);
else if (parameter is CustomTabViewItemParameter tabArgs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public override void GetBaseProperties()
else
{
await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(
() => NavigationHelpers.OpenPathInNewTab(Path.GetDirectoryName(ViewModel.ShortcutItemPath)));
() => NavigationHelpers.OpenPathInNewTab(Path.GetDirectoryName(ViewModel.ShortcutItemPath), true));
}
},
() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public override void GetBaseProperties()
ViewModel.ShortcutItemOpenLinkCommand = new RelayCommand(async () =>
{
await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(
() => NavigationHelpers.OpenPathInNewTab(Path.GetDirectoryName(Environment.ExpandEnvironmentVariables(ViewModel.ShortcutItemPath))));
() => NavigationHelpers.OpenPathInNewTab(Path.GetDirectoryName(Environment.ExpandEnvironmentVariables(ViewModel.ShortcutItemPath)), true));
},
() =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ public async Task PathBoxItem_Tapped(object sender, TappedRoutedEventArgs e)
{
await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () =>
{
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), itemTappedPath);
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), itemTappedPath, true);
}, DispatcherQueuePriority.Low);
e.Handled = true;
pointerRoutedEventArgs = null;
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/ViewModels/UserControls/SidebarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ public async void HandleItemInvokedAsync(object item, PointerUpdateKind pointerU
middleClickPressed) &&
navigationControlItem.Path is not null)
{
await NavigationHelpers.OpenPathInNewTab(navigationControlItem.Path);
await NavigationHelpers.OpenPathInNewTab(navigationControlItem.Path, false);
return;
}

Expand Down Expand Up @@ -831,7 +831,7 @@ private async Task OpenInNewTabAsync()
if (await DriveHelpers.CheckEmptyDrive(rightClickedItem.Path))
return;

await NavigationHelpers.OpenPathInNewTab(rightClickedItem.Path);
await NavigationHelpers.OpenPathInNewTab(rightClickedItem.Path, false);
}

private async Task OpenInNewWindowAsync()
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Views/Layouts/DetailsLayoutPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ protected override async void FileList_PreviewKeyDown(object sender, KeyRoutedEv
if (folders is not null)
{
foreach (ListedItem folder in folders)
await NavigationHelpers.OpenPathInNewTab(folder.ItemPath);
await NavigationHelpers.OpenPathInNewTab(folder.ItemPath, false);
}
}
else if (ctrlPressed && shiftPressed)
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ protected override async void FileList_PreviewKeyDown(object sender, KeyRoutedEv
foreach (ListedItem? folder in folders)
{
if (folder is not null)
await NavigationHelpers.OpenPathInNewTab(folder.ItemPath);
await NavigationHelpers.OpenPathInNewTab(folder.ItemPath, false);
}
}
else if (ctrlPressed && shiftPressed)
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ private async void HorizontalMultitaskingControlAddButton_Drop(object sender, Dr
try
{
foreach (var item in items)
await NavigationHelpers.OpenPathInNewTab(item.Path);
await NavigationHelpers.OpenPathInNewTab(item.Path, true);

deferral.Complete();
}
Expand Down

0 comments on commit 2460818

Please sign in to comment.