Skip to content

Rich command: NewTab + DuplicateTab #11596

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

Merged
merged 7 commits into from
Mar 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/Files.App/Actions/Navigation/DuplicateTabAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Files.App.Commands;
using Files.App.Extensions;
using Files.App.ViewModels;
using System.Threading.Tasks;
using Windows.System;

namespace Files.App.Actions
{
internal class DuplicateTabAction : IAction
{
public string Label { get; } = "DuplicateTab".GetLocalizedResource();

public HotKey HotKey { get; } = new(VirtualKey.K, VirtualKeyModifiers.Control | VirtualKeyModifiers.Shift);

public Task ExecuteAsync() => MainPageViewModel.DuplicateTabAsync();
}
}
17 changes: 17 additions & 0 deletions src/Files.App/Actions/Navigation/NewTabAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Files.App.Commands;
using Files.App.Extensions;
using Files.App.ViewModels;
using System.Threading.Tasks;
using Windows.System;

namespace Files.App.Actions
{
internal class NewTabAction : IAction
{
public string Label { get; } = "NewTab".GetLocalizedResource();

public HotKey HotKey { get; } = new(VirtualKey.T, VirtualKeyModifiers.Control);

public Task ExecuteAsync() => MainPageViewModel.AddNewTabAsync();
}
}
6 changes: 5 additions & 1 deletion src/Files.App/Commands/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public enum CommandCodes

// Image Edition
RotateLeft,
RotateRight
RotateRight,

// Navigation
NewTab,
DuplicateTab,
}
}
6 changes: 5 additions & 1 deletion src/Files.App/Commands/Manager/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ internal class CommandManager : ICommandManager
public IRichCommand CompressIntoZip => commands[CommandCodes.CompressIntoZip];
public IRichCommand RotateLeft => commands[CommandCodes.RotateLeft];
public IRichCommand RotateRight => commands[CommandCodes.RotateRight];
public IRichCommand NewTab => commands[CommandCodes.NewTab];
public IRichCommand DuplicateTab => commands[CommandCodes.DuplicateTab];

public CommandManager()
{
Expand Down Expand Up @@ -119,7 +121,9 @@ public CommandManager()
[CommandCodes.CompressIntoSevenZip] = new CompressIntoSevenZipAction(),
[CommandCodes.CompressIntoZip] = new CompressIntoZipAction(),
[CommandCodes.RotateLeft] = new RotateLeftAction(),
[CommandCodes.RotateRight] = new RotateRightAction()
[CommandCodes.RotateRight] = new RotateRightAction(),
[CommandCodes.NewTab] = new NewTabAction(),
[CommandCodes.DuplicateTab] = new DuplicateTabAction(),
};

[DebuggerDisplay("Command None")]
Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/Commands/Manager/ICommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,8 @@ public interface ICommandManager : IEnumerable<IRichCommand>

IRichCommand RotateLeft { get; }
IRichCommand RotateRight { get; }

IRichCommand NewTab { get; }
IRichCommand DuplicateTab { get; }
}
}
22 changes: 0 additions & 22 deletions src/Files.App/Helpers/MultitaskingTabsHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,5 @@ public static Task MoveTabToNewWindow(TabItem tab, IMultitaskingControl multitas
? NavigationHelpers.OpenTabInNewWindowAsync(tabItemArguments.Serialize())
: NavigationHelpers.OpenPathInNewWindowAsync("Home");
}

