Skip to content

Commit

Permalink
Feature: Added an action to close all tabs (files-community#16418)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaira2 authored Nov 1, 2024
1 parent 4221568 commit 39df64d
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Files.App/Actions/Navigation/CloseActivePaneAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
37 changes: 37 additions & 0 deletions src/Files.App/Actions/Navigation/CloseAllTabsAction.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
1 change: 1 addition & 0 deletions src/Files.App/Data/Commands/Manager/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public enum CommandCodes
PreviousTab,
NextTab,
CloseSelectedTab,
CloseAllTabs,

// Shell Panes
CloseActivePane,
Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Data/Commands/Manager/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -382,6 +383,7 @@ public IEnumerator<IRichCommand> 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(),
Expand Down
1 change: 1 addition & 0 deletions src/Files.App/Data/Commands/Manager/ICommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
IRichCommand PreviousTab { get; }
IRichCommand NextTab { get; }
IRichCommand CloseSelectedTab { get; }
IRichCommand CloseAllTabs { get; }

IRichCommand CloseActivePane { get; }
IRichCommand FocusOtherPane { get; }
Expand Down
9 changes: 9 additions & 0 deletions src/Files.App/Helpers/Navigation/MultitaskingTabsHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
6 changes: 6 additions & 0 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1940,6 +1940,9 @@
<data name="CloseOtherTabs" xml:space="preserve">
<value>Close other tabs</value>
</data>
<data name="CloseAllTabs" xml:space="preserve">
<value>Close all tabs</value>
</data>
<data name="Music" xml:space="preserve">
<value>Music</value>
</data>
Expand Down Expand Up @@ -2696,6 +2699,9 @@
<data name="CloseOtherTabsSelectedDescription" xml:space="preserve">
<value>Close tabs other than selected tab</value>
</data>
<data name="CloseAllTabsDescription" xml:space="preserve">
<value>Close all tabs including the current tab</value>
</data>
<data name="ReopenClosedTabDescription" xml:space="preserve">
<value>Reopen last closed tab</value>
</data>
Expand Down

0 comments on commit 39df64d

Please sign in to comment.