Skip to content

Commit 04c6fd7

Browse files
authored
Code Quality: Added action for toggling shelf pane (#16690)
1 parent f743f2e commit 04c6fd7

File tree

10 files changed

+71
-31
lines changed

10 files changed

+71
-31
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
namespace Files.App.Actions
5+
{
6+
internal sealed class ToggleShelfPaneAction : ObservableObject, IToggleAction
7+
{
8+
private readonly IGeneralSettingsService generalSettingsService = Ioc.Default.GetRequiredService<IGeneralSettingsService>();
9+
10+
public string Label
11+
=> Strings.ToggleShelfPane.GetLocalizedResource();
12+
13+
public string Description
14+
=> Strings.ToggleShelfPaneDescription.GetLocalizedResource();
15+
16+
public RichGlyph Glyph
17+
=> new(themedIconStyle: "App.ThemedIcons.Shelf");
18+
19+
// TODO Remove IsAccessibleGlobally when shelf feature is ready
20+
public bool IsAccessibleGlobally
21+
=> AppLifecycleHelper.AppEnvironment is AppEnvironment.Dev;
22+
23+
// TODO Remove IsExecutable when shelf feature is ready
24+
public bool IsExecutable
25+
=> AppLifecycleHelper.AppEnvironment is AppEnvironment.Dev;
26+
27+
public bool IsOn
28+
=> generalSettingsService.ShowShelfPane;
29+
30+
public ToggleShelfPaneAction()
31+
{
32+
generalSettingsService.PropertyChanged += GeneralSettingsService_PropertyChanged;
33+
}
34+
35+
public Task ExecuteAsync(object? parameter = null)
36+
{
37+
generalSettingsService.ShowShelfPane = !IsOn;
38+
39+
return Task.CompletedTask;
40+
}
41+
42+
private void GeneralSettingsService_PropertyChanged(object? sender, PropertyChangedEventArgs e)
43+
{
44+
if (e.PropertyName is nameof(GeneralSettingsService.ShowShelfPane))
45+
OnPropertyChanged(nameof(IsOn));
46+
}
47+
}
48+
}

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+
ToggleShelfPane,
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 ToggleShelfPane => commands[CommandCodes.ToggleShelfPane];
6061
public IRichCommand SelectAll => commands[CommandCodes.SelectAll];
6162
public IRichCommand InvertSelection => commands[CommandCodes.InvertSelection];
6263
public IRichCommand ClearSelection => commands[CommandCodes.ClearSelection];
@@ -260,6 +261,7 @@ public IEnumerator<IRichCommand> GetEnumerator() =>
260261
[CommandCodes.ToggleDetailsPane] = new ToggleDetailsPaneAction(),
261262
[CommandCodes.ToggleInfoPane] = new ToggleInfoPaneAction(),
262263
[CommandCodes.ToggleToolbar] = new ToggleToolbarAction(),
264+
[CommandCodes.ToggleShelfPane] = new ToggleShelfPaneAction(),
263265
[CommandCodes.SelectAll] = new SelectAllAction(),
264266
[CommandCodes.InvertSelection] = new InvertSelectionAction(),
265267
[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 ToggleShelfPane { get; }
3435

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

src/Files.App/Data/Items/ShelfItem.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using Files.Shared.Utils;
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
using Files.Shared.Utils;
25

36
namespace Files.App.Data.Items
47
{

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4022,6 +4022,9 @@
40224022
<data name="ToggleShelfPane" xml:space="preserve">
40234023
<value>Toggle the shelf pane</value>
40244024
</data>
4025+
<data name="ToggleShelfPaneDescription" xml:space="preserve">
4026+
<value>Toggle the shelf pane visibility</value>
4027+
</data>
40254028
<data name="ShowShelfPaneButtonInAddressBar" xml:space="preserve">
40264029
<value>Show shelf pane toggle in address bar</value>
40274030
</data>

src/Files.App/UserControls/AddressToolbar.xaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,17 +491,17 @@
491491

492492
<!-- Shelf Pane -->
493493
<ToggleButton
494-
x:Name="OpenShelfPaneButton"
494+
x:Name="ShelfPaneToggleButton"
495495
Width="36"
496496
Height="32"
497497
Padding="0"
498498
x:Load="{x:Bind ViewModel.ShowShelfPaneToggleButton, Mode=OneWay}"
499499
AccessKeyInvoked="Button_AccessKeyInvoked"
500-
AutomationProperties.Name="{helpers:ResourceString Name=ToggleShelfPane}"
500+
AutomationProperties.Name="{x:Bind ViewModel.Commands.ToggleShelfPane.Label}"
501501
Background="Transparent"
502502
BorderBrush="Transparent"
503-
IsChecked="{x:Bind ViewModel.ShowShelfPane, Mode=TwoWay}"
504-
ToolTipService.ToolTip="{helpers:ResourceString Name=ToggleShelfPane}">
503+
IsChecked="{x:Bind Commands.ToggleShelfPane.IsOn, Mode=TwoWay}"
504+
ToolTipService.ToolTip="{x:Bind ViewModel.Commands.ToggleShelfPane.LabelWithHotKey, Mode=OneWay}">
505505
<controls:ThemedIcon
506506
Width="20"
507507
Height="20"

src/Files.App/ViewModels/UserControls/AddressToolbarViewModel.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -166,20 +166,6 @@ public bool ShowHomeButton
166166
public bool ShowShelfPaneToggleButton
167167
=> AppearanceSettingsService.ShowShelfPaneToggleButton && AppLifecycleHelper.AppEnvironment is AppEnvironment.Dev;
168168

169-
170-
// TODO replace with action when feature is marked as stable
171-
public bool ShowShelfPane
172-
{
173-
get => GeneralSettingsService.ShowShelfPane;
174-
set
175-
{
176-
if (value == GeneralSettingsService.ShowShelfPane)
177-
return;
178-
179-
GeneralSettingsService.ShowShelfPane = value;
180-
}
181-
}
182-
183169
public ObservableCollection<NavigationBarSuggestionItem> NavigationBarSuggestions = [];
184170

185171
private CurrentInstanceViewModel instanceViewModel;
@@ -236,16 +222,6 @@ public AddressToolbarViewModel()
236222
break;
237223
}
238224
};
239-
240-
GeneralSettingsService.PropertyChanged += (s, e) =>
241-
{
242-
switch (e.PropertyName)
243-
{
244-
case nameof(GeneralSettingsService.ShowShelfPane):
245-
OnPropertyChanged(nameof(ShowShelfPane));
246-
break;
247-
}
248-
};
249225
}
250226

251227
private async void UpdateService_OnPropertyChanged(object? sender, PropertyChangedEventArgs e)

src/Files.Shared/Utils/IAsyncInitialize.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using System.Threading;
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
using System.Threading;
25
using System.Threading.Tasks;
36

47
namespace Files.Shared.Utils

src/Files.Shared/Utils/IWrapper.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
namespace Files.Shared.Utils
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
namespace Files.Shared.Utils
25
{
36
/// <summary>
47
/// Wraps and exposes <typeparamref name="T"/> implementation for access.

0 commit comments

Comments
 (0)