Skip to content

Commit

Permalink
Feature: Added shortcuts to switch between Preview & Detail panes (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
yaira2 authored Nov 10, 2023
1 parent 6a35907 commit b6bbe52
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 9 deletions.
46 changes: 46 additions & 0 deletions src/Files.App/Actions/Show/ToggleDetailsPaneAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

namespace Files.App.Actions
{
internal class ToggleDetailsPaneAction : ObservableObject, IToggleAction
{
private readonly PreviewPaneViewModel viewModel;
private readonly IPreviewPaneSettingsService previewSettingsService = Ioc.Default.GetRequiredService<IPreviewPaneSettingsService>();

public string Label
=> "ToggleDetailsPane".GetLocalizedResource();

public string Description
=> "ToggleDetailsPaneDescription".GetLocalizedResource();

public RichGlyph Glyph
=> new(opacityStyle: "ColorIconRightPane");

public HotKey HotKey
=> new(Keys.D, KeyModifiers.MenuCtrl);

public bool IsOn
=> viewModel.IsEnabled;

public ToggleDetailsPaneAction()
{
viewModel = Ioc.Default.GetRequiredService<PreviewPaneViewModel>();
viewModel.PropertyChanged += ViewModel_PropertyChanged;
}

public Task ExecuteAsync()
{
viewModel.IsEnabled = true;
previewSettingsService.ShowPreviewOnly = false;

return Task.CompletedTask;
}

private void ViewModel_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(PreviewPaneViewModel.IsEnabled))
OnPropertyChanged(nameof(IsOn));
}
}
}
41 changes: 41 additions & 0 deletions src/Files.App/Actions/Show/ToggleInfoPaneAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

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

public string Label
=> "ToggleInfoPane".GetLocalizedResource();

public string Description
=> "ToggleInfoPaneDescription".GetLocalizedResource();

public RichGlyph Glyph
=> new(opacityStyle: "ColorIconRightPane");

public bool IsOn
=> viewModel.IsEnabled;

