diff --git a/src/Files.App/Actions/Show/ToggleDualPaneAction.cs b/src/Files.App/Actions/Show/ToggleDualPaneAction.cs new file mode 100644 index 000000000000..a7004a0957ec --- /dev/null +++ b/src/Files.App/Actions/Show/ToggleDualPaneAction.cs @@ -0,0 +1,46 @@ +// Copyright (c) Files Community +// Licensed under the MIT License. + +namespace Files.App.Actions +{ + internal sealed partial class ToggleDualPaneAction : ObservableObject, IToggleAction + { + private readonly IContentPageContext ContentPageContext = Ioc.Default.GetRequiredService(); + private readonly IGeneralSettingsService generalSettingsService = Ioc.Default.GetRequiredService(); + + public string Label + => Strings.ToggleDualPane.GetLocalizedResource(); + + public string Description + => Strings.ToggleDualPaneDescription.GetLocalizedResource(); + + public bool IsOn + => ContentPageContext.IsMultiPaneActive; + + public ToggleDualPaneAction() + { + ContentPageContext.PropertyChanged += ContentPageContext_PropertyChanged; + } + + public Task ExecuteAsync(object? parameter = null) + { + if (IsOn) + ContentPageContext.ShellPage?.PaneHolder.CloseOtherPane(); + else + ContentPageContext.ShellPage?.PaneHolder.OpenSecondaryPane(arrangement: generalSettingsService.ShellPaneArrangementOption); + + return Task.CompletedTask; + } + + private void ContentPageContext_PropertyChanged(object? sender, PropertyChangedEventArgs e) + { + switch (e.PropertyName) + { + case nameof(IContentPageContext.ShellPage): + case nameof(IContentPageContext.IsMultiPaneActive): + OnPropertyChanged(nameof(IsOn)); + break; + } + } + } +} diff --git a/src/Files.App/Data/Commands/Manager/CommandCodes.cs b/src/Files.App/Data/Commands/Manager/CommandCodes.cs index 7c3cfcb448e0..100ee5b89476 100644 --- a/src/Files.App/Data/Commands/Manager/CommandCodes.cs +++ b/src/Files.App/Data/Commands/Manager/CommandCodes.cs @@ -28,6 +28,7 @@ public enum CommandCodes ToggleToolbar, ToggleShelfPane, ToggleFilterHeader, + ToggleDualPane, // File System CopyItem, diff --git a/src/Files.App/Data/Commands/Manager/CommandManager.cs b/src/Files.App/Data/Commands/Manager/CommandManager.cs index 12e4518885ad..626f6e4c29fb 100644 --- a/src/Files.App/Data/Commands/Manager/CommandManager.cs +++ b/src/Files.App/Data/Commands/Manager/CommandManager.cs @@ -59,6 +59,7 @@ public IRichCommand this[HotKey hotKey] public IRichCommand ToggleToolbar => commands[CommandCodes.ToggleToolbar]; public IRichCommand ToggleShelfPane => commands[CommandCodes.ToggleShelfPane]; public IRichCommand ToggleFilterHeader => commands[CommandCodes.ToggleFilterHeader]; + public IRichCommand ToggleDualPane => commands[CommandCodes.ToggleDualPane]; public IRichCommand SelectAll => commands[CommandCodes.SelectAll]; public IRichCommand InvertSelection => commands[CommandCodes.InvertSelection]; public IRichCommand ClearSelection => commands[CommandCodes.ClearSelection]; @@ -266,6 +267,7 @@ public IEnumerator GetEnumerator() => [CommandCodes.ToggleToolbar] = new ToggleToolbarAction(), [CommandCodes.ToggleShelfPane] = new ToggleShelfPaneAction(), [CommandCodes.ToggleFilterHeader] = new ToggleFilterHeaderAction(), + [CommandCodes.ToggleDualPane] = new ToggleDualPaneAction(), [CommandCodes.SelectAll] = new SelectAllAction(), [CommandCodes.InvertSelection] = new InvertSelectionAction(), [CommandCodes.ClearSelection] = new ClearSelectionAction(), diff --git a/src/Files.App/Data/Commands/Manager/ICommandManager.cs b/src/Files.App/Data/Commands/Manager/ICommandManager.cs index 56d91bdb5732..a2b5ff7c6191 100644 --- a/src/Files.App/Data/Commands/Manager/ICommandManager.cs +++ b/src/Files.App/Data/Commands/Manager/ICommandManager.cs @@ -33,6 +33,7 @@ public interface ICommandManager : IEnumerable IRichCommand ToggleToolbar { get; } IRichCommand ToggleShelfPane { get; } IRichCommand ToggleFilterHeader { get; } + IRichCommand ToggleDualPane { get; } IRichCommand CopyItem { get; } IRichCommand CopyItemPath { get; } diff --git a/src/Files.App/Data/Contracts/IShellPanesPage.cs b/src/Files.App/Data/Contracts/IShellPanesPage.cs index afeace482ef9..d2e6e1ba6ee8 100644 --- a/src/Files.App/Data/Contracts/IShellPanesPage.cs +++ b/src/Files.App/Data/Contracts/IShellPanesPage.cs @@ -54,6 +54,11 @@ public interface IShellPanesPage : IDisposable, INotifyPropertyChanged /// public void CloseActivePane(); + /// + /// Closes the non active/focused pane. + /// + public void CloseOtherPane(); + /// /// Focuses the other pane. /// diff --git a/src/Files.App/Strings/en-US/Resources.resw b/src/Files.App/Strings/en-US/Resources.resw index dc6dc947fbbf..b078f103dcc7 100644 --- a/src/Files.App/Strings/en-US/Resources.resw +++ b/src/Files.App/Strings/en-US/Resources.resw @@ -1106,6 +1106,12 @@ Toggle visibility of the filter header + + Toggle dual pane + + + Toggle dual pane mode + No preview available diff --git a/src/Files.App/Views/ShellPanesPage.xaml.cs b/src/Files.App/Views/ShellPanesPage.xaml.cs index 9617ed607149..ceb126b9f2dd 100644 --- a/src/Files.App/Views/ShellPanesPage.xaml.cs +++ b/src/Files.App/Views/ShellPanesPage.xaml.cs @@ -336,6 +336,18 @@ ShellPaneArrangement is ShellPaneArrangement.Vertical } } + /// + public void CloseOtherPane() + { + if (!IsMultiPaneActive) + return; + + if (ActivePane == (IShellPage)GetPane(0)!) + RemovePane(1); + else + RemovePane(0); + } + /// public void CloseActivePane() {