Skip to content

Commit 119f191

Browse files
committed
Feature: Added an action to close all tabs
1 parent 4221568 commit 119f191

File tree

6 files changed

+48
-0
lines changed

6 files changed

+48
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) 2024 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
namespace Files.App.Actions
5+
{
6+
internal sealed class CloseAllTabsAction : CloseTabBaseAction
7+
{
8+
public override string Label
9+
=> Strings.CloseAllTabs.GetLocalizedResource();
10+
11+
public override string Description
12+
=> Strings.CloseAllTabsDescription.GetLocalizedResource();
13+
14+
public override HotKey HotKey
15+
=> new(Keys.W, KeyModifiers.CtrlShift);
16+
17+
public CloseAllTabsAction()
18+
{
19+
}
20+
21+
public override Task ExecuteAsync(object? parameter = null)
22+
{
23+
if (context.Control is not null)
24+
MultitaskingTabsHelpers.CloseAllTabs(context.Control);
25+
26+
return Task.CompletedTask;
27+
}
28+
}
29+
}

src/Files.App/Data/Commands/Manager/CommandCodes.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ public enum CommandCodes
197197
PreviousTab,
198198
NextTab,
199199
CloseSelectedTab,
200+
CloseAllTabs,
200201

201202
// Shell Panes
202203
CloseActivePane,

src/Files.App/Data/Commands/Manager/CommandManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ public IRichCommand this[HotKey hotKey]
187187
public IRichCommand CloseTabsToTheRightSelected => commands[CommandCodes.CloseTabsToTheRightSelected];
188188
public IRichCommand CloseOtherTabsCurrent => commands[CommandCodes.CloseOtherTabsCurrent];
189189
public IRichCommand CloseOtherTabsSelected => commands[CommandCodes.CloseOtherTabsSelected];
190+
public IRichCommand CloseAllTabs => commands[CommandCodes.CloseAllTabs];
190191
public IRichCommand OpenInNewPaneAction => commands[CommandCodes.OpenInNewPane];
191192
public IRichCommand OpenInNewPaneFromHomeAction => commands[CommandCodes.OpenInNewPaneFromHome];
192193
public IRichCommand OpenInNewPaneFromSidebarAction => commands[CommandCodes.OpenInNewPaneFromSidebar];
@@ -382,6 +383,7 @@ public IEnumerator<IRichCommand> GetEnumerator() =>
382383
[CommandCodes.CloseTabsToTheRightSelected] = new CloseTabsToTheRightSelectedAction(),
383384
[CommandCodes.CloseOtherTabsCurrent] = new CloseOtherTabsCurrentAction(),
384385
[CommandCodes.CloseOtherTabsSelected] = new CloseOtherTabsSelectedAction(),
386+
[CommandCodes.CloseAllTabs] = new CloseAllTabsAction(),
385387
[CommandCodes.OpenInNewPane] = new OpenInNewPaneAction(),
386388
[CommandCodes.OpenInNewPaneFromHome] = new OpenInNewPaneFromHomeAction(),
387389
[CommandCodes.OpenInNewPaneFromSidebar] = new OpenInNewPaneFromSidebarAction(),

src/Files.App/Data/Commands/Manager/ICommandManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
181181
IRichCommand PreviousTab { get; }
182182
IRichCommand NextTab { get; }
183183
IRichCommand CloseSelectedTab { get; }
184+
IRichCommand CloseAllTabs { get; }
184185

185186
IRichCommand CloseActivePane { get; }
186187
IRichCommand FocusOtherPane { get; }

src/Files.App/Helpers/Navigation/MultitaskingTabsHelpers.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ public static void CloseOtherTabs(TabBarItem clickedTab, ITabBar multitaskingCon
4040
tabs.Where((t) => t != clickedTab).ToList().ForEach(tab => multitaskingControl.CloseTab(tab));
4141
}
4242
}
43+
44+
public static void CloseAllTabs(ITabBar multitaskingControl)
45+
{
46+
if (multitaskingControl is not null)
47+
{
48+
var tabs = MainPageViewModel.AppInstances;
49+
tabs.ForEach(tab => multitaskingControl.CloseTab(tab));
50+
}
51+
}
4352

4453
public static Task MoveTabToNewWindow(TabBarItem tab, ITabBar multitaskingControl)
4554
{

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,6 +1940,9 @@
19401940
<data name="CloseOtherTabs" xml:space="preserve">
19411941
<value>Close other tabs</value>
19421942
</data>
1943+
<data name="CloseAllTabs" xml:space="preserve">
1944+
<value>Close all tabs</value>
1945+
</data>
19431946
<data name="Music" xml:space="preserve">
19441947
<value>Music</value>
19451948
</data>
@@ -2696,6 +2699,9 @@
26962699
<data name="CloseOtherTabsSelectedDescription" xml:space="preserve">
26972700
<value>Close tabs other than selected tab</value>
26982701
</data>
2702+
<data name="CloseAllTabsDescription" xml:space="preserve">
2703+
<value>Close all tabs including the current tab</value>
2704+
</data>
26992705
<data name="ReopenClosedTabDescription" xml:space="preserve">
27002706
<value>Reopen last closed tab</value>
27012707
</data>

0 commit comments

Comments
 (0)