From 428901e0f0e50e4391c2d4486377f1bea6df8244 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Wed, 8 Jan 2025 22:33:10 -0500 Subject: [PATCH 1/4] Code Quality: Added action for toggling shelf pane --- .../Actions/Show/ToggleShelfPaneAction.cs | 47 +++++++++++++++++++ .../Data/Commands/Manager/CommandCodes.cs | 1 + .../Data/Commands/Manager/CommandManager.cs | 2 + .../Data/Commands/Manager/ICommandManager.cs | 1 + src/Files.App/Data/Items/ShelfItem.cs | 5 +- src/Files.App/Strings/en-US/Resources.resw | 3 ++ .../UserControls/AddressToolbar.xaml | 8 ++-- .../UserControls/AddressToolbarViewModel.cs | 24 ---------- src/Files.Shared/Utils/IAsyncInitialize.cs | 5 +- src/Files.Shared/Utils/IWrapper.cs | 5 +- 10 files changed, 70 insertions(+), 31 deletions(-) create mode 100644 src/Files.App/Actions/Show/ToggleShelfPaneAction.cs diff --git a/src/Files.App/Actions/Show/ToggleShelfPaneAction.cs b/src/Files.App/Actions/Show/ToggleShelfPaneAction.cs new file mode 100644 index 000000000000..ae54002af3cc --- /dev/null +++ b/src/Files.App/Actions/Show/ToggleShelfPaneAction.cs @@ -0,0 +1,47 @@ +// Copyright (c) Files Community +// Licensed under the MIT License. + +namespace Files.App.Actions +{ + internal sealed class ToggleShelfPaneAction : ObservableObject, IToggleAction + { + private readonly IGeneralSettingsService generalSettingsService = Ioc.Default.GetRequiredService(); + + public string Label + => Strings.ToggleShelfPane.GetLocalizedResource(); + + public string Description + => Strings.ToggleShelfPaneDescription.GetLocalizedResource(); + + public RichGlyph Glyph + => new(themedIconStyle: "App.ThemedIcons.Shelf"); + + // TODO Remove IsAccessibleGlobally when feature is ready + public bool IsAccessibleGlobally + => AppLifecycleHelper.AppEnvironment is AppEnvironment.Dev;; + + public bool IsExecutable + => AppLifecycleHelper.AppEnvironment is AppEnvironment.Dev; + + public bool IsOn + => generalSettingsService.ShowShelfPane; + + public ToggleShelfPaneAction() + { + generalSettingsService.PropertyChanged += GeneralSettingsService_PropertyChanged; + } + + public Task ExecuteAsync(object? parameter = null) + { + generalSettingsService.ShowShelfPane = !IsOn; + + return Task.CompletedTask; + } + + private void GeneralSettingsService_PropertyChanged(object? sender, PropertyChangedEventArgs e) + { + if (e.PropertyName is nameof(GeneralSettingsService.ShowShelfPane)) + OnPropertyChanged(nameof(IsOn)); + } + } +} diff --git a/src/Files.App/Data/Commands/Manager/CommandCodes.cs b/src/Files.App/Data/Commands/Manager/CommandCodes.cs index f0c6bbad4eed..0ea8a3416d76 100644 --- a/src/Files.App/Data/Commands/Manager/CommandCodes.cs +++ b/src/Files.App/Data/Commands/Manager/CommandCodes.cs @@ -26,6 +26,7 @@ public enum CommandCodes ToggleDetailsPane, ToggleInfoPane, ToggleToolbar, + ToggleShelfPane, // File System CopyItem, diff --git a/src/Files.App/Data/Commands/Manager/CommandManager.cs b/src/Files.App/Data/Commands/Manager/CommandManager.cs index 91de1b48bc59..d1e63fca40f5 100644 --- a/src/Files.App/Data/Commands/Manager/CommandManager.cs +++ b/src/Files.App/Data/Commands/Manager/CommandManager.cs @@ -57,6 +57,7 @@ public IRichCommand this[HotKey hotKey] public IRichCommand ToggleDetailsPane => commands[CommandCodes.ToggleDetailsPane]; public IRichCommand ToggleInfoPane => commands[CommandCodes.ToggleInfoPane]; public IRichCommand ToggleToolbar => commands[CommandCodes.ToggleToolbar]; + public IRichCommand ToggleShelfPane => commands[CommandCodes.ToggleShelfPane]; public IRichCommand SelectAll => commands[CommandCodes.SelectAll]; public IRichCommand InvertSelection => commands[CommandCodes.InvertSelection]; public IRichCommand ClearSelection => commands[CommandCodes.ClearSelection]; @@ -260,6 +261,7 @@ public IEnumerator GetEnumerator() => [CommandCodes.ToggleDetailsPane] = new ToggleDetailsPaneAction(), [CommandCodes.ToggleInfoPane] = new ToggleInfoPaneAction(), [CommandCodes.ToggleToolbar] = new ToggleToolbarAction(), + [CommandCodes.ToggleShelfPane] = new ToggleShelfPaneAction(), [CommandCodes.SelectAll] = new SelectAllAction(), [CommandCodes.InvertSelection] = new InvertSelectionAction(), [CommandCodes.ClearSelection] = new ClearSelectionAction(), diff --git a/src/Files.App/Data/Commands/Manager/ICommandManager.cs b/src/Files.App/Data/Commands/Manager/ICommandManager.cs index e96dc6b5e1c0..385fb56ec31f 100644 --- a/src/Files.App/Data/Commands/Manager/ICommandManager.cs +++ b/src/Files.App/Data/Commands/Manager/ICommandManager.cs @@ -31,6 +31,7 @@ public interface ICommandManager : IEnumerable IRichCommand ToggleDetailsPane { get; } IRichCommand ToggleInfoPane { get; } IRichCommand ToggleToolbar { get; } + IRichCommand ToggleShelfPane { get; } IRichCommand CopyItem { get; } IRichCommand CopyItemPath { get; } diff --git a/src/Files.App/Data/Items/ShelfItem.cs b/src/Files.App/Data/Items/ShelfItem.cs index 7facfabce5b9..fc8b554c333d 100644 --- a/src/Files.App/Data/Items/ShelfItem.cs +++ b/src/Files.App/Data/Items/ShelfItem.cs @@ -1,4 +1,7 @@ -using Files.Shared.Utils; +// Copyright (c) Files Community +// Licensed under the MIT License. + +using Files.Shared.Utils; namespace Files.App.Data.Items { diff --git a/src/Files.App/Strings/en-US/Resources.resw b/src/Files.App/Strings/en-US/Resources.resw index 5588e3984e7b..2892c9cde50d 100644 --- a/src/Files.App/Strings/en-US/Resources.resw +++ b/src/Files.App/Strings/en-US/Resources.resw @@ -4022,6 +4022,9 @@ Toggle the shelf pane + + Toggle the shelf pane visibility + Show shelf pane toggle in address bar diff --git a/src/Files.App/UserControls/AddressToolbar.xaml b/src/Files.App/UserControls/AddressToolbar.xaml index e387f49169a6..dc6c5357e935 100644 --- a/src/Files.App/UserControls/AddressToolbar.xaml +++ b/src/Files.App/UserControls/AddressToolbar.xaml @@ -491,17 +491,17 @@ + IsChecked="{x:Bind Commands.ToggleShelfPane.IsOn, Mode=TwoWay}" + ToolTipService.ToolTip="{x:Bind ViewModel.Commands.ToggleShelfPane.LabelWithHotKey, Mode=OneWay}"> AppearanceSettingsService.ShowShelfPaneToggleButton && AppLifecycleHelper.AppEnvironment is AppEnvironment.Dev; - - // TODO replace with action when feature is marked as stable - public bool ShowShelfPane - { - get => GeneralSettingsService.ShowShelfPane; - set - { - if (value == GeneralSettingsService.ShowShelfPane) - return; - - GeneralSettingsService.ShowShelfPane = value; - } - } - public ObservableCollection NavigationBarSuggestions = []; private CurrentInstanceViewModel instanceViewModel; @@ -236,16 +222,6 @@ public AddressToolbarViewModel() break; } }; - - GeneralSettingsService.PropertyChanged += (s, e) => - { - switch (e.PropertyName) - { - case nameof(GeneralSettingsService.ShowShelfPane): - OnPropertyChanged(nameof(ShowShelfPane)); - break; - } - }; } private async void UpdateService_OnPropertyChanged(object? sender, PropertyChangedEventArgs e) diff --git a/src/Files.Shared/Utils/IAsyncInitialize.cs b/src/Files.Shared/Utils/IAsyncInitialize.cs index 86bcfd7a8795..8591c225a96f 100644 --- a/src/Files.Shared/Utils/IAsyncInitialize.cs +++ b/src/Files.Shared/Utils/IAsyncInitialize.cs @@ -1,4 +1,7 @@ -using System.Threading; +// Copyright (c) Files Community +// Licensed under the MIT License. + +using System.Threading; using System.Threading.Tasks; namespace Files.Shared.Utils diff --git a/src/Files.Shared/Utils/IWrapper.cs b/src/Files.Shared/Utils/IWrapper.cs index cb9b39701d87..38a67cd768d5 100644 --- a/src/Files.Shared/Utils/IWrapper.cs +++ b/src/Files.Shared/Utils/IWrapper.cs @@ -1,4 +1,7 @@ -namespace Files.Shared.Utils +// Copyright (c) Files Community +// Licensed under the MIT License. + +namespace Files.Shared.Utils { /// /// Wraps and exposes implementation for access. From b717636c5a26911ab970013618e50f90fbafb849 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Wed, 8 Jan 2025 22:33:21 -0500 Subject: [PATCH 2/4] Update ToggleShelfPaneAction.cs --- src/Files.App/Actions/Show/ToggleShelfPaneAction.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App/Actions/Show/ToggleShelfPaneAction.cs b/src/Files.App/Actions/Show/ToggleShelfPaneAction.cs index ae54002af3cc..5087b6b8dd4c 100644 --- a/src/Files.App/Actions/Show/ToggleShelfPaneAction.cs +++ b/src/Files.App/Actions/Show/ToggleShelfPaneAction.cs @@ -18,7 +18,7 @@ public RichGlyph Glyph // TODO Remove IsAccessibleGlobally when feature is ready public bool IsAccessibleGlobally - => AppLifecycleHelper.AppEnvironment is AppEnvironment.Dev;; + => AppLifecycleHelper.AppEnvironment is AppEnvironment.Dev; public bool IsExecutable => AppLifecycleHelper.AppEnvironment is AppEnvironment.Dev; From 7dc9b5d07225287a67499d8cf7857ed90209d27d Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Wed, 8 Jan 2025 22:33:48 -0500 Subject: [PATCH 3/4] Update ToggleShelfPaneAction.cs --- src/Files.App/Actions/Show/ToggleShelfPaneAction.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Files.App/Actions/Show/ToggleShelfPaneAction.cs b/src/Files.App/Actions/Show/ToggleShelfPaneAction.cs index 5087b6b8dd4c..d81c2e603b32 100644 --- a/src/Files.App/Actions/Show/ToggleShelfPaneAction.cs +++ b/src/Files.App/Actions/Show/ToggleShelfPaneAction.cs @@ -20,6 +20,7 @@ public RichGlyph Glyph public bool IsAccessibleGlobally => AppLifecycleHelper.AppEnvironment is AppEnvironment.Dev; + // TODO Remove IsExecutable when feature is ready public bool IsExecutable => AppLifecycleHelper.AppEnvironment is AppEnvironment.Dev; From ad19f7401c195685b568ee5bdf75e037a0e63993 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Wed, 8 Jan 2025 22:33:57 -0500 Subject: [PATCH 4/4] Update ToggleShelfPaneAction.cs --- src/Files.App/Actions/Show/ToggleShelfPaneAction.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Files.App/Actions/Show/ToggleShelfPaneAction.cs b/src/Files.App/Actions/Show/ToggleShelfPaneAction.cs index d81c2e603b32..6d8c8d3ba808 100644 --- a/src/Files.App/Actions/Show/ToggleShelfPaneAction.cs +++ b/src/Files.App/Actions/Show/ToggleShelfPaneAction.cs @@ -16,11 +16,11 @@ public string Description public RichGlyph Glyph => new(themedIconStyle: "App.ThemedIcons.Shelf"); - // TODO Remove IsAccessibleGlobally when feature is ready + // TODO Remove IsAccessibleGlobally when shelf feature is ready public bool IsAccessibleGlobally => AppLifecycleHelper.AppEnvironment is AppEnvironment.Dev; - // TODO Remove IsExecutable when feature is ready + // TODO Remove IsExecutable when shelf feature is ready public bool IsExecutable => AppLifecycleHelper.AppEnvironment is AppEnvironment.Dev;