Skip to content

RichCommands: Open & Close Pane #12002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 14, 2023
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/ClosePaneAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Extensions;
using System.ComponentModel;
using System.Threading.Tasks;

namespace Files.App.Actions
{
internal class ClosePaneAction : ObservableObject, IAction
{
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();

public string Label { get; } = "NavigationToolbarClosePane/Label".GetLocalizedResource();

public string Description { get; } = "TODO: Need to be described.";

public HotKey HotKey { get; } = new(Keys.W, KeyModifiers.CtrlShift);

public RichGlyph Glyph { get; } = new("\uE89F");

public bool IsExecutable => context.IsMultiPaneActive;

public ClosePaneAction()
{
context.PropertyChanged += Context_PropertyChanged;
}

public Task ExecuteAsync()
{
context.ShellPage!.PaneHolder.CloseActivePane();
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;
}
}
}
}
49 changes: 49 additions & 0 deletions src/Files.App/Actions/Navigation/OpenNewPaneAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Extensions;
using System.ComponentModel;
using System.Threading.Tasks;

namespace Files.App.Actions
{
internal class OpenNewPaneAction : ObservableObject, IAction
{
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();

public string Label { get; } = "NavigationToolbarNewPane/Label".GetLocalizedResource();

public string Description { get; } = "TODO: Need to be described.";

public HotKey HotKey { get; } = new(Keys.OemPlus, KeyModifiers.MenuShift);

public HotKey SecondHotKey { get; } = new(Keys.Add, KeyModifiers.MenuShift);

public RichGlyph Glyph { get; } = new(opacityStyle: "ColorIconRightPane");

public bool IsExecutable => context.IsMultiPaneEnabled && !context.IsMultiPaneActive;

public OpenNewPaneAction()
{
context.PropertyChanged += Context_PropertyChanged;
}

public Task ExecuteAsync()
{
context.ShellPage!.PaneHolder.OpenPathInNewPane("Home");
return Task.CompletedTask;
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IContentPageContext.IsMultiPaneEnabled):
case nameof(IContentPageContext.IsMultiPaneActive):
OnPropertyChanged(nameof(IsExecutable));
break;
}
}
}
}
2 changes: 2 additions & 0 deletions src/Files.App/Commands/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,7 @@ public enum CommandCodes
PreviousTab,
NextTab,
CloseSelectedTab,
OpenNewPane,
ClosePane,
}
}
4 changes: 4 additions & 0 deletions src/Files.App/Commands/Manager/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ internal class CommandManager : ICommandManager
public IRichCommand PreviousTab => commands[CommandCodes.PreviousTab];
public IRichCommand NextTab => commands[CommandCodes.NextTab];
public IRichCommand CloseSelectedTab => commands[CommandCodes.CloseSelectedTab];
public IRichCommand OpenNewPane => commands[CommandCodes.OpenNewPane];
public IRichCommand ClosePane => commands[CommandCodes.ClosePane];

public CommandManager()
{
Expand Down Expand Up @@ -270,6 +272,8 @@ public CommandManager()
[CommandCodes.PreviousTab] = new PreviousTabAction(),
[CommandCodes.NextTab] = new NextTabAction(),
[CommandCodes.CloseSelectedTab] = new CloseSelectedTabAction(),
[CommandCodes.OpenNewPane] = new OpenNewPaneAction(),
[CommandCodes.ClosePane] = new ClosePaneAction(),
};

[DebuggerDisplay("Command None")]
Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Commands/Manager/ICommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
IRichCommand PreviousTab { get; }
IRichCommand NextTab { get; }
IRichCommand CloseSelectedTab { get; }
IRichCommand OpenNewPane { get; }
IRichCommand ClosePane { get; }
}
}
31 changes: 29 additions & 2 deletions src/Files.App/Contexts/ContentPage/ContentPageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,20 @@ internal class ContentPageContext : ObservableObject, IContentPageContext
private IReadOnlyList<ListedItem> selectedItems = emptyItems;
public IReadOnlyList<ListedItem> SelectedItems => selectedItems;

public bool CanRefresh => ShellPage is not null && ShellPage.ToolbarViewModel.CanRefresh;
public bool CanRefresh => ShellPage is not null && ShellPage.ToolbarViewModel.CanRefresh;