public ToggleInfoPaneAction()
{
viewModel = Ioc.Default.GetRequiredService<PreviewPaneViewModel>();
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));
}
}
}
6 changes: 4 additions & 2 deletions src/Files.App/Actions/Show/TogglePreviewPaneAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Files.App.Actions
internal class TogglePreviewPaneAction : ObservableObject, IToggleAction
{
private readonly PreviewPaneViewModel viewModel;
private readonly IPreviewPaneSettingsService previewSettingsService = Ioc.Default.GetRequiredService<IPreviewPaneSettingsService>();

public string Label
=> "TogglePreviewPane".GetLocalizedResource();
Expand All @@ -17,7 +18,7 @@ public RichGlyph Glyph
=> new(opacityStyle: "ColorIconRightPane");

public HotKey HotKey
=> new(Keys.P, KeyModifiers.Ctrl);
=> new(Keys.P, KeyModifiers.MenuCtrl);

public bool IsOn
=> viewModel.IsEnabled;
Expand All @@ -30,7 +31,8 @@ public TogglePreviewPaneAction()

public Task ExecuteAsync()
{
viewModel.IsEnabled = !IsOn;
viewModel.IsEnabled = true;
previewSettingsService.ShowPreviewOnly = true;

return Task.CompletedTask;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Data/Commands/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public enum CommandCodes
ToggleShowHiddenItems,
ToggleShowFileExtensions,
TogglePreviewPane,
ToggleDetailsPane,
ToggleInfoPane,

// File System
CopyItem,
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 @@ -51,6 +51,8 @@ public IRichCommand this[HotKey hotKey]
public IRichCommand ToggleShowHiddenItems => commands[CommandCodes.ToggleShowHiddenItems];
public IRichCommand ToggleShowFileExtensions => commands[CommandCodes.ToggleShowFileExtensions];
public IRichCommand TogglePreviewPane => commands[CommandCodes.TogglePreviewPane];
public IRichCommand ToggleDetailsPane => commands[CommandCodes.ToggleDetailsPane];
public IRichCommand ToggleInfoPane => commands[CommandCodes.ToggleInfoPane];
public IRichCommand SelectAll => commands[CommandCodes.SelectAll];
public IRichCommand InvertSelection => commands[CommandCodes.InvertSelection];
public IRichCommand ClearSelection => commands[CommandCodes.ClearSelection];
Expand Down Expand Up @@ -212,6 +214,8 @@ public CommandManager()
[CommandCodes.ToggleShowHiddenItems] = new ToggleShowHiddenItemsAction(),
[CommandCodes.ToggleShowFileExtensions] = new ToggleShowFileExtensionsAction(),
[CommandCodes.TogglePreviewPane] = new TogglePreviewPaneAction(),
[CommandCodes.ToggleDetailsPane] = new ToggleDetailsPaneAction(),
[CommandCodes.ToggleInfoPane] = new ToggleInfoPaneAction(),
[CommandCodes.SelectAll] = new SelectAllAction(),
[CommandCodes.InvertSelection] = new InvertSelectionAction(),
[CommandCodes.ClearSelection] = new ClearSelectionAction(),
Expand Down
1 change: 1 addition & 0 deletions src/Files.App/Data/Commands/Manager/ICommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
IRichCommand ToggleShowHiddenItems { get; }
IRichCommand ToggleShowFileExtensions { get; }
IRichCommand TogglePreviewPane { get; }
IRichCommand ToggleInfoPane { get; }

IRichCommand CopyItem { get; }
IRichCommand CopyPath { 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 @@ -1053,6 +1053,15 @@
<data name="TogglePreviewPane" xml:space="preserve">
<value>Toggle the preview pane</value>
</data>
<data name="ToggleDetailsPane" xml:space="preserve">
<value>Toggle the details pane</value>
</data>
<data name="ToggleInfoPane" xml:space="preserve">
<value>Toggle the details/preview pane</value>
</data>
<data name="ToggleInfoPaneDescription" xml:space="preserve">
<value>Toggles the details/preview pane</value>
</data>
<data name="DetailsPanePreviewNotAvaliableText" xml:space="preserve">
<value>No preview available</value>
</data>
Expand Down Expand Up @@ -2397,6 +2406,9 @@
<data name="TogglePreviewPaneDescription" xml:space="preserve">
<value>Toggle whether to show preview pane</value>
</data>
<data name="ToggleDetailsPaneDescription" xml:space="preserve">
<value>Toggle the details pane</value>
</data>
<data name="ToggleSidebarDescription" xml:space="preserve">
<value>Toggle whether to show sidebar</value>
</data>
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/UserControls/FilePreviews/MediaPreview.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<KeyboardAccelerator
Key="Space"
Invoked="TogglePlaybackAcceleratorInvoked"
Modifiers="Control" />
Modifiers="Menu" />
</UserControl.KeyboardAccelerators>

<Border CornerRadius="{StaticResource ControlCornerRadius}">
Expand Down
12 changes: 6 additions & 6 deletions src/Files.App/UserControls/InnerNavigationToolbar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -911,19 +911,19 @@

</AppBarButton>

<!-- Toggle Preview Pane -->
<!-- Toggle Preview\Details Pane -->
<AppBarToggleButton
x:Name="PreviewPane"
Width="Auto"
MinWidth="40"
AccessKey="P"
AutomationProperties.Name="{x:Bind Commands.TogglePreviewPane.AutomationName}"
IsChecked="{x:Bind Commands.TogglePreviewPane.IsOn, Mode=TwoWay}"
Label="{x:Bind Commands.TogglePreviewPane.Label}"
AutomationProperties.Name="{x:Bind Commands.ToggleInfoPane.AutomationName}"
IsChecked="{x:Bind Commands.ToggleInfoPane.IsOn, Mode=TwoWay}"
Label="{x:Bind Commands.ToggleInfoPane.Label}"
LabelPosition="Collapsed"
ToolTipService.ToolTip="{x:Bind Commands.TogglePreviewPane.LabelWithHotKey, Mode=OneWay}"
ToolTipService.ToolTip="{x:Bind Commands.ToggleInfoPane.LabelWithHotKey, Mode=OneWay}"
Visibility="{x:Bind ShowPreviewPaneButton, Mode=OneWay}">
<local:OpacityIcon IsSelected="{x:Bind Commands.TogglePreviewPane.IsOn, Mode=OneWay}" Style="{x:Bind Commands.TogglePreviewPane.OpacityStyle}" />
<local:OpacityIcon IsSelected="{x:Bind Commands.ToggleInfoPane.IsOn, Mode=OneWay}" Style="{x:Bind Commands.ToggleInfoPane.OpacityStyle}" />
</AppBarToggleButton>

<!-- 3 Dots Commands -->
Expand Down

0 comments on commit b6bbe52

Please sign in to comment.