Skip to content

Commit 90d6f5b

Browse files
author
Gness Erquint
committed
Added a ToggleSidebar action, imitating 4af2d59 as a template.
1 parent 39df64d commit 90d6f5b

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) 2024 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
namespace Files.App.Actions
5+
{
6+
internal sealed class ToggleSidebarAction : ObservableObject, IToggleAction
7+
{
8+
private IAppearanceSettingsService AppearanceSettingsService { get; } = Ioc.Default.GetRequiredService<IAppearanceSettingsService>();
9+
10+
public string Label
11+
=> "ToggleSidebar".GetLocalizedResource();
12+
13+
public string Description
14+
=> "ToggleSidebar".GetLocalizedResource();
15+
16+
public HotKey HotKey
17+
=> new(Keys.S, KeyModifiers.CtrlAlt);
18+
19+
public bool IsOn
20+
=> AppearanceSettingsService.IsSidebarOpen;
21+
22+
public ToggleSidebarAction()
23+
{
24+
AppearanceSettingsService.PropertyChanged += ViewModel_PropertyChanged;
25+
}
26+
27+
public Task ExecuteAsync(object? parameter = null)
28+
{
29+
AppearanceSettingsService.IsSidebarOpen = !IsOn;
30+
31+
return Task.CompletedTask;
32+
}
33+
34+
private void ViewModel_PropertyChanged(object? sender, PropertyChangedEventArgs e)
35+
{
36+
if (e.PropertyName is nameof(AppearanceSettingsService.IsSidebarOpen))
37+
OnPropertyChanged(nameof(IsOn));
38+
}
39+
}
40+
}

src/Files.App/Data/Commands/Manager/CommandCodes.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public enum CommandCodes
2626
ToggleDetailsPane,
2727
ToggleInfoPane,
2828
ToggleToolbar,
29+
ToggleSidebar,
2930

3031
// File System
3132
CopyItem,

src/Files.App/Data/Commands/Manager/CommandManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public IRichCommand this[HotKey hotKey]
5757
public IRichCommand ToggleDetailsPane => commands[CommandCodes.ToggleDetailsPane];
5858
public IRichCommand ToggleInfoPane => commands[CommandCodes.ToggleInfoPane];
5959
public IRichCommand ToggleToolbar => commands[CommandCodes.ToggleToolbar];
60+
public IRichCommand ToggleSidebar => commands[CommandCodes.ToggleSidebar];
6061
public IRichCommand SelectAll => commands[CommandCodes.SelectAll];
6162
public IRichCommand InvertSelection => commands[CommandCodes.InvertSelection];
6263
public IRichCommand ClearSelection => commands[CommandCodes.ClearSelection];
@@ -253,6 +254,7 @@ public IEnumerator<IRichCommand> GetEnumerator() =>
253254
[CommandCodes.ToggleDetailsPane] = new ToggleDetailsPaneAction(),
254255
[CommandCodes.ToggleInfoPane] = new ToggleInfoPaneAction(),
255256
[CommandCodes.ToggleToolbar] = new ToggleToolbarAction(),
257+
[CommandCodes.ToggleSidebar] = new ToggleSidebarAction(),
256258
[CommandCodes.SelectAll] = new SelectAllAction(),
257259
[CommandCodes.InvertSelection] = new InvertSelectionAction(),
258260
[CommandCodes.ClearSelection] = new ClearSelectionAction(),

src/Files.App/Data/Commands/Manager/ICommandManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
3131
IRichCommand ToggleDetailsPane { get; }
3232
IRichCommand ToggleInfoPane { get; }
3333
IRichCommand ToggleToolbar { get; }
34+
IRichCommand ToggleSidebar { get; }
3435

3536
IRichCommand CopyItem { get; }
3637
IRichCommand CopyItemPath { get; }

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,9 @@
10911091
<data name="ToggleToolbar" xml:space="preserve">
10921092
<value>Toggle the Toolbar</value>
10931093
</data>
1094+
<data name="ToggleSidebar" xml:space="preserve">
1095+
<value>Toggle the Sidebar</value>
1096+
</data>
10941097
<data name="DetailsPanePreviewNotAvaliableText" xml:space="preserve">
10951098
<value>No preview available</value>
10961099
</data>

0 commit comments

Comments
 (0)