public bool CanGoBack => ShellPage is not null && ShellPage.ToolbarViewModel.CanGoBack;

public bool CanGoForward => ShellPage is not null && ShellPage.ToolbarViewModel.CanGoForward;

public bool CanNavigateToParent => ShellPage is not null && ShellPage.ToolbarViewModel.CanNavigateToParent;

public bool IsSearchBoxVisible => ShellPage is not null && ShellPage.ToolbarViewModel.IsSearchBoxVisible;

public bool IsMultiPaneEnabled => ShellPage is not null && ShellPage.PaneHolder is not null && ShellPage.PaneHolder.IsMultiPaneEnabled;

public bool IsMultiPaneActive => ShellPage is not null && ShellPage.PaneHolder is not null && ShellPage.PaneHolder.IsMultiPaneActive;

public ContentPageContext()
{
context.Changing += Context_Changing;
Expand All @@ -62,6 +66,9 @@ private void Context_Changing(object? sender, EventArgs e)
page.ContentChanged -= Page_ContentChanged;
page.InstanceViewModel.PropertyChanged -= InstanceViewModel_PropertyChanged;
page.ToolbarViewModel.PropertyChanged -= ToolbarViewModel_PropertyChanged;

if (page.PaneHolder is not null)
page.PaneHolder.PropertyChanged -= PaneHolder_PropertyChanged;
}

if (filesystemViewModel is not null)
Expand All @@ -78,6 +85,9 @@ private void Context_Changed(object? sender, EventArgs e)
page.ContentChanged += Page_ContentChanged;
page.InstanceViewModel.PropertyChanged += InstanceViewModel_PropertyChanged;
page.ToolbarViewModel.PropertyChanged += ToolbarViewModel_PropertyChanged;

if (page.PaneHolder is not null)
page.PaneHolder.PropertyChanged += PaneHolder_PropertyChanged;
}

filesystemViewModel = ShellPage?.FilesystemViewModel;
Expand All @@ -95,11 +105,26 @@ private void Page_PropertyChanged(object? sender, PropertyChangedEventArgs e)
case nameof(ShellPage.CurrentPageType):
OnPropertyChanged(nameof(PageLayoutType));
break;
case nameof(ShellPage.PaneHolder):
OnPropertyChanged(nameof(IsMultiPaneEnabled));
OnPropertyChanged(nameof(IsMultiPaneActive));
break;
}
}

private void Page_ContentChanged(object? sender, TabItemArguments e) => Update();

private void PaneHolder_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IPaneHolder.IsMultiPaneEnabled):
case nameof(IPaneHolder.IsMultiPaneActive):
OnPropertyChanged(e.PropertyName);
break;
}
}

private void InstanceViewModel_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
Expand Down Expand Up @@ -152,6 +177,8 @@ private void Update()
OnPropertyChanged(nameof(CanGoForward));
OnPropertyChanged(nameof(CanNavigateToParent));
OnPropertyChanged(nameof(CanRefresh));
OnPropertyChanged(nameof(IsMultiPaneEnabled));
OnPropertyChanged(nameof(IsMultiPaneActive));
}

private void UpdatePageType()
Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/Contexts/ContentPage/IContentPageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ public interface IContentPageContext : INotifyPropertyChanged
bool CanNavigateToParent { get; }

bool IsSearchBoxVisible { get; }

bool IsMultiPaneEnabled { get; }
bool IsMultiPaneActive { get; }
}
}
6 changes: 0 additions & 6 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1845,12 +1845,6 @@
<data name="Home" xml:space="preserve">
<value>Home</value>
</data>
<data name="NavigationToolbarNewPane.KeyboardAcceleratorTextOverride" xml:space="preserve">
<value>Alt+Shift++</value>
</data>
<data name="NavigationToolbarClosePane.KeyboardAcceleratorTextOverride" xml:space="preserve">
<value>Ctrl+Shift+W</value>
</data>
<data name="NavigationToolbarNewWindow.KeyboardAcceleratorTextOverride" xml:space="preserve">
<value>Ctrl+N</value>
</data>
Expand Down
33 changes: 10 additions & 23 deletions src/Files.App/UserControls/InnerNavigationToolbar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -812,34 +812,21 @@
<CommandBar.SecondaryCommands>
<AppBarButton
x:Name="NavToolbarNewPane"
x:Load="{x:Bind converters:MultiBooleanConverter.AndNotConvert(ShowMultiPaneControls, IsMultiPaneActive), Mode=OneWay}"
Command="{x:Bind ViewModel.OpenNewPaneCommand, Mode=OneWay}"
KeyboardAcceleratorTextOverride="{helpers:ResourceString Name=NavigationToolbarNewPane/KeyboardAcceleratorTextOverride}"
Label="{helpers:ResourceString Name=NavigationToolbarNewPane/Label}">

