From 39df64d692a83f01eb69dab96dc261a3d0bc9976 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Fri, 1 Nov 2024 10:43:52 -0400 Subject: [PATCH] Feature: Added an action to close all tabs (#16418) --- .../Navigation/CloseActivePaneAction.cs | 2 +- .../Actions/Navigation/CloseAllTabsAction.cs | 37 +++++++++++++++++++ .../Data/Commands/Manager/CommandCodes.cs | 1 + .../Data/Commands/Manager/CommandManager.cs | 2 + .../Data/Commands/Manager/ICommandManager.cs | 1 + .../Navigation/MultitaskingTabsHelpers.cs | 9 +++++ src/Files.App/Strings/en-US/Resources.resw | 6 +++ 7 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/Files.App/Actions/Navigation/CloseAllTabsAction.cs diff --git a/src/Files.App/Actions/Navigation/CloseActivePaneAction.cs b/src/Files.App/Actions/Navigation/CloseActivePaneAction.cs index 847609a65852..08c0735f4905 100644 --- a/src/Files.App/Actions/Navigation/CloseActivePaneAction.cs +++ b/src/Files.App/Actions/Navigation/CloseActivePaneAction.cs @@ -14,7 +14,7 @@ public string Description => "CloseActivePaneDescription".GetLocalizedResource(); public HotKey HotKey - => new(Keys.W, KeyModifiers.CtrlShift); + => new(Keys.W, KeyModifiers.CtrlAlt); public RichGlyph Glyph => new(themedIconStyle: "App.ThemedIcons.PanelLeftClose"); diff --git a/src/Files.App/Actions/Navigation/CloseAllTabsAction.cs b/src/Files.App/Actions/Navigation/CloseAllTabsAction.cs new file mode 100644 index 000000000000..5726553b41a1 --- /dev/null +++ b/src/Files.App/Actions/Navigation/CloseAllTabsAction.cs @@ -0,0 +1,37 @@ +// Copyright (c) 2024 Files Community +// Licensed under the MIT License. See the LICENSE. + +namespace Files.App.Actions +{ + internal sealed class CloseAllTabsAction : CloseTabBaseAction + { + public override string Label + => Strings.CloseAllTabs.GetLocalizedResource(); + + public override string Description + => Strings.CloseAllTabsDescription.GetLocalizedResource(); + + public override HotKey HotKey + => new(Keys.W, KeyModifiers.CtrlShift); + + public CloseAllTabsAction() + { + } + + protected override bool GetIsExecutable() + { + return + context.Control is not null && + context.TabCount > 0 && + context.CurrentTabItem is not null; + } + + public override Task ExecuteAsync(object? parameter = null) + { + if (context.Control is not null) + MultitaskingTabsHelpers.CloseAllTabs(context.Control); + + return Task.CompletedTask; + } + } +} diff --git a/src/Files.App/Data/Commands/Manager/CommandCodes.cs b/src/Files.App/Data/Commands/Manager/CommandCodes.cs index 60480f36a7bb..42858fa1303a 100644 --- a/src/Files.App/Data/Commands/Manager/CommandCodes.cs +++ b/src/Files.App/Data/Commands/Manager/CommandCodes.cs @@ -197,6 +197,7 @@ public enum CommandCodes PreviousTab, NextTab, CloseSelectedTab, + CloseAllTabs, // Shell Panes CloseActivePane, diff --git a/src/Files.App/Data/Commands/Manager/CommandManager.cs b/src/Files.App/Data/Commands/Manager/CommandManager.cs index 8766847953e6..aba8781e33ca 100644 --- a/src/Files.App/Data/Commands/Manager/CommandManager.cs +++ b/src/Files.App/Data/Commands/Manager/CommandManager.cs @@ -187,6 +187,7 @@ public IRichCommand this[HotKey hotKey] public IRichCommand CloseTabsToTheRightSelected => commands[CommandCodes.CloseTabsToTheRightSelected]; public IRichCommand CloseOtherTabsCurrent => commands[CommandCodes.CloseOtherTabsCurrent]; public IRichCommand CloseOtherTabsSelected => commands[CommandCodes.CloseOtherTabsSelected]; + public IRichCommand CloseAllTabs => commands[CommandCodes.CloseAllTabs]; public IRichCommand OpenInNewPaneAction => commands[CommandCodes.OpenInNewPane]; public IRichCommand OpenInNewPaneFromHomeAction => commands[CommandCodes.OpenInNewPaneFromHome]; public IRichCommand OpenInNewPaneFromSidebarAction => commands[CommandCodes.OpenInNewPaneFromSidebar]; @@ -382,6 +383,7 @@ public IEnumerator GetEnumerator() => [CommandCodes.CloseTabsToTheRightSelected] = new CloseTabsToTheRightSelectedAction(), [CommandCodes.CloseOtherTabsCurrent] = new CloseOtherTabsCurrentAction(), [CommandCodes.CloseOtherTabsSelected] = new CloseOtherTabsSelectedAction(), + [CommandCodes.CloseAllTabs] = new CloseAllTabsAction(), [CommandCodes.OpenInNewPane] = new OpenInNewPaneAction(), [CommandCodes.OpenInNewPaneFromHome] = new OpenInNewPaneFromHomeAction(), [CommandCodes.OpenInNewPaneFromSidebar] = new OpenInNewPaneFromSidebarAction(), diff --git a/src/Files.App/Data/Commands/Manager/ICommandManager.cs b/src/Files.App/Data/Commands/Manager/ICommandManager.cs index 43acdbdaeb4c..03735eed1d38 100644 --- a/src/Files.App/Data/Commands/Manager/ICommandManager.cs +++ b/src/Files.App/Data/Commands/Manager/ICommandManager.cs @@ -181,6 +181,7 @@ public interface ICommandManager : IEnumerable IRichCommand PreviousTab { get; } IRichCommand NextTab { get; } IRichCommand CloseSelectedTab { get; } + IRichCommand CloseAllTabs { get; } IRichCommand CloseActivePane { get; } IRichCommand FocusOtherPane { get; } diff --git a/src/Files.App/Helpers/Navigation/MultitaskingTabsHelpers.cs b/src/Files.App/Helpers/Navigation/MultitaskingTabsHelpers.cs index 03bd783b4e95..50610ae1dc42 100644 --- a/src/Files.App/Helpers/Navigation/MultitaskingTabsHelpers.cs +++ b/src/Files.App/Helpers/Navigation/MultitaskingTabsHelpers.cs @@ -40,6 +40,15 @@ public static void CloseOtherTabs(TabBarItem clickedTab, ITabBar multitaskingCon tabs.Where((t) => t != clickedTab).ToList().ForEach(tab => multitaskingControl.CloseTab(tab)); } } + + public static void CloseAllTabs(ITabBar multitaskingControl) + { + if (multitaskingControl is not null) + { + var tabs = MainPageViewModel.AppInstances; + tabs.ToList().ForEach(tab => multitaskingControl.CloseTab(tab)); + } + } public static Task MoveTabToNewWindow(TabBarItem tab, ITabBar multitaskingControl) { diff --git a/src/Files.App/Strings/en-US/Resources.resw b/src/Files.App/Strings/en-US/Resources.resw index 03223e6e5268..07de3cb82ab2 100644 --- a/src/Files.App/Strings/en-US/Resources.resw +++ b/src/Files.App/Strings/en-US/Resources.resw @@ -1940,6 +1940,9 @@ Close other tabs + + Close all tabs + Music @@ -2696,6 +2699,9 @@ Close tabs other than selected tab + + Close all tabs including the current tab + Reopen last closed tab