diff --git a/src/Files.App/Actions/Navigation/FocusLeftPaneAction.cs b/src/Files.App/Actions/Navigation/FocusLeftPaneAction.cs new file mode 100644 index 000000000000..4d13203029a8 --- /dev/null +++ b/src/Files.App/Actions/Navigation/FocusLeftPaneAction.cs @@ -0,0 +1,47 @@ +// Copyright (c) 2024 Files Community +// Licensed under the MIT License. See the LICENSE. + +namespace Files.App.Actions +{ + internal sealed class FocusLeftPaneAction : ObservableObject, IAction + { + private readonly IContentPageContext context; + + public string Label + => "FocusLeftPane".GetLocalizedResource(); + + public string Description + => "FocusLeftPaneDescription".GetLocalizedResource(); + + public HotKey HotKey + => new(Keys.Left, KeyModifiers.CtrlShift); + + public bool IsExecutable + => context.IsMultiPaneActive; + + public FocusLeftPaneAction() + { + context = Ioc.Default.GetRequiredService(); + + context.PropertyChanged += Context_PropertyChanged; + } + + public Task ExecuteAsync(object? parameter = null) + { + context.ShellPage!.PaneHolder.FocusLeftPane(); + + return Task.CompletedTask; + } + + private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) + { + switch (e.PropertyName) + { + case nameof(IContentPageContext.ShellPage): + case nameof(IContentPageContext.IsMultiPaneActive): + OnPropertyChanged(nameof(IsExecutable)); + break; + } + } + } +} diff --git a/src/Files.App/Actions/Navigation/FocusRightPane.cs b/src/Files.App/Actions/Navigation/FocusRightPane.cs new file mode 100644 index 000000000000..2a166edffc9a --- /dev/null +++ b/src/Files.App/Actions/Navigation/FocusRightPane.cs @@ -0,0 +1,47 @@ +// Copyright (c) 2024 Files Community +// Licensed under the MIT License. See the LICENSE. + +namespace Files.App.Actions +{ + internal sealed class FocusRightPaneAction : ObservableObject, IAction + { + private readonly IContentPageContext context; + + public string Label + => "FocusRightPane".GetLocalizedResource(); + + public string Description + => "FocusRightPaneDescription".GetLocalizedResource(); + + public HotKey HotKey + => new(Keys.Right, KeyModifiers.CtrlShift); + + public bool IsExecutable + => context.IsMultiPaneActive; + + public FocusRightPaneAction() + { + context = Ioc.Default.GetRequiredService(); + + context.PropertyChanged += Context_PropertyChanged; + } + + public Task ExecuteAsync(object? parameter = null) + { + context.ShellPage!.PaneHolder.FocusRightPane(); + + return Task.CompletedTask; + } + + private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) + { + switch (e.PropertyName) + { + case nameof(IContentPageContext.ShellPage): + case nameof(IContentPageContext.IsMultiPaneActive): + OnPropertyChanged(nameof(IsExecutable)); + break; + } + } + } +} diff --git a/src/Files.App/Data/Commands/Manager/CommandCodes.cs b/src/Files.App/Data/Commands/Manager/CommandCodes.cs index d5b2da8d12f7..e357b9d16dea 100644 --- a/src/Files.App/Data/Commands/Manager/CommandCodes.cs +++ b/src/Files.App/Data/Commands/Manager/CommandCodes.cs @@ -190,6 +190,8 @@ public enum CommandCodes CloseSelectedTab, OpenNewPane, ClosePane, + FocusLeftPane, + FocusRightPane, // Play PlayAll, diff --git a/src/Files.App/Data/Commands/Manager/CommandManager.cs b/src/Files.App/Data/Commands/Manager/CommandManager.cs index a43cc08cd456..aa746cd91556 100644 --- a/src/Files.App/Data/Commands/Manager/CommandManager.cs +++ b/src/Files.App/Data/Commands/Manager/CommandManager.cs @@ -185,6 +185,8 @@ public IRichCommand this[HotKey hotKey] public IRichCommand CloseSelectedTab => commands[CommandCodes.CloseSelectedTab]; public IRichCommand OpenNewPane => commands[CommandCodes.OpenNewPane]; public IRichCommand ClosePane => commands[CommandCodes.ClosePane]; + public IRichCommand FocusLeftPane => commands[CommandCodes.FocusLeftPane]; + public IRichCommand FocusRightPane => commands[CommandCodes.FocusRightPane]; public IRichCommand OpenFileLocation => commands[CommandCodes.OpenFileLocation]; public IRichCommand PlayAll => commands[CommandCodes.PlayAll]; public IRichCommand GitFetch => commands[CommandCodes.GitFetch]; @@ -360,6 +362,8 @@ public IEnumerator GetEnumerator() => [CommandCodes.CloseSelectedTab] = new CloseSelectedTabAction(), [CommandCodes.OpenNewPane] = new OpenNewPaneAction(), [CommandCodes.ClosePane] = new ClosePaneAction(), + [CommandCodes.FocusLeftPane] = new FocusLeftPaneAction(), + [CommandCodes.FocusRightPane] = new FocusRightPaneAction(), [CommandCodes.OpenFileLocation] = new OpenFileLocationAction(), [CommandCodes.PlayAll] = new PlayAllAction(), [CommandCodes.GitFetch] = new GitFetchAction(), diff --git a/src/Files.App/Data/Commands/Manager/ICommandManager.cs b/src/Files.App/Data/Commands/Manager/ICommandManager.cs index 2105e2e56937..77d2a6d947c1 100644 --- a/src/Files.App/Data/Commands/Manager/ICommandManager.cs +++ b/src/Files.App/Data/Commands/Manager/ICommandManager.cs @@ -175,6 +175,8 @@ public interface ICommandManager : IEnumerable IRichCommand CloseSelectedTab { get; } IRichCommand OpenNewPane { get; } IRichCommand ClosePane { get; } + IRichCommand FocusLeftPane { get; } + IRichCommand FocusRightPane { get; } IRichCommand PlayAll { get; } diff --git a/src/Files.App/Data/Contracts/IPanesPage.cs b/src/Files.App/Data/Contracts/IPanesPage.cs index 4585e6ddca80..14f6c84557dd 100644 --- a/src/Files.App/Data/Contracts/IPanesPage.cs +++ b/src/Files.App/Data/Contracts/IPanesPage.cs @@ -18,6 +18,10 @@ public interface IPanesPage : IDisposable, INotifyPropertyChanged public void CloseActivePane(); + public void FocusLeftPane(); + + public void FocusRightPane(); + public bool IsLeftPaneActive { get; } public bool IsRightPaneActive { get; } diff --git a/src/Files.App/Strings/en-US/Resources.resw b/src/Files.App/Strings/en-US/Resources.resw index fbc1c41b613a..e327e1dd40da 100644 --- a/src/Files.App/Strings/en-US/Resources.resw +++ b/src/Files.App/Strings/en-US/Resources.resw @@ -2678,6 +2678,18 @@ Close right pane + + Focus left pane + + + Switch focus to the left pane + + + Focus right pane + + + Switch focus to the right pane + Toggle the sidebar diff --git a/src/Files.App/Views/PaneHolderPage.xaml b/src/Files.App/Views/PaneHolderPage.xaml index 18ae855f4d71..2942cc730085 100644 --- a/src/Files.App/Views/PaneHolderPage.xaml +++ b/src/Files.App/Views/PaneHolderPage.xaml @@ -25,17 +25,6 @@ - - - - - " select right pane - if (string.IsNullOrEmpty(NavParamsRight?.NavPath)) - { - NavParamsRight = new NavigationParams { NavPath = "Home" }; - } - IsRightPaneVisible = true; - ActivePane = PaneRight; - break; - } - } - private void Pane_ContentChanged(object sender, TabBarItemParameter e) { TabBarItemParameter = new() @@ -346,8 +336,6 @@ private void Pane_Loaded(object sender, RoutedEventArgs e) { ((UIElement)sender).GotFocus += Pane_GotFocus; ((UIElement)sender).RightTapped += Pane_RightTapped; - - PaneLeft.RootGrid.Translation = new System.Numerics.Vector3(0, 0, 8); } private void Pane_GotFocus(object sender, RoutedEventArgs e) @@ -369,22 +357,30 @@ private void Pane_GotFocus(object sender, RoutedEventArgs e) var activePane = isLeftPane ? PaneLeft : PaneRight; if (ActivePane != activePane) ActivePane = activePane; + } - // Add theme shadow to the active pane - if (isLeftPane) + private void SetShadow() + { + if (IsMultiPaneActive) { - if (PaneRight is not null) - PaneRight.RootGrid.Translation = new System.Numerics.Vector3(0, 0, 0); - if (PaneLeft is not null) - PaneLeft.RootGrid.Translation = new System.Numerics.Vector3(0, 0, 8); + // Add theme shadow to the active pane + if (IsLeftPaneActive) + { + if (PaneRight is not null) + PaneRight.RootGrid.Translation = new System.Numerics.Vector3(0, 0, 0); + if (PaneLeft is not null) + PaneLeft.RootGrid.Translation = new System.Numerics.Vector3(0, 0, 32); + } + else + { + if (PaneRight is not null) + PaneRight.RootGrid.Translation = new System.Numerics.Vector3(0, 0, 32); + if (PaneLeft is not null) + PaneLeft.RootGrid.Translation = new System.Numerics.Vector3(0, 0, 0); + } } else - { - if (PaneRight is not null) - PaneRight.RootGrid.Translation = new System.Numerics.Vector3(0, 0, 8); - if (PaneLeft is not null) - PaneLeft.RootGrid.Translation = new System.Numerics.Vector3(0, 0, 0); - } + PaneLeft.RootGrid.Translation = new System.Numerics.Vector3(0, 0, 8); } private void Pane_RightTapped(object sender, RoutedEventArgs e)