<local:OpacityIcon Style="{StaticResource ColorIconRightPane}" />
<AppBarButton.KeyboardAccelerators>
<KeyboardAccelerator
Key="Add"
IsEnabled="False"
Modifiers="Menu,Shift" />
</AppBarButton.KeyboardAccelerators>
x:Load="{x:Bind Commands.OpenNewPane.IsExecutable, Mode=OneWay}"
Command="{x:Bind Commands.OpenNewPane, Mode=OneWay}"
Label="{x:Bind Commands.OpenNewPane.Label}"
ToolTipService.ToolTip="{x:Bind Commands.OpenNewPane.LabelWithHotKey, Mode=OneWay}">
<local:OpacityIcon Style="{x:Bind Commands.OpenNewPane.OpacityStyle}" />
</AppBarButton>
<AppBarButton
x:Name="NavToolbarClosePane"
x:Load="{x:Bind IsMultiPaneActive, Mode=OneWay}"
Command="{x:Bind ViewModel.ClosePaneCommand, Mode=OneWay}"
KeyboardAcceleratorTextOverride="{helpers:ResourceString Name=NavigationToolbarClosePane/KeyboardAcceleratorTextOverride}"
Label="{helpers:ResourceString Name=NavigationToolbarClosePane/Label}">
x:Load="{x:Bind Commands.ClosePane.IsExecutable, Mode=OneWay}"
Command="{x:Bind Commands.ClosePane, Mode=OneWay}"
Label="{x:Bind Commands.ClosePane.Label}"
ToolTipService.ToolTip="{x:Bind Commands.ClosePane.LabelWithHotKey, Mode=OneWay}">
<AppBarButton.Icon>
<FontIcon Glyph="&#xE89F;" />
<FontIcon Glyph="{x:Bind Commands.ClosePane.Glyph.BaseGlyph}" />
</AppBarButton.Icon>
<AppBarButton.KeyboardAccelerators>
<KeyboardAccelerator
Key="W"
IsEnabled="False"
Modifiers="Control,Shift" />
</AppBarButton.KeyboardAccelerators>
</AppBarButton>
<AppBarButton
x:Name="NavToolbarNewWindow"
Expand Down
21 changes: 0 additions & 21 deletions src/Files.App/UserControls/InnerNavigationToolbar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,6 @@ public bool ShowPreviewPaneButton
// Using a DependencyProperty as the backing store for ShowPreviewPaneButton. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ShowPreviewPaneButtonProperty =
DependencyProperty.Register("ShowPreviewPaneButton", typeof(bool), typeof(AddressToolbar), new PropertyMetadata(null));

public bool ShowMultiPaneControls
{
get => (bool)GetValue(ShowMultiPaneControlsProperty);
set => SetValue(ShowMultiPaneControlsProperty, value);
}

// Using a DependencyProperty as the backing store for ShowMultiPaneControls. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ShowMultiPaneControlsProperty =
DependencyProperty.Register(nameof(ShowMultiPaneControls), typeof(bool), typeof(AddressToolbar), new PropertyMetadata(null));

public bool IsMultiPaneActive
{
get { return (bool)GetValue(IsMultiPaneActiveProperty); }
set { SetValue(IsMultiPaneActiveProperty, value); }
}

// Using a DependencyProperty as the backing store for IsMultiPaneActive. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsMultiPaneActiveProperty =
DependencyProperty.Register("IsMultiPaneActive", typeof(bool), typeof(AddressToolbar), new PropertyMetadata(false));

private void NewEmptySpace_Opening(object sender, object e)
{
if (!ViewModel.InstanceViewModel.CanCreateFileInPage)
Expand Down
4 changes: 0 additions & 4 deletions src/Files.App/ViewModels/ToolbarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,6 @@ private void SearchRegion_Escaped(object? sender, ISearchBox searchBox)

public IAsyncRelayCommand? OpenNewWindowCommand { get; set; }

public ICommand? OpenNewPaneCommand { get; set; }

public ICommand? ClosePaneCommand { get; set; }

public ICommand? CreateNewFileCommand { get; set; }

public ICommand? Share { get; set; }
Expand Down
2 changes: 0 additions & 2 deletions src/Files.App/Views/BaseShellPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,6 @@ protected virtual void ShellPage_NavigationRequested(object sender, PathNavigati
protected void InitToolbarCommands()
{
ToolbarViewModel.OpenNewWindowCommand = new AsyncRelayCommand(NavigationHelpers.LaunchNewWindowAsync);
ToolbarViewModel.OpenNewPaneCommand = new RelayCommand(() => PaneHolder?.OpenPathInNewPane("Home".GetLocalizedResource()));
ToolbarViewModel.ClosePaneCommand = new RelayCommand(() => PaneHolder?.CloseActivePane());
ToolbarViewModel.CreateNewFileCommand = new RelayCommand<ShellNewEntry>(x => UIFilesystemHelpers.CreateFileFromDialogResultType(AddItemDialogItemType.File, x, this));
ToolbarViewModel.PropertiesCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.ShowPropertiesCommand.Execute(null));
ToolbarViewModel.UpdateCommand = new AsyncRelayCommand(async () => await updateSettingsService.DownloadUpdates());
Expand Down
4 changes: 0 additions & 4 deletions src/Files.App/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,7 @@ private void UpdateNavToolbarProperties()
NavToolbar.ViewModel = SidebarAdaptiveViewModel.PaneHolder?.ActivePaneOrColumn.ToolbarViewModel;

if (InnerNavigationToolbar is not null)
{
InnerNavigationToolbar.ViewModel = SidebarAdaptiveViewModel.PaneHolder?.ActivePaneOrColumn.ToolbarViewModel;
InnerNavigationToolbar.ShowMultiPaneControls = SidebarAdaptiveViewModel.PaneHolder?.IsMultiPaneEnabled ?? false;
InnerNavigationToolbar.IsMultiPaneActive = SidebarAdaptiveViewModel.PaneHolder?.IsMultiPaneActive ?? false;
}
}

protected override void OnNavigatedTo(NavigationEventArgs e)
Expand Down
12 changes: 0 additions & 12 deletions src/Files.App/Views/PaneHolderPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,6 @@
Key="Right"
Invoked="KeyboardAccelerator_Invoked"
Modifiers="Control,Shift" />
<KeyboardAccelerator
Key="W"
Invoked="KeyboardAccelerator_Invoked"
Modifiers="Control,Shift" />
<KeyboardAccelerator
Key="Add"
Invoked="KeyboardAccelerator_Invoked"
Modifiers="Menu,Shift" />
<KeyboardAccelerator
Key="{x:Bind local:PaneHolderPage.PlusKey}"
Invoked="KeyboardAccelerator_Invoked"
Modifiers="Menu,Shift" />
</Page.KeyboardAccelerators>

<Grid x:Name="RootGrid">
Expand Down
15 changes: 0 additions & 15 deletions src/Files.App/Views/PaneHolderPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,6 @@ public bool IsCurrentInstance
}
}

public const VirtualKey PlusKey = (VirtualKey)187;

public PaneHolderPage()
{
InitializeComponent();
Expand Down Expand Up @@ -297,19 +295,6 @@ private void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, KeyboardAcc
IsRightPaneVisible = true;
ActivePane = PaneRight;
break;

case (true, true, false, VirtualKey.W): // ctrl + shift + "W" close right pane
IsRightPaneVisible = false;
break;

case (false, true, true, VirtualKey.Add): // alt + shift + "+" open pane
case (false, true, true, PlusKey):
if (string.IsNullOrEmpty(NavParamsRight?.NavPath))
{
NavParamsRight = new NavigationParams { NavPath = "Home" };
}
IsRightPaneVisible = true;
break;
}
}

Expand Down