From f0315f4a316405a3d32ae62d8f6b1ccac5fd821a Mon Sep 17 00:00:00 2001 From: Quaint Mako <110472580+QuaintMako@users.noreply.github.com> Date: Mon, 9 Jan 2023 13:54:45 +0100 Subject: [PATCH 1/4] Now can open secondary pane with keyboard accelerator --- src/Files.App/Helpers/ContextFlyoutItemHelper.cs | 12 ++++++------ src/Files.App/Helpers/NavigationHelpers.cs | 14 ++++++++++++++ .../BaseLayoutCommandImplementationModel.cs | 4 +--- .../Views/LayoutModes/DetailsLayoutBrowser.xaml.cs | 9 ++++++++- .../Views/LayoutModes/GridViewBrowser.xaml.cs | 6 +++++- 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/Files.App/Helpers/ContextFlyoutItemHelper.cs b/src/Files.App/Helpers/ContextFlyoutItemHelper.cs index 24aa5d46347f..80789ce0f32b 100644 --- a/src/Files.App/Helpers/ContextFlyoutItemHelper.cs +++ b/src/Files.App/Helpers/ContextFlyoutItemHelper.cs @@ -658,7 +658,7 @@ public static List GetBaseItemMenuItems(BaseLayo Tag = "OpenWith", CollapseLabel = true, ShowInSearchPage = true, - ShowItem = selectedItems.All(i => (i.PrimaryItemAttribute == Windows.Storage.StorageItemTypes.File && !i.IsShortcut && !i.IsExecutable) || (i.PrimaryItemAttribute == Windows.Storage.StorageItemTypes.Folder && i.IsArchive)), + ShowItem = selectedItems.All(i => (i.PrimaryItemAttribute == StorageItemTypes.File && !i.IsShortcut && !i.IsExecutable) || (i.PrimaryItemAttribute == StorageItemTypes.Folder && i.IsArchive)), }, new ContextMenuFlyoutItemViewModel() { @@ -675,7 +675,7 @@ public static List GetBaseItemMenuItems(BaseLayo } }, ShowInSearchPage = true, - ShowItem = selectedItems.All(i => (i.PrimaryItemAttribute == Windows.Storage.StorageItemTypes.File && !i.IsShortcut && !i.IsExecutable) || (i.PrimaryItemAttribute == Windows.Storage.StorageItemTypes.Folder && i.IsArchive)), + ShowItem = selectedItems.All(i => (i.PrimaryItemAttribute == StorageItemTypes.File && !i.IsShortcut && !i.IsExecutable) || (i.PrimaryItemAttribute == StorageItemTypes.Folder && i.IsArchive)), }, new ContextMenuFlyoutItemViewModel() { @@ -688,10 +688,10 @@ public static List GetBaseItemMenuItems(BaseLayo new ContextMenuFlyoutItemViewModel() { Text = "BaseLayoutItemContextFlyoutOpenInNewPane/Text".GetLocalizedResource(), - Glyph = "\uE117", + Glyph = "\xF117", GlyphFontFamilyName = "CustomGlyph", Command = commandsViewModel.OpenDirectoryInNewPaneCommand, - ShowItem = userSettingsService.PreferencesSettingsService.IsDualPaneEnabled && selectedItems.All(i => i.PrimaryItemAttribute == Windows.Storage.StorageItemTypes.Folder), + ShowItem = userSettingsService.PreferencesSettingsService.IsDualPaneEnabled && selectedItems.All(i => i.PrimaryItemAttribute == StorageItemTypes.Folder), SingleItemOnly = true, ShowInSearchPage = true, ShowInFtpPage = true, @@ -703,7 +703,7 @@ public static List GetBaseItemMenuItems(BaseLayo Glyph = "\uF113", GlyphFontFamilyName = "CustomGlyph", Command = commandsViewModel.OpenDirectoryInNewTabCommand, - ShowItem = selectedItems.Count < 5 && selectedItems.All(i => i.PrimaryItemAttribute == Windows.Storage.StorageItemTypes.Folder), + ShowItem = selectedItems.Count < 5 && selectedItems.All(i => i.PrimaryItemAttribute == StorageItemTypes.Folder), ShowInSearchPage = true, ShowInFtpPage = true, ShowInZipPage = true, @@ -713,7 +713,7 @@ public static List GetBaseItemMenuItems(BaseLayo Text = "BaseLayoutItemContextFlyoutOpenInNewWindow/Text".GetLocalizedResource(), Glyph = "\uE737", Command = commandsViewModel.OpenInNewWindowItemCommand, - ShowItem = selectedItems.Count < 5 && selectedItems.All(i => i.PrimaryItemAttribute == Windows.Storage.StorageItemTypes.Folder), + ShowItem = selectedItems.Count < 5 && selectedItems.All(i => i.PrimaryItemAttribute == StorageItemTypes.Folder), ShowInSearchPage = true, ShowInFtpPage = true, ShowOnShift = true, diff --git a/src/Files.App/Helpers/NavigationHelpers.cs b/src/Files.App/Helpers/NavigationHelpers.cs index 5238a48870f0..37232d4149f7 100644 --- a/src/Files.App/Helpers/NavigationHelpers.cs +++ b/src/Files.App/Helpers/NavigationHelpers.cs @@ -2,6 +2,7 @@ using Files.App.Extensions; using Files.App.Filesystem; using Files.App.Filesystem.StorageItems; +using Files.App.ServicesImplementation.Settings; using Files.App.Shell; using Files.App.ViewModels; using Files.App.Views; @@ -36,6 +37,19 @@ public static Task OpenTabInNewWindowAsync(string tabArgs) return Launcher.LaunchUriAsync(folderUri).AsTask(); } + public static void OpenInSecondaryPanel(IShellPage associatedInstance, ListedItem listedItem) + { + if(associatedInstance is null || listedItem is null) + return; + + IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService(); + if (!userSettingsService.PreferencesSettingsService.IsDualPaneEnabled) + return; + + if (listedItem is not null) + associatedInstance.PaneHolder?.OpenPathInNewPane((listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath); + } + public static Task LaunchNewWindowAsync() { var filesUWPUri = new Uri("files-uwp:"); diff --git a/src/Files.App/Interacts/BaseLayoutCommandImplementationModel.cs b/src/Files.App/Interacts/BaseLayoutCommandImplementationModel.cs index bc16b6d9d42f..ec09f72a998e 100644 --- a/src/Files.App/Interacts/BaseLayoutCommandImplementationModel.cs +++ b/src/Files.App/Interacts/BaseLayoutCommandImplementationModel.cs @@ -261,9 +261,7 @@ await App.Window.DispatcherQueue.EnqueueAsync(async () => public virtual void OpenDirectoryInNewPane(RoutedEventArgs e) { - ListedItem listedItem = SlimContentPage.SelectedItems.FirstOrDefault(); - if (listedItem is not null) - associatedInstance.PaneHolder?.OpenPathInNewPane((listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath); + NavigationHelpers.OpenInSecondaryPanel(associatedInstance, SlimContentPage.SelectedItems.FirstOrDefault()); } public virtual async void OpenInNewWindowItem(RoutedEventArgs e) diff --git a/src/Files.App/Views/LayoutModes/DetailsLayoutBrowser.xaml.cs b/src/Files.App/Views/LayoutModes/DetailsLayoutBrowser.xaml.cs index 460d72987a05..160a7f6f6782 100644 --- a/src/Files.App/Views/LayoutModes/DetailsLayoutBrowser.xaml.cs +++ b/src/Files.App/Views/LayoutModes/DetailsLayoutBrowser.xaml.cs @@ -420,6 +420,9 @@ private void EndRename(TextBox textBox) private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e) { + if (ParentShellPageInstance is null) + return; + var ctrlPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down); var shiftPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down); var focusedElement = (FrameworkElement)FocusManager.GetFocusedElement(XamlRoot); @@ -433,7 +436,7 @@ private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e) e.Handled = true; - if (ctrlPressed) + if (ctrlPressed && !shiftPressed) { var folders = ParentShellPageInstance?.SlimContentPage.SelectedItems?.Where(file => file.PrimaryItemAttribute == StorageItemTypes.Folder); foreach (ListedItem? folder in folders) @@ -442,6 +445,10 @@ private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e) await NavigationHelpers.OpenPathInNewTab(folder.ItemPath); } } + else if(ctrlPressed && shiftPressed) + { + NavigationHelpers.OpenInSecondaryPanel(ParentShellPageInstance, SelectedItems.FirstOrDefault(item => item.PrimaryItemAttribute == StorageItemTypes.Folder)); + } else { await NavigationHelpers.OpenSelectedItems(ParentShellPageInstance, false); diff --git a/src/Files.App/Views/LayoutModes/GridViewBrowser.xaml.cs b/src/Files.App/Views/LayoutModes/GridViewBrowser.xaml.cs index 46c8058e164a..ab6b144a2605 100644 --- a/src/Files.App/Views/LayoutModes/GridViewBrowser.xaml.cs +++ b/src/Files.App/Views/LayoutModes/GridViewBrowser.xaml.cs @@ -385,7 +385,7 @@ private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e) e.Handled = true; - if (ctrlPressed) + if (ctrlPressed && !shiftPressed) { var folders = ParentShellPageInstance?.SlimContentPage.SelectedItems?.Where(file => file.PrimaryItemAttribute == StorageItemTypes.Folder); foreach (ListedItem? folder in folders) @@ -394,6 +394,10 @@ private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e) await NavigationHelpers.OpenPathInNewTab(folder.ItemPath); } } + else if (ctrlPressed && shiftPressed) + { + NavigationHelpers.OpenInSecondaryPanel(ParentShellPageInstance, SelectedItems.FirstOrDefault(item => item.PrimaryItemAttribute == StorageItemTypes.Folder)); + } else { await NavigationHelpers.OpenSelectedItems(ParentShellPageInstance, false); From c5ee366f9b292eb9dc5ce3e033c9d5e92a364337 Mon Sep 17 00:00:00 2001 From: Quaint Mako <110472580+QuaintMako@users.noreply.github.com> Date: Mon, 9 Jan 2023 13:57:18 +0100 Subject: [PATCH 2/4] Adding null check --- src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs | 3 +++ src/Files.App/Views/LayoutModes/GridViewBrowser.xaml.cs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs b/src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs index 8ed9489980b5..7f396930be56 100644 --- a/src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs +++ b/src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs @@ -402,6 +402,9 @@ private void FileList_PreviewKeyUp(object sender, KeyRoutedEventArgs e) private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e) { + if (ParentShellPageInstance is null) + return; + var ctrlPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down); var shiftPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down); diff --git a/src/Files.App/Views/LayoutModes/GridViewBrowser.xaml.cs b/src/Files.App/Views/LayoutModes/GridViewBrowser.xaml.cs index ab6b144a2605..05fca5db01f7 100644 --- a/src/Files.App/Views/LayoutModes/GridViewBrowser.xaml.cs +++ b/src/Files.App/Views/LayoutModes/GridViewBrowser.xaml.cs @@ -373,6 +373,9 @@ private void EndRename(TextBox textBox) private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e) { + if (ParentShellPageInstance is null) + return; + var ctrlPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down); var shiftPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down); var focusedElement = FocusManager.GetFocusedElement(XamlRoot) as FrameworkElement; From cc7685caea867be70e95d2343cb0d7c3de36563e Mon Sep 17 00:00:00 2001 From: Quaint Mako <110472580+QuaintMako@users.noreply.github.com> Date: Wed, 11 Jan 2023 17:29:04 +0100 Subject: [PATCH 3/4] Renamed method for consistency. --- src/Files.App/Helpers/NavigationHelpers.cs | 2 +- src/Files.App/Interacts/BaseLayoutCommandImplementationModel.cs | 2 +- src/Files.App/Views/LayoutModes/DetailsLayoutBrowser.xaml.cs | 2 +- src/Files.App/Views/LayoutModes/GridViewBrowser.xaml.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Files.App/Helpers/NavigationHelpers.cs b/src/Files.App/Helpers/NavigationHelpers.cs index 37232d4149f7..45b6a5a16848 100644 --- a/src/Files.App/Helpers/NavigationHelpers.cs +++ b/src/Files.App/Helpers/NavigationHelpers.cs @@ -37,7 +37,7 @@ public static Task OpenTabInNewWindowAsync(string tabArgs) return Launcher.LaunchUriAsync(folderUri).AsTask(); } - public static void OpenInSecondaryPanel(IShellPage associatedInstance, ListedItem listedItem) + public static void OpenInSecondaryPane(IShellPage associatedInstance, ListedItem listedItem) { if(associatedInstance is null || listedItem is null) return; diff --git a/src/Files.App/Interacts/BaseLayoutCommandImplementationModel.cs b/src/Files.App/Interacts/BaseLayoutCommandImplementationModel.cs index 2295290e94ba..209cb692860f 100644 --- a/src/Files.App/Interacts/BaseLayoutCommandImplementationModel.cs +++ b/src/Files.App/Interacts/BaseLayoutCommandImplementationModel.cs @@ -261,7 +261,7 @@ await App.Window.DispatcherQueue.EnqueueAsync(async () => public virtual void OpenDirectoryInNewPane(RoutedEventArgs e) { - NavigationHelpers.OpenInSecondaryPanel(associatedInstance, SlimContentPage.SelectedItems.FirstOrDefault()); + NavigationHelpers.OpenInSecondaryPane(associatedInstance, SlimContentPage.SelectedItems.FirstOrDefault()); } public virtual async void OpenInNewWindowItem(RoutedEventArgs e) diff --git a/src/Files.App/Views/LayoutModes/DetailsLayoutBrowser.xaml.cs b/src/Files.App/Views/LayoutModes/DetailsLayoutBrowser.xaml.cs index 160a7f6f6782..3f76d9d1f8f5 100644 --- a/src/Files.App/Views/LayoutModes/DetailsLayoutBrowser.xaml.cs +++ b/src/Files.App/Views/LayoutModes/DetailsLayoutBrowser.xaml.cs @@ -447,7 +447,7 @@ private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e) } else if(ctrlPressed && shiftPressed) { - NavigationHelpers.OpenInSecondaryPanel(ParentShellPageInstance, SelectedItems.FirstOrDefault(item => item.PrimaryItemAttribute == StorageItemTypes.Folder)); + NavigationHelpers.OpenInSecondaryPane(ParentShellPageInstance, SelectedItems.FirstOrDefault(item => item.PrimaryItemAttribute == StorageItemTypes.Folder)); } else { diff --git a/src/Files.App/Views/LayoutModes/GridViewBrowser.xaml.cs b/src/Files.App/Views/LayoutModes/GridViewBrowser.xaml.cs index 05fca5db01f7..1f929fd380b5 100644 --- a/src/Files.App/Views/LayoutModes/GridViewBrowser.xaml.cs +++ b/src/Files.App/Views/LayoutModes/GridViewBrowser.xaml.cs @@ -399,7 +399,7 @@ private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e) } else if (ctrlPressed && shiftPressed) { - NavigationHelpers.OpenInSecondaryPanel(ParentShellPageInstance, SelectedItems.FirstOrDefault(item => item.PrimaryItemAttribute == StorageItemTypes.Folder)); + NavigationHelpers.OpenInSecondaryPane(ParentShellPageInstance, SelectedItems.FirstOrDefault(item => item.PrimaryItemAttribute == StorageItemTypes.Folder)); } else { From b2c0d9f1cd78b8f27b750649d0e3ea4372eedafa Mon Sep 17 00:00:00 2001 From: Quaint Mako <110472580+QuaintMako@users.noreply.github.com> Date: Sun, 15 Jan 2023 19:25:46 +0100 Subject: [PATCH 4/4] Requested changes --- src/Files.App/Helpers/NavigationHelpers.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Files.App/Helpers/NavigationHelpers.cs b/src/Files.App/Helpers/NavigationHelpers.cs index 45b6a5a16848..9adb213c9d11 100644 --- a/src/Files.App/Helpers/NavigationHelpers.cs +++ b/src/Files.App/Helpers/NavigationHelpers.cs @@ -22,6 +22,8 @@ namespace Files.App.Helpers { public static class NavigationHelpers { + private static readonly IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService(); + public static Task OpenPathInNewTab(string path) => MainPageViewModel.AddNewTabByPathAsync(typeof(PaneHolderPage), path); @@ -42,12 +44,10 @@ public static void OpenInSecondaryPane(IShellPage associatedInstance, ListedItem if(associatedInstance is null || listedItem is null) return; - IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService(); if (!userSettingsService.PreferencesSettingsService.IsDualPaneEnabled) return; - if (listedItem is not null) - associatedInstance.PaneHolder?.OpenPathInNewPane((listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath); + associatedInstance.PaneHolder?.OpenPathInNewPane((listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath); } public static Task LaunchNewWindowAsync()