Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Added shortcut for opening folders in secondary pane #10966

Merged
merged 10 commits into from
Jan 16, 2023
12 changes: 6 additions & 6 deletions src/Files.App/Helpers/ContextFlyoutItemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ public static List<ContextMenuFlyoutItemViewModel> 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()
{
Expand All @@ -675,7 +675,7 @@ public static List<ContextMenuFlyoutItemViewModel> 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()
{
Expand All @@ -688,10 +688,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(BaseLayo
new ContextMenuFlyoutItemViewModel()
{
Text = "BaseLayoutItemContextFlyoutOpenInNewPane/Text".GetLocalizedResource(),
Glyph = "\uE117",
Glyph = "\xF117",
d2dyno1 marked this conversation as resolved.
Show resolved Hide resolved
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,
Expand All @@ -703,7 +703,7 @@ public static List<ContextMenuFlyoutItemViewModel> 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,
Expand All @@ -713,7 +713,7 @@ public static List<ContextMenuFlyoutItemViewModel> 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,
Expand Down
14 changes: 14 additions & 0 deletions src/Files.App/Helpers/NavigationHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,6 +22,8 @@ namespace Files.App.Helpers
{
public static class NavigationHelpers
{
private static readonly IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();

public static Task OpenPathInNewTab(string path)
=> MainPageViewModel.AddNewTabByPathAsync(typeof(PaneHolderPage), path);

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

public static void OpenInSecondaryPane(IShellPage associatedInstance, ListedItem listedItem)
{
if(associatedInstance is null || listedItem is null)
return;

if (!userSettingsService.PreferencesSettingsService.IsDualPaneEnabled)
return;

associatedInstance.PaneHolder?.OpenPathInNewPane((listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath);
}

public static Task LaunchNewWindowAsync()
{
var filesUWPUri = new Uri("files-uwp:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.OpenInSecondaryPane(associatedInstance, SlimContentPage.SelectedItems.FirstOrDefault());
}

public virtual async void OpenInNewWindowItem(RoutedEventArgs e)
Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
9 changes: 8 additions & 1 deletion src/Files.App/Views/LayoutModes/DetailsLayoutBrowser.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -442,6 +445,10 @@ private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
await NavigationHelpers.OpenPathInNewTab(folder.ItemPath);
}
}
else if(ctrlPressed && shiftPressed)
{
NavigationHelpers.OpenInSecondaryPane(ParentShellPageInstance, SelectedItems.FirstOrDefault(item => item.PrimaryItemAttribute == StorageItemTypes.Folder));
}
else
{
await NavigationHelpers.OpenSelectedItems(ParentShellPageInstance, false);
Expand Down
9 changes: 8 additions & 1 deletion src/Files.App/Views/LayoutModes/GridViewBrowser.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -385,7 +388,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)
Expand All @@ -394,6 +397,10 @@ private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
await NavigationHelpers.OpenPathInNewTab(folder.ItemPath);
}
}
else if (ctrlPressed && shiftPressed)
{
NavigationHelpers.OpenInSecondaryPane(ParentShellPageInstance, SelectedItems.FirstOrDefault(item => item.PrimaryItemAttribute == StorageItemTypes.Folder));
}
else
{
await NavigationHelpers.OpenSelectedItems(ParentShellPageInstance, false);
Expand Down