Skip to content

Commit 81d9e3d

Browse files
authored
Feature: Added shortcut for opening folders in secondary pane (#10966)
1 parent d143234 commit 81d9e3d

File tree

6 files changed

+40
-11
lines changed

6 files changed

+40
-11
lines changed

src/Files.App/Helpers/ContextFlyoutItemHelper.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(BaseLayo
658658
Tag = "OpenWith",
659659
CollapseLabel = true,
660660
ShowInSearchPage = true,
661-
ShowItem = selectedItems.All(i => (i.PrimaryItemAttribute == Windows.Storage.StorageItemTypes.File && !i.IsShortcut && !i.IsExecutable) || (i.PrimaryItemAttribute == Windows.Storage.StorageItemTypes.Folder && i.IsArchive)),
661+
ShowItem = selectedItems.All(i => (i.PrimaryItemAttribute == StorageItemTypes.File && !i.IsShortcut && !i.IsExecutable) || (i.PrimaryItemAttribute == StorageItemTypes.Folder && i.IsArchive)),
662662
},
663663
new ContextMenuFlyoutItemViewModel()
664664
{
@@ -675,7 +675,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(BaseLayo
675675
}
676676
},
677677
ShowInSearchPage = true,
678-
ShowItem = selectedItems.All(i => (i.PrimaryItemAttribute == Windows.Storage.StorageItemTypes.File && !i.IsShortcut && !i.IsExecutable) || (i.PrimaryItemAttribute == Windows.Storage.StorageItemTypes.Folder && i.IsArchive)),
678+
ShowItem = selectedItems.All(i => (i.PrimaryItemAttribute == StorageItemTypes.File && !i.IsShortcut && !i.IsExecutable) || (i.PrimaryItemAttribute == StorageItemTypes.Folder && i.IsArchive)),
679679
},
680680
new ContextMenuFlyoutItemViewModel()
681681
{
@@ -688,10 +688,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(BaseLayo
688688
new ContextMenuFlyoutItemViewModel()
689689
{
690690
Text = "BaseLayoutItemContextFlyoutOpenInNewPane/Text".GetLocalizedResource(),
691-
Glyph = "\uE117",
691+
Glyph = "\xF117",
692692
GlyphFontFamilyName = "CustomGlyph",
693693
Command = commandsViewModel.OpenDirectoryInNewPaneCommand,
694-
ShowItem = userSettingsService.PreferencesSettingsService.IsDualPaneEnabled && selectedItems.All(i => i.PrimaryItemAttribute == Windows.Storage.StorageItemTypes.Folder),
694+
ShowItem = userSettingsService.PreferencesSettingsService.IsDualPaneEnabled && selectedItems.All(i => i.PrimaryItemAttribute == StorageItemTypes.Folder),
695695
SingleItemOnly = true,
696696
ShowInSearchPage = true,
697697
ShowInFtpPage = true,
@@ -703,7 +703,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(BaseLayo
703703
Glyph = "\uF113",
704704
GlyphFontFamilyName = "CustomGlyph",
705705
Command = commandsViewModel.OpenDirectoryInNewTabCommand,
706-
ShowItem = selectedItems.Count < 5 && selectedItems.All(i => i.PrimaryItemAttribute == Windows.Storage.StorageItemTypes.Folder),
706+
ShowItem = selectedItems.Count < 5 && selectedItems.All(i => i.PrimaryItemAttribute == StorageItemTypes.Folder),
707707
ShowInSearchPage = true,
708708
ShowInFtpPage = true,
709709
ShowInZipPage = true,
@@ -713,7 +713,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(BaseLayo
713713
Text = "BaseLayoutItemContextFlyoutOpenInNewWindow/Text".GetLocalizedResource(),
714714
Glyph = "\uE737",
715715
Command = commandsViewModel.OpenInNewWindowItemCommand,
716-
ShowItem = selectedItems.Count < 5 && selectedItems.All(i => i.PrimaryItemAttribute == Windows.Storage.StorageItemTypes.Folder),
716+
ShowItem = selectedItems.Count < 5 && selectedItems.All(i => i.PrimaryItemAttribute == StorageItemTypes.Folder),
717717
ShowInSearchPage = true,
718718
ShowInFtpPage = true,
719719
ShowOnShift = true,

src/Files.App/Helpers/NavigationHelpers.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Files.App.Extensions;
33
using Files.App.Filesystem;
44
using Files.App.Filesystem.StorageItems;
5+
using Files.App.ServicesImplementation.Settings;
56
using Files.App.Shell;
67
using Files.App.ViewModels;
78
using Files.App.Views;
@@ -21,6 +22,8 @@ namespace Files.App.Helpers
2122
{
2223
public static class NavigationHelpers
2324
{
25+
private static readonly IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
26+
2427
public static Task OpenPathInNewTab(string path)
2528
=> MainPageViewModel.AddNewTabByPathAsync(typeof(PaneHolderPage), path);
2629

@@ -36,6 +39,17 @@ public static Task<bool> OpenTabInNewWindowAsync(string tabArgs)
3639
return Launcher.LaunchUriAsync(folderUri).AsTask();
3740
}
3841

42+
public static void OpenInSecondaryPane(IShellPage associatedInstance, ListedItem listedItem)
43+
{
44+
if(associatedInstance is null || listedItem is null)
45+
return;
46+
47+
if (!userSettingsService.PreferencesSettingsService.IsDualPaneEnabled)
48+
return;
49+
50+
associatedInstance.PaneHolder?.OpenPathInNewPane((listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath);
51+
}
52+
3953
public static Task LaunchNewWindowAsync()
4054
{
4155
var filesUWPUri = new Uri("files-uwp:");

src/Files.App/Interacts/BaseLayoutCommandImplementationModel.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,7 @@ await App.Window.DispatcherQueue.EnqueueAsync(async () =>
261261

262262
public virtual void OpenDirectoryInNewPane(RoutedEventArgs e)
263263
{
264-
ListedItem listedItem = SlimContentPage.SelectedItems.FirstOrDefault();
265-
if (listedItem is not null)
266-
associatedInstance.PaneHolder?.OpenPathInNewPane((listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath);
264+
NavigationHelpers.OpenInSecondaryPane(associatedInstance, SlimContentPage.SelectedItems.FirstOrDefault());
267265
}
268266

269267
public virtual async void OpenInNewWindowItem(RoutedEventArgs e)

src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ private void FileList_PreviewKeyUp(object sender, KeyRoutedEventArgs e)
402402

403403
private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
404404
{
405+
if (ParentShellPageInstance is null)
406+
return;
407+
405408
var ctrlPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
406409
var shiftPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down);
407410

src/Files.App/Views/LayoutModes/DetailsLayoutBrowser.xaml.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,9 @@ private void EndRename(TextBox textBox)
420420

421421
private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
422422
{
423+
if (ParentShellPageInstance is null)
424+
return;
425+
423426
var ctrlPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
424427
var shiftPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down);
425428
var focusedElement = (FrameworkElement)FocusManager.GetFocusedElement(XamlRoot);
@@ -433,7 +436,7 @@ private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
433436

434437
e.Handled = true;
435438

436-
if (ctrlPressed)
439+
if (ctrlPressed && !shiftPressed)
437440
{
438441
var folders = ParentShellPageInstance?.SlimContentPage.SelectedItems?.Where(file => file.PrimaryItemAttribute == StorageItemTypes.Folder);
439442
foreach (ListedItem? folder in folders)
@@ -442,6 +445,10 @@ private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
442445
await NavigationHelpers.OpenPathInNewTab(folder.ItemPath);
443446
}
444447
}
448+
else if(ctrlPressed && shiftPressed)
449+
{
450+
NavigationHelpers.OpenInSecondaryPane(ParentShellPageInstance, SelectedItems.FirstOrDefault(item => item.PrimaryItemAttribute == StorageItemTypes.Folder));
451+
}
445452
else
446453
{
447454
await NavigationHelpers.OpenSelectedItems(ParentShellPageInstance, false);

src/Files.App/Views/LayoutModes/GridViewBrowser.xaml.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,9 @@ private void EndRename(TextBox textBox)
373373

374374
private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
375375
{
376+
if (ParentShellPageInstance is null)
377+
return;
378+
376379
var ctrlPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
377380
var shiftPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down);
378381
var focusedElement = FocusManager.GetFocusedElement(XamlRoot) as FrameworkElement;
@@ -385,7 +388,7 @@ private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
385388

386389
e.Handled = true;
387390

388-
if (ctrlPressed)
391+
if (ctrlPressed && !shiftPressed)
389392
{
390393
var folders = ParentShellPageInstance?.SlimContentPage.SelectedItems?.Where(file => file.PrimaryItemAttribute == StorageItemTypes.Folder);
391394
foreach (ListedItem? folder in folders)
@@ -394,6 +397,10 @@ private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
394397
await NavigationHelpers.OpenPathInNewTab(folder.ItemPath);
395398
}
396399
}
400+
else if (ctrlPressed && shiftPressed)
401+
{
402+
NavigationHelpers.OpenInSecondaryPane(ParentShellPageInstance, SelectedItems.FirstOrDefault(item => item.PrimaryItemAttribute == StorageItemTypes.Folder));
403+
}
397404
else
398405
{
399406
await NavigationHelpers.OpenSelectedItems(ParentShellPageInstance, false);

0 commit comments

Comments
 (0)