public static async Task AddNewTab(Type type, object tabViewItemArgs, int atIndex = -1)
{
FontIconSource fontIconSource = new FontIconSource();
fontIconSource.FontFamily = App.AppModel.SymbolFontFamily;

TabItem tabItem = new TabItem()
{
Header = null,
IconSource = fontIconSource,
Description = null,
ToolTipText = null
};
tabItem.Control.NavigationArguments = new TabItemArguments()
{
InitialPageType = type,
NavigationArg = tabViewItemArgs
};
tabItem.Control.ContentChanged += MainPageViewModel.Control_ContentChanged;
await MainPageViewModel.UpdateTabInfo(tabItem, tabViewItemArgs);
MainPageViewModel.AppInstances.Insert(atIndex == -1 ? MainPageViewModel.AppInstances.Count : atIndex, tabItem);
}
}
}
10 changes: 2 additions & 8 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -987,18 +987,15 @@
<data name="SideBarEjectDevice.Text" xml:space="preserve">
<value>Eject</value>
</data>
<data name="HorizontalMultitaskingControlDuplicateTab.Text" xml:space="preserve">
<data name="DuplicateTab" xml:space="preserve">
<value>Duplicate tab</value>
</data>
<data name="HorizontalMultitaskingControlMoveTabToNewWindow.Text" xml:space="preserve">
<value>Move tab to new window</value>
</data>
<data name="HorizontalMultitaskingControlNewTab.Text" xml:space="preserve">
<data name="NewTab" xml:space="preserve">
<value>New tab</value>
</data>
<data name="NewTabCtrlT" xml:space="preserve">
<value>New tab (Ctrl+T)</value>
</data>
<data name="ClearPropertiesFlyoutText.Text" xml:space="preserve">
<value>Some properties may contain personal information.</value>
</data>
Expand Down Expand Up @@ -1881,9 +1878,6 @@
<data name="BaseLayoutContextFlyoutColumn.KeyboardAcceleratorTextOverride" xml:space="preserve">
<value>Ctrl+Shift+6</value>
</data>
<data name="HorizontalMultitaskingControlNewTab.KeyboardAcceleratorTextOverride" xml:space="preserve">
<value>Ctrl+T</value>
</data>
<data name="HorizontalMultitaskingControlReopenClosedTab.KeyboardAcceleratorTextOverride" xml:space="preserve">
<value>Ctrl+Shift+T</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,13 @@
x:Name="TabItemContextMenu"
Opening="TabItemContextMenu_Opening">
<MenuFlyoutItem
Click="{x:Bind vm:MainPageViewModel.AddNewTabAtIndex}"
KeyboardAcceleratorTextOverride="{helpers:ResourceString Name=HorizontalMultitaskingControlNewTab/KeyboardAcceleratorTextOverride}"
Text="{helpers:ResourceString Name=HorizontalMultitaskingControlNewTab/Text}">
<MenuFlyoutItem.KeyboardAccelerators>
<KeyboardAccelerator
Key="T"
IsEnabled="False"
Modifiers="Control" />
</MenuFlyoutItem.KeyboardAccelerators>
</MenuFlyoutItem>
Command="{x:Bind Commands.NewTab}"
KeyboardAcceleratorTextOverride="{x:Bind Commands.NewTab.HotKeyText, Mode=OneWay}"
Text="{x:Bind Commands.NewTab.Label}" />
<MenuFlyoutItem
Click="{x:Bind vm:MainPageViewModel.DuplicateTabAtIndex}"
KeyboardAcceleratorTextOverride="{helpers:ResourceString Name=HorizontalMultitaskingControlDuplicateTab/KeyboardAcceleratorTextOverride}"
Text="{helpers:ResourceString Name=HorizontalMultitaskingControlDuplicateTab/Text}" />
Command="{x:Bind Commands.DuplicateTab}"
KeyboardAcceleratorTextOverride="{x:Bind Commands.DuplicateTab.HotKeyText, Mode=OneWay}"
Text="{x:Bind Commands.DuplicateTab.Label}" />
<MenuFlyoutItem
x:Name="MenuItemMoveTabToNewWindow"
Click="MoveTabToNewWindow"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using CommunityToolkit.Mvvm.DependencyInjection;
using CommunityToolkit.WinUI.UI;
using Files.App.Commands;
using Files.App.Extensions;
using Files.App.Helpers;
using Files.App.ViewModels;
Expand All @@ -9,14 +11,15 @@
using System.Linq;
using Windows.ApplicationModel.DataTransfer;
using Windows.Storage;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;

// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236

namespace Files.App.UserControls.MultitaskingControl
{
public sealed partial class HorizontalMultitaskingControl : BaseMultitaskingControl
{
private ICommandManager Commands { get; } = Ioc.Default.GetRequiredService<ICommandManager>();

private readonly DispatcherTimer tabHoverTimer = new DispatcherTimer();
private TabViewItem? hoveredTabViewItem;

Expand Down
24 changes: 6 additions & 18 deletions src/Files.App/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Files.Backend.Services.Settings;
using Files.Backend.ViewModels.Dialogs;
using Files.Shared.Extensions;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Navigation;
using System;
Expand Down Expand Up @@ -53,7 +52,6 @@ public bool IsWindowCompactOverlay
public ICommand NavigateToNumberedTabKeyboardAcceleratorCommand { get; private set; }
public IAsyncRelayCommand OpenNewWindowAcceleratorCommand { get; private set; }
public ICommand CloseSelectedTabKeyboardAcceleratorCommand { get; private set; }
public IAsyncRelayCommand AddNewInstanceAcceleratorCommand { get; private set; }
public ICommand ReopenClosedTabAcceleratorCommand { get; private set; }
public ICommand OpenSettingsCommand { get; private set; }

Expand All @@ -63,7 +61,6 @@ public MainPageViewModel()
NavigateToNumberedTabKeyboardAcceleratorCommand = new RelayCommand<KeyboardAcceleratorInvokedEventArgs>(NavigateToNumberedTabKeyboardAccelerator);
OpenNewWindowAcceleratorCommand = new AsyncRelayCommand<KeyboardAcceleratorInvokedEventArgs>(OpenNewWindowAccelerator);
CloseSelectedTabKeyboardAcceleratorCommand = new RelayCommand<KeyboardAcceleratorInvokedEventArgs>(CloseSelectedTabKeyboardAccelerator);
AddNewInstanceAcceleratorCommand = new AsyncRelayCommand<KeyboardAcceleratorInvokedEventArgs>(AddNewInstanceAccelerator);
ReopenClosedTabAcceleratorCommand = new RelayCommand<KeyboardAcceleratorInvokedEventArgs>(ReopenClosedTabAccelerator);
OpenSettingsCommand = new RelayCommand(OpenSettings);
}
Expand Down Expand Up @@ -155,12 +152,6 @@ private void CloseSelectedTabKeyboardAccelerator(KeyboardAcceleratorInvokedEvent
e!.Handled = true;
}

private async Task AddNewInstanceAccelerator(KeyboardAcceleratorInvokedEventArgs? e)
{
await AddNewTabAsync();
e!.Handled = true;
}

private void ReopenClosedTabAccelerator(KeyboardAcceleratorInvokedEventArgs? e)
{
(MultitaskingControl as BaseMultitaskingControl)?.ReopenClosedTab(null, null);
Expand Down Expand Up @@ -414,19 +405,16 @@ public void AddNewTab()
AddNewTabAsync();
}

public static async void AddNewTabAtIndex(object sender, RoutedEventArgs e)
public static async Task DuplicateTabAsync()
{
await AddNewTabAsync();
}
var tabItem = AppInstances.FirstOrDefault(instance => instance.Control.TabItemContent.IsCurrentInstance);
if (tabItem is null)
return;

public static async void DuplicateTabAtIndex(object sender, RoutedEventArgs e)
{
var tabItem = (TabItem)((FrameworkElement)sender).DataContext;
var index = AppInstances.IndexOf(tabItem);

if (AppInstances[index].TabItemArguments is not null)
if (tabItem.TabItemArguments is not null)
{
var tabArgs = AppInstances[index].TabItemArguments;
var tabArgs = tabItem.TabItemArguments;
await AddNewTabByParam(tabArgs.InitialPageType, tabArgs.NavigationArg, index + 1);
}
else
Expand Down
5 changes: 0 additions & 5 deletions src/Files.App/Views/ColumnShellPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@
Key="F3"
Invoked="KeyboardAccelerator_Invoked"
IsEnabled="{x:Bind IsCurrentInstance, Mode=OneWay}" />
<KeyboardAccelerator
Key="K"
Invoked="KeyboardAccelerator_Invoked"
IsEnabled="{x:Bind IsCurrentInstance, Mode=OneWay}"
Modifiers="Control,Shift" />
<KeyboardAccelerator
Key="H"
Invoked="KeyboardAccelerator_Invoked"
Expand Down
4 changes: 0 additions & 4 deletions src/Files.App/Views/ColumnShellPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,6 @@ private async void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, Keybo
ToolbarViewModel.IsEditModeEnabled = true;
break;

case (true, true, false, true, VirtualKey.K): // ctrl + shift + k, duplicate tab
await NavigationHelpers.OpenPathInNewTab(FilesystemViewModel.WorkingDirectory);
break;

case (true, false, false, true, VirtualKey.H): // ctrl + h, toggle hidden folder visibility
userSettingsService.FoldersSettingsService.ShowHiddenItems ^= true; // flip bool
break;
Expand Down
14 changes: 0 additions & 14 deletions src/Files.App/Views/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,27 +136,13 @@
</icore:EventTriggerBehavior>
</i:Interaction.Behaviors>
</KeyboardAccelerator>
<KeyboardAccelerator Key="T" Modifiers="Control">
<i:Interaction.Behaviors>
<icore:EventTriggerBehavior EventName="Invoked">
<icore:InvokeCommandAction Command="{x:Bind ViewModel.AddNewInstanceAcceleratorCommand}" />
</icore:EventTriggerBehavior>
</i:Interaction.Behaviors>
</KeyboardAccelerator>
<KeyboardAccelerator Key="T" Modifiers="Control,Shift">
<i:Interaction.Behaviors>
<icore:EventTriggerBehavior EventName="Invoked">
<icore:InvokeCommandAction Command="{x:Bind ViewModel.ReopenClosedTabAcceleratorCommand}" />
</icore:EventTriggerBehavior>
</i:Interaction.Behaviors>
</KeyboardAccelerator>
<KeyboardAccelerator Key="K" Modifiers="Control,Shift">
<i:Interaction.Behaviors>
<icore:EventTriggerBehavior EventName="Invoked">
<icore:InvokeCommandAction Command="{x:Bind ViewModel.AddNewInstanceAcceleratorCommand}" />
</icore:EventTriggerBehavior>
</i:Interaction.Behaviors>
</KeyboardAccelerator>
<KeyboardAccelerator Key="F12">
<i:Interaction.Behaviors>
<icore:EventTriggerBehavior EventName="Invoked">
Expand Down
5 changes: 0 additions & 5 deletions src/Files.App/Views/ModernShellPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@
Invoked="KeyboardAccelerator_Invoked"
IsEnabled="{x:Bind IsCurrentInstance, Mode=OneWay}"
Modifiers="Menu" />
<KeyboardAccelerator
Key="K"
Invoked="KeyboardAccelerator_Invoked"
IsEnabled="{x:Bind IsCurrentInstance, Mode=OneWay}"
Modifiers="Control,Shift" />
<KeyboardAccelerator
Key="F2"
Invoked="KeyboardAccelerator_Invoked"
Expand Down
4 changes: 0 additions & 4 deletions src/Files.App/Views/ModernShellPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,6 @@ private async void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, Keybo

break;

case (true, true, false, true, VirtualKey.K): // ctrl + shift + k, duplicate tab
await NavigationHelpers.OpenPathInNewTab(FilesystemViewModel.WorkingDirectory);
break;

case (true, false, false, true, VirtualKey.H): // ctrl + h, toggle hidden folder visibility
userSettingsService.FoldersSettingsService.ShowHiddenItems ^= true; // flip bool
break;
Expand Down