Skip to content

Commit 2460818

Browse files
committed
Fix: Fixed issue where new tab was selected
1 parent 3b59c34 commit 2460818

18 files changed

+33
-32
lines changed

src/Files.App/Actions/Content/Tags/OpenAllTaggedActions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public async Task ExecuteAsync()
3939
await Task.WhenAll(files.Select(file
4040
=> NavigationHelpers.OpenPath(file.path, _pageContext.ShellPage!)));
4141

42-
folders.ForEach(async folder => await NavigationHelpers.OpenPathInNewTab(folder.path));
42+
folders.ForEach(async folder => await NavigationHelpers.OpenPathInNewTab(folder.path, false));
4343
}
4444

4545
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)

src/Files.App/Actions/Navigation/DuplicateCurrentTabAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public async Task ExecuteAsync()
2424

2525
if (arguments is null)
2626
{
27-
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), "Home");
27+
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), "Home", true);
2828
}
2929
else
3030
{

src/Files.App/Actions/Navigation/DuplicateSelectedTabAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public async Task ExecuteAsync()
3131

3232
if (arguments is null)
3333
{
34-
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), "Home");
34+
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), "Home", true);
3535
}
3636
else
3737
{

src/Files.App/Actions/Navigation/OpenDirectoryInNewTabAction.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () =>
4444
{
4545
await NavigationHelpers.AddNewTabByPathAsync(
4646
typeof(PaneHolderPage),
47-
(listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath);
47+
(listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath,
48+
false);
4849
},
4950
Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);
5051
}

src/Files.App/Helpers/Navigation/NavigationHelpers.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT License. See the LICENSE.
33

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

20-
public static Task OpenPathInNewTab(string? path)
19+
public static Task OpenPathInNewTab(string? path, bool focusNewTab)
2120
{
22-
return AddNewTabByPathAsync(typeof(PaneHolderPage), path);
21+
return AddNewTabByPathAsync(typeof(PaneHolderPage), path, focusNewTab);
2322
}
2423

2524
public static Task AddNewTabAsync()
2625
{
27-
return AddNewTabByPathAsync(typeof(PaneHolderPage), "Home");
26+
return AddNewTabByPathAsync(typeof(PaneHolderPage), "Home", true);
2827
}
2928

30-
public static async Task AddNewTabByPathAsync(Type type, string? path, int atIndex = -1)
29+
public static async Task AddNewTabByPathAsync(Type type, string? path, bool focusNewTab, int atIndex = -1)
3130
{
3231
if (string.IsNullOrEmpty(path))
3332
{
@@ -60,7 +59,8 @@ public static async Task AddNewTabByPathAsync(Type type, string? path, int atInd
6059

6160
MainPageViewModel.AppInstances.Insert(index, tabItem);
6261

63-
App.AppModel.TabStripSelectedIndex = index;
62+
if (focusNewTab)
63+
App.AppModel.TabStripSelectedIndex = index;
6464
}
6565

6666
public static async Task AddNewTabByParamAsync(Type type, object tabViewItemArgs, int atIndex = -1)
@@ -358,7 +358,7 @@ public static async Task<bool> OpenPath(string path, IShellPage associatedInstan
358358
}
359359
else
360360
{
361-
await NavigationHelpers.OpenPathInNewTab(path);
361+
await NavigationHelpers.OpenPathInNewTab(path, true);
362362
}
363363

364364
return true;
@@ -651,7 +651,7 @@ private static async Task OpenPathAsync(bool forceOpenInNewTab, bool openFolderI
651651
{
652652
if (forceOpenInNewTab || openFolderInNewTabSetting)
653653
{
654-
await OpenPathInNewTab(text);
654+
await OpenPathInNewTab(text, true);
655655
}
656656
else
657657
{

src/Files.App/MainWindow.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public async Task InitializeApplicationAsync(object activatedEventArgs)
9494
else if (!(string.IsNullOrEmpty(launchArgs.Arguments) && MainPageViewModel.AppInstances.Count > 0))
9595
{
9696
InteropHelpers.SwitchToThisWindow(WindowHandle, true);
97-
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), launchArgs.Arguments);
97+
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), launchArgs.Arguments, true);
9898
}
9999
else
100100
{
@@ -174,7 +174,7 @@ public async Task InitializeApplicationAsync(object activatedEventArgs)
174174
InteropHelpers.SwitchToThisWindow(WindowHandle, true);
175175
for (; index < fileArgs.Files.Count; index++)
176176
{
177-
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), fileArgs.Files[index].Path);
177+
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), fileArgs.Files[index].Path, true);
178178
}
179179
break;
180180

src/Files.App/UserControls/Widgets/BaseWidgetViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void Button_RightTapped(object sender, RightTappedRoutedEventArgs e)
9393

9494
public async Task OpenInNewTabAsync(WidgetCardItem item)
9595
{
96-
await NavigationHelpers.OpenPathInNewTab(item.Path);
96+
await NavigationHelpers.OpenPathInNewTab(item.Path, false);
9797
}
9898

9999
public async Task OpenInNewWindowAsync(WidgetCardItem item)

src/Files.App/UserControls/Widgets/DrivesWidget.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ private async void Button_Click(object sender, RoutedEventArgs e)
266266
var ctrlPressed = Microsoft.UI.Input.InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
267267
if (ctrlPressed)
268268
{
269-
await NavigationHelpers.OpenPathInNewTab(NavigationPath);
269+
await NavigationHelpers.OpenPathInNewTab(NavigationPath, false);
270270
return;
271271
}
272272

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

289289
public class DrivesWidgetInvokedEventArgs : EventArgs

src/Files.App/UserControls/Widgets/QuickAccessWidget.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ private async void Button_PointerPressed(object sender, PointerRoutedEventArgs e
279279
if (e.GetCurrentPoint(null).Properties.IsMiddleButtonPressed) // check middle click
280280
{
281281
string navigationPath = ((Button)sender).Tag.ToString()!;
282-
await NavigationHelpers.OpenPathInNewTab(navigationPath);
282+
await NavigationHelpers.OpenPathInNewTab(navigationPath, false);
283283
}
284284
}
285285

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

src/Files.App/ViewModels/Layouts/BaseLayoutViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ private async Task ItemPointerPressedAsync(PointerRoutedEventArgs e)
6161
_associatedInstance.SlimContentPage.IsMiddleClickToScrollEnabled = true;
6262

6363
if (Item.IsShortcut)
64-
await NavigationHelpers.OpenPathInNewTab(((e.OriginalSource as FrameworkElement)?.DataContext as ShortcutItem)?.TargetPath ?? Item.ItemPath);
64+
await NavigationHelpers.OpenPathInNewTab(((e.OriginalSource as FrameworkElement)?.DataContext as ShortcutItem)?.TargetPath ?? Item.ItemPath, false);
6565
else
66-
await NavigationHelpers.OpenPathInNewTab(Item.ItemPath);
66+
await NavigationHelpers.OpenPathInNewTab(Item.ItemPath, false);
6767
}
6868
}
6969

0 commit comments

Comments
 (0)