Skip to content

RichCommand: TogglePreviewPane #11578

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 1 commit into from
Mar 6, 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
39 changes: 39 additions & 0 deletions src/Files.App/Actions/Show/TogglePreviewPaneAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Files.App.Commands;
using Files.App.Extensions;
using Files.App.ViewModels;
using System.ComponentModel;
using System.Threading.Tasks;
using Windows.System;

namespace Files.App.Actions
{
internal class TogglePreviewPaneAction : ObservableObject, IToggleAction
{
private readonly PreviewPaneViewModel viewModel = App.PreviewPaneViewModel;

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

public RichGlyph Glyph { get; } = new(opacityStyle: "ColorIconRightPane");
public HotKey HotKey { get; } = new(VirtualKey.P, VirtualKeyModifiers.Control);

public bool IsOn => viewModel.IsEnabled;

public TogglePreviewPaneAction()
{
viewModel.PropertyChanged += ViewModel_PropertyChanged;
}

public Task ExecuteAsync()
{
viewModel.IsEnabled = !IsOn;
return Task.CompletedTask;
}

private void ViewModel_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(PreviewPaneViewModel.IsEnabled))
OnPropertyChanged(nameof(IsOn));
}
}
}
1 change: 1 addition & 0 deletions src/Files.App/Commands/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public enum CommandCodes
// Show
ToggleShowHiddenItems,
ToggleShowFileExtensions,
TogglePreviewPane,

// File System
CopyItem,
Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Commands/Manager/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ internal class CommandManager : ICommandManager
public IRichCommand ToggleFullScreen => commands[CommandCodes.ToggleFullScreen];
public IRichCommand ToggleShowHiddenItems => commands[CommandCodes.ToggleShowHiddenItems];
public IRichCommand ToggleShowFileExtensions => commands[CommandCodes.ToggleShowFileExtensions];
public IRichCommand TogglePreviewPane => commands[CommandCodes.TogglePreviewPane];
public IRichCommand MultiSelect => commands[CommandCodes.MultiSelect];
public IRichCommand SelectAll => commands[CommandCodes.SelectAll];
public IRichCommand InvertSelection => commands[CommandCodes.InvertSelection];
Expand Down Expand Up @@ -76,6 +77,7 @@ public CommandManager()
[CommandCodes.ToggleFullScreen] = new ToggleFullScreenAction(),
[CommandCodes.ToggleShowHiddenItems] = new ToggleShowHiddenItemsAction(),
[CommandCodes.ToggleShowFileExtensions] = new ToggleShowFileExtensionsAction(),
[CommandCodes.TogglePreviewPane] = new TogglePreviewPaneAction(),
[CommandCodes.MultiSelect] = new MultiSelectAction(),
[CommandCodes.SelectAll] = new SelectAllAction(),
[CommandCodes.InvertSelection] = new InvertSelectionAction(),
Expand Down
1 change: 1 addition & 0 deletions src/Files.App/Commands/Manager/ICommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>

IRichCommand ToggleShowHiddenItems { get; }
IRichCommand ToggleShowFileExtensions { get; }
IRichCommand TogglePreviewPane { get; }

IRichCommand CopyItem { get; }
IRichCommand CutItem { get; }
Expand Down
7 changes: 2 additions & 5 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1065,9 +1065,6 @@
<data name="NavToolbarDetails.ToolTipService.ToolTip" xml:space="preserve">
<value>Details (Ctrl+Shift+1)</value>
</data>
<data name="PreviewPaneToggle.Label" xml:space="preserve">
<value>Preview</value>
</data>
<data name="NavToolbarLargeIcons.ToolTipService.ToolTip" xml:space="preserve">
<value>Large Icons (Ctrl+Shift+5)</value>
</data>
Expand Down Expand Up @@ -1134,8 +1131,8 @@
<data name="DesiredName" xml:space="preserve">
<value>Desired name</value>
</data>
<data name="PreviewPaneToggle.ToolTipService.ToolTip" xml:space="preserve">
<value>Toggle the preview pane (Ctrl+P)</value>
<data name="TogglePreviewPane" xml:space="preserve">
<value>Toggle the preview pane</value>
</data>
<data name="DetailsPanePreviewNotAvaliableText" xml:space="preserve">
<value>No preview available</value>
Expand Down
16 changes: 6 additions & 10 deletions src/Files.App/UserControls/InnerNavigationToolbar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -792,17 +792,13 @@
x:Name="PreviewPane"
Width="Auto"
MinWidth="40"
AccessKey="P"
AutomationProperties.Name="{helpers:ResourceString Name=PreviewPaneToggle/AutomationProperties/Name}"
IsChecked="{x:Bind PreviewPaneViewModel.IsEnabled, Mode=TwoWay}"
IsEnabled="{x:Bind ShowPreviewPaneButton, Mode=OneWay}"
Label="{helpers:ResourceString Name=PreviewPaneToggle/Label}"
AutomationProperties.Name="{x:Bind Commands.TogglePreviewPane.AutomationName}"
Content="{x:Bind Commands.TogglePreviewPane.Icon}"
IsChecked="{x:Bind Commands.TogglePreviewPane.IsOn, Mode=TwoWay}"
Label="{x:Bind Commands.TogglePreviewPane.Label}"
LabelPosition="Collapsed"
ToolTipService.ToolTip="{helpers:ResourceString Name=PreviewPaneToggle/ToolTipService/ToolTip}"
Visibility="{x:Bind ShowPreviewPaneButton, Mode=OneWay}">

<local:OpacityIcon Style="{StaticResource ColorIconRightPane}" />
</AppBarToggleButton>
ToolTipService.ToolTip="{x:Bind Commands.TogglePreviewPane.LabelWithHotKey, Mode=OneWay}"
Visibility="{x:Bind ShowPreviewPaneButton, Mode=OneWay}" />
<CommandBar.SecondaryCommands>
<AppBarButton
x:Name="NavToolbarNewPane"
Expand Down
5 changes: 0 additions & 5 deletions src/Files.App/Views/ColumnShellPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,6 @@
Invoked="KeyboardAccelerator_Invoked"
IsEnabled="{x:Bind IsCurrentInstance, Mode=OneWay}"
Modifiers="None" />
<KeyboardAccelerator
Key="P"
Invoked="KeyboardAccelerator_Invoked"
IsEnabled="{x:Bind IsCurrentInstance, Mode=OneWay}"
Modifiers="Control" />
<KeyboardAccelerator
Key="F"
Invoked="KeyboardAccelerator_Invoked"
Expand Down
4 changes: 0 additions & 4 deletions src/Files.App/Views/ColumnShellPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,6 @@ private async void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, Keybo
}
break;

case (true, false, false, true, VirtualKey.P): // ctrl + p, toggle preview pane
App.PreviewPaneViewModel.IsEnabled = !App.PreviewPaneViewModel.IsEnabled;
break;

case (true, false, false, true, VirtualKey.R): // ctrl + r, refresh
if (ToolbarViewModel.CanRefresh)
Refresh_Click();
Expand Down
5 changes: 0 additions & 5 deletions src/Files.App/Views/ModernShellPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@
Invoked="KeyboardAccelerator_Invoked"
IsEnabled="{x:Bind IsCurrentInstance, Mode=OneWay}"
Modifiers="None" />
<KeyboardAccelerator
Key="P"
Invoked="KeyboardAccelerator_Invoked"
IsEnabled="{x:Bind IsCurrentInstance, Mode=OneWay}"
Modifiers="Control" />
<KeyboardAccelerator
Key="F"
Invoked="KeyboardAccelerator_Invoked"
Expand Down
4 changes: 0 additions & 4 deletions src/Files.App/Views/ModernShellPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,6 @@ private async void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, Keybo

break;

case (true, false, false, true, VirtualKey.P): // ctrl + p, toggle preview pane
App.PreviewPaneViewModel.IsEnabled = !App.PreviewPaneViewModel.IsEnabled;
break;

case (true, false, false, true, VirtualKey.R): // ctrl + r, refresh
if (ToolbarViewModel.CanRefresh)
Refresh_Click();
Expand Down