Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/Files.App/Actions/Navigation/FocusLeftPaneAction.cs
Original file line number Diff line number Diff line change
@@ -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<IContentPageContext>();

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;
}
}
}
}
47 changes: 47 additions & 0 deletions src/Files.App/Actions/Navigation/FocusRightPane.cs
Original file line number Diff line number Diff line change
@@ -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<IContentPageContext>();

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;
}
}
}
}
2 changes: 2 additions & 0 deletions src/Files.App/Data/Commands/Manager/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ public enum CommandCodes
CloseSelectedTab,
OpenNewPane,
ClosePane,
FocusLeftPane,
FocusRightPane,

// Play
PlayAll,
Expand Down
4 changes: 4 additions & 0 deletions src/Files.App/Data/Commands/Manager/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -360,6 +362,8 @@ public IEnumerator<IRichCommand> 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(),
Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Data/Commands/Manager/ICommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ public interface ICommandManager : IEnumerable<IRichCommand>
IRichCommand CloseSelectedTab { get; }
IRichCommand OpenNewPane { get; }
IRichCommand ClosePane { get; }
IRichCommand FocusLeftPane { get; }
IRichCommand FocusRightPane { get; }

IRichCommand PlayAll { get; }

Expand Down
4 changes: 4 additions & 0 deletions src/Files.App/Data/Contracts/IPanesPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
12 changes: 12 additions & 0 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -2678,6 +2678,18 @@
<data name="ClosePaneDescription" xml:space="preserve">
<value>Close right pane</value>
</data>
<data name="FocusLeftPane" xml:space="preserve">
<value>Focus left pane</value>
</data>
<data name="FocusLeftPaneDescription" xml:space="preserve">
<value>Switch focus to the left pane</value>
</data>
<data name="FocusRightPane" xml:space="preserve">
<value>Focus right pane</value>
</data>
<data name="FocusRightPaneDescription" xml:space="preserve">
<value>Switch focus to the right pane</value>
</data>
<data name="ToggleSidebar" xml:space="preserve">
<value>Toggle the sidebar</value>
</data>
Expand Down
11 changes: 0 additions & 11 deletions src/Files.App/Views/PaneHolderPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,6 @@
</ResourceDictionary>
</Page.Resources>

<Page.KeyboardAccelerators>
<KeyboardAccelerator
Key="Left"
Invoked="KeyboardAccelerator_Invoked"
Modifiers="Control,Shift" />
<KeyboardAccelerator
Key="Right"
Invoked="KeyboardAccelerator_Invoked"
Modifiers="Control,Shift" />
</Page.KeyboardAccelerators>

<Grid x:Name="RootGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition
Expand Down
72 changes: 34 additions & 38 deletions src/Files.App/Views/PaneHolderPage.xaml.cs
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic in here is a bit fragile but it's only temporary

Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ public IShellPage? ActivePane
NotifyPropertyChanged(nameof(IsRightPaneActive));
NotifyPropertyChanged(nameof(ActivePaneOrColumn));
NotifyPropertyChanged(nameof(FilesystemHelpers));

SetShadow();
}
}
}
Expand Down Expand Up @@ -243,9 +245,21 @@ public void CloseActivePane()
{
// NOTE: Can only close right pane at the moment
IsRightPaneVisible = false;

PaneLeft.Focus(FocusState.Programmatic);
SetShadow();
}

public void FocusLeftPane()
{
PaneLeft.Focus(FocusState.Programmatic);
}

public void FocusRightPane()
{
PaneRight.Focus(FocusState.Programmatic);
}

// Override methods

protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
Expand Down Expand Up @@ -305,30 +319,6 @@ private void MainWindow_SizeChanged(object sender, WindowSizeChangedEventArgs e)
WindowIsCompact = MainWindow.Instance.Bounds.Width <= Constants.UI.MultiplePaneWidthThreshold;
}

private void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)
{
args.Handled = true;
var ctrl = args.KeyboardAccelerator.Modifiers.HasFlag(VirtualKeyModifiers.Control);
var shift = args.KeyboardAccelerator.Modifiers.HasFlag(VirtualKeyModifiers.Shift);
var menu = args.KeyboardAccelerator.Modifiers.HasFlag(VirtualKeyModifiers.Menu);

switch (c: ctrl, s: shift, m: menu, k: args.KeyboardAccelerator.Key)
{
case (true, true, false, VirtualKey.Left): // ctrl + shift + "<-" select left pane
ActivePane = PaneLeft;
break;

case (true, true, false, VirtualKey.Right): // ctrl + shift + "->" 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()
Expand All @@ -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)
Expand All @@ -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)
Expand Down