From bb92cd7124c184a7eaf567e183b3e9ac39220b5d Mon Sep 17 00:00:00 2001 From: Marco Franzen Date: Thu, 23 Mar 2023 01:15:42 +0100 Subject: [PATCH 1/8] fix IsExecutable for rotate left/right --- src/Files.App/Actions/Content/ImageEdition/RotateLeftAction.cs | 2 +- src/Files.App/Actions/Content/ImageEdition/RotateRightAction.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Files.App/Actions/Content/ImageEdition/RotateLeftAction.cs b/src/Files.App/Actions/Content/ImageEdition/RotateLeftAction.cs index c1d4f0860ed3..681e6b77dabe 100644 --- a/src/Files.App/Actions/Content/ImageEdition/RotateLeftAction.cs +++ b/src/Files.App/Actions/Content/ImageEdition/RotateLeftAction.cs @@ -45,7 +45,7 @@ and not ContentPageTypes.ZipFolder private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) { - if (e.PropertyName is nameof(IContentPageContext.HasSelection)) + if (e.PropertyName is nameof(IContentPageContext.SelectedItem)) { if (context.ShellPage is not null && context.ShellPage.SlimContentPage is not null) { diff --git a/src/Files.App/Actions/Content/ImageEdition/RotateRightAction.cs b/src/Files.App/Actions/Content/ImageEdition/RotateRightAction.cs index 62a8cb53a639..d34990b39855 100644 --- a/src/Files.App/Actions/Content/ImageEdition/RotateRightAction.cs +++ b/src/Files.App/Actions/Content/ImageEdition/RotateRightAction.cs @@ -45,7 +45,7 @@ and not ContentPageTypes.ZipFolder private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) { - if (e.PropertyName is nameof(IContentPageContext.HasSelection)) + if (e.PropertyName is nameof(IContentPageContext.SelectedItem)) { if (context.ShellPage is not null && context.ShellPage.SlimContentPage is not null) { From 9429ed09e43d852d4fcbef698c8286a7262a294d Mon Sep 17 00:00:00 2001 From: Marco Franzen Date: Thu, 23 Mar 2023 01:15:53 +0100 Subject: [PATCH 2/8] cleanup Background Actions --- .../Background/SetAsLockscreenBackgroundAction.cs | 14 ++++++-------- .../Background/SetAsSlideshowBackgroundAction.cs | 13 +++++-------- .../Background/SetAsWallpaperBackgroundAction.cs | 14 ++++++-------- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/Files.App/Actions/Content/Background/SetAsLockscreenBackgroundAction.cs b/src/Files.App/Actions/Content/Background/SetAsLockscreenBackgroundAction.cs index c4f5c389879e..6791fbe6d739 100644 --- a/src/Files.App/Actions/Content/Background/SetAsLockscreenBackgroundAction.cs +++ b/src/Files.App/Actions/Content/Background/SetAsLockscreenBackgroundAction.cs @@ -18,12 +18,13 @@ internal class SetAsLockscreenBackgroundAction : ObservableObject, IAction public RichGlyph Glyph { get; } = new("\uEE3F"); - private bool isExecutable; - public bool IsExecutable => isExecutable; + public bool IsExecutable => context.ShellPage is not null && + context.SelectedItem is not null && + context.PageType is not ContentPageTypes.RecycleBin and not ContentPageTypes.ZipFolder && + (context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false); public SetAsLockscreenBackgroundAction() { - isExecutable = GetIsExecutable(); context.PropertyChanged += Context_PropertyChanged; } @@ -31,20 +32,17 @@ public Task ExecuteAsync() { if (context.SelectedItem is not null) WallpaperHelpers.SetAsBackground(WallpaperType.LockScreen, context.SelectedItem.ItemPath); + return Task.CompletedTask; } - private bool GetIsExecutable() => context.ShellPage is not null && context.SelectedItem is not null - && context.PageType is not ContentPageTypes.RecycleBin and not ContentPageTypes.ZipFolder - && (context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false); - private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) { switch (e.PropertyName) { case nameof(IContentPageContext.PageType): case nameof(IContentPageContext.SelectedItem): - SetProperty(ref isExecutable, GetIsExecutable(), nameof(IsExecutable)); + OnPropertyChanged(nameof(IsExecutable)); break; } } diff --git a/src/Files.App/Actions/Content/Background/SetAsSlideshowBackgroundAction.cs b/src/Files.App/Actions/Content/Background/SetAsSlideshowBackgroundAction.cs index c37296d6f315..5243f861aaee 100644 --- a/src/Files.App/Actions/Content/Background/SetAsSlideshowBackgroundAction.cs +++ b/src/Files.App/Actions/Content/Background/SetAsSlideshowBackgroundAction.cs @@ -18,12 +18,13 @@ internal class SetAsSlideshowBackgroundAction : ObservableObject, IAction public RichGlyph Glyph { get; } = new("\uE91B"); - private bool isExecutable; - public bool IsExecutable => isExecutable; + public bool IsExecutable => context.ShellPage is not null && + context.SelectedItems.Count > 1 && + context.PageType is not ContentPageTypes.RecycleBin and not ContentPageTypes.ZipFolder && + (context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false); public SetAsSlideshowBackgroundAction() { - isExecutable = GetIsExecutable(); context.PropertyChanged += Context_PropertyChanged; } @@ -35,17 +36,13 @@ public Task ExecuteAsync() return Task.CompletedTask; } - private bool GetIsExecutable() => context.ShellPage is not null && context.SelectedItems.Count > 1 - && context.PageType is not ContentPageTypes.RecycleBin and not ContentPageTypes.ZipFolder - && (context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false); - private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) { switch (e.PropertyName) { case nameof(IContentPageContext.PageType): case nameof(IContentPageContext.SelectedItems): - SetProperty(ref isExecutable, GetIsExecutable(), nameof(IsExecutable)); + OnPropertyChanged(nameof(IsExecutable)); break; } } diff --git a/src/Files.App/Actions/Content/Background/SetAsWallpaperBackgroundAction.cs b/src/Files.App/Actions/Content/Background/SetAsWallpaperBackgroundAction.cs index c5ede317c618..da1e1e009df9 100644 --- a/src/Files.App/Actions/Content/Background/SetAsWallpaperBackgroundAction.cs +++ b/src/Files.App/Actions/Content/Background/SetAsWallpaperBackgroundAction.cs @@ -18,12 +18,13 @@ internal class SetAsWallpaperBackgroundAction : ObservableObject, IAction public RichGlyph Glyph { get; } = new("\uE91B"); - private bool isExecutable; - public bool IsExecutable => isExecutable; + public bool IsExecutable => context.ShellPage is not null && + context.SelectedItem is not null && + context.PageType is not ContentPageTypes.RecycleBin and not ContentPageTypes.ZipFolder && + (context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false); public SetAsWallpaperBackgroundAction() { - isExecutable = GetIsExecutable(); context.PropertyChanged += Context_PropertyChanged; } @@ -31,20 +32,17 @@ public Task ExecuteAsync() { if (context.SelectedItem is not null) WallpaperHelpers.SetAsBackground(WallpaperType.Desktop, context.SelectedItem.ItemPath); + return Task.CompletedTask; } - private bool GetIsExecutable() => context.ShellPage is not null && context.SelectedItem is not null - && context.PageType is not ContentPageTypes.RecycleBin and not ContentPageTypes.ZipFolder - && (context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false); - private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) { switch (e.PropertyName) { case nameof(IContentPageContext.PageType): case nameof(IContentPageContext.SelectedItem): - SetProperty(ref isExecutable, GetIsExecutable(), nameof(IsExecutable)); + OnPropertyChanged(nameof(IsExecutable)); break; } } From bf744ca656d62f1dcbd25990684a2f212bc7edb4 Mon Sep 17 00:00:00 2001 From: Marco Franzen Date: Thu, 23 Mar 2023 01:37:42 +0100 Subject: [PATCH 3/8] ensure that the properties of the SelectedItemsPropertiesViewModel have been updated --- .../Background/SetAsLockscreenBackgroundAction.cs | 11 +++++++++++ .../Background/SetAsSlideshowBackgroundAction.cs | 10 ++++++++++ .../Background/SetAsWallpaperBackgroundAction.cs | 11 +++++++++++ 3 files changed, 32 insertions(+) diff --git a/src/Files.App/Actions/Content/Background/SetAsLockscreenBackgroundAction.cs b/src/Files.App/Actions/Content/Background/SetAsLockscreenBackgroundAction.cs index 6791fbe6d739..a47a99463b98 100644 --- a/src/Files.App/Actions/Content/Background/SetAsLockscreenBackgroundAction.cs +++ b/src/Files.App/Actions/Content/Background/SetAsLockscreenBackgroundAction.cs @@ -6,6 +6,7 @@ using Files.App.Helpers; using Files.Shared.Enums; using System.ComponentModel; +using System.Linq; using System.Threading.Tasks; namespace Files.App.Actions.Content.Background @@ -41,7 +42,17 @@ private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) switch (e.PropertyName) { case nameof(IContentPageContext.PageType): + OnPropertyChanged(nameof(IsExecutable)); + break; case nameof(IContentPageContext.SelectedItem): + if (context.ShellPage is not null && context.ShellPage.SlimContentPage is not null) + { + var viewModel = context.ShellPage.SlimContentPage.SelectedItemsPropertiesViewModel; + var extensions = context.SelectedItems.Select(selectedItem => selectedItem.FileExtension).Distinct().ToList(); + + viewModel.CheckAllFileExtensions(extensions); + } + OnPropertyChanged(nameof(IsExecutable)); break; } diff --git a/src/Files.App/Actions/Content/Background/SetAsSlideshowBackgroundAction.cs b/src/Files.App/Actions/Content/Background/SetAsSlideshowBackgroundAction.cs index 5243f861aaee..da686b55f319 100644 --- a/src/Files.App/Actions/Content/Background/SetAsSlideshowBackgroundAction.cs +++ b/src/Files.App/Actions/Content/Background/SetAsSlideshowBackgroundAction.cs @@ -41,7 +41,17 @@ private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) switch (e.PropertyName) { case nameof(IContentPageContext.PageType): + OnPropertyChanged(nameof(IsExecutable)); + break; case nameof(IContentPageContext.SelectedItems): + if (context.ShellPage is not null && context.ShellPage.SlimContentPage is not null) + { + var viewModel = context.ShellPage.SlimContentPage.SelectedItemsPropertiesViewModel; + var extensions = context.SelectedItems.Select(selectedItem => selectedItem.FileExtension).Distinct().ToList(); + + viewModel.CheckAllFileExtensions(extensions); + } + OnPropertyChanged(nameof(IsExecutable)); break; } diff --git a/src/Files.App/Actions/Content/Background/SetAsWallpaperBackgroundAction.cs b/src/Files.App/Actions/Content/Background/SetAsWallpaperBackgroundAction.cs index da1e1e009df9..305dd55e3fab 100644 --- a/src/Files.App/Actions/Content/Background/SetAsWallpaperBackgroundAction.cs +++ b/src/Files.App/Actions/Content/Background/SetAsWallpaperBackgroundAction.cs @@ -6,6 +6,7 @@ using Files.App.Helpers; using Files.Shared.Enums; using System.ComponentModel; +using System.Linq; using System.Threading.Tasks; namespace Files.App.Actions.Content.Background @@ -41,7 +42,17 @@ private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) switch (e.PropertyName) { case nameof(IContentPageContext.PageType): + OnPropertyChanged(nameof(IsExecutable)); + break; case nameof(IContentPageContext.SelectedItem): + if (context.ShellPage is not null && context.ShellPage.SlimContentPage is not null) + { + var viewModel = context.ShellPage.SlimContentPage.SelectedItemsPropertiesViewModel; + var extensions = context.SelectedItems.Select(selectedItem => selectedItem.FileExtension).Distinct().ToList(); + + viewModel.CheckAllFileExtensions(extensions); + } + OnPropertyChanged(nameof(IsExecutable)); break; } From dfe629ddcf1e5da18e8b7b395dd6f1b0f54c57ba Mon Sep 17 00:00:00 2001 From: Marco Franzen Date: Fri, 24 Mar 2023 00:15:24 +0100 Subject: [PATCH 4/8] create BaseSetAsAction --- .../Content/Background/BaseSetAsAction.cs | 54 +++++++++++++++++++ .../SetAsLockscreenBackgroundAction.cs | 49 ++++------------- .../SetAsSlideshowBackgroundAction.cs | 48 ++++------------- .../SetAsWallpaperBackgroundAction.cs | 49 ++++------------- 4 files changed, 81 insertions(+), 119 deletions(-) create mode 100644 src/Files.App/Actions/Content/Background/BaseSetAsAction.cs diff --git a/src/Files.App/Actions/Content/Background/BaseSetAsAction.cs b/src/Files.App/Actions/Content/Background/BaseSetAsAction.cs new file mode 100644 index 000000000000..7eebe5545330 --- /dev/null +++ b/src/Files.App/Actions/Content/Background/BaseSetAsAction.cs @@ -0,0 +1,54 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.DependencyInjection; +using Files.App.Commands; +using Files.App.Contexts; +using System.ComponentModel; +using System.Linq; +using System.Threading.Tasks; + +namespace Files.App.Actions +{ + internal abstract class BaseSetAsAction : ObservableObject, IAction + { + protected readonly IContentPageContext context = Ioc.Default.GetRequiredService(); + + public abstract string Label { get; } + + public abstract string Description { get; } + + public abstract RichGlyph Glyph { get; } + + public virtual bool IsExecutable => context.ShellPage is not null && + context.PageType is not ContentPageTypes.RecycleBin and not ContentPageTypes.ZipFolder && + (context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false); + + public BaseSetAsAction() + { + context.PropertyChanged += Context_PropertyChanged; + } + + private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) + { + switch (e.PropertyName) + { + case nameof(IContentPageContext.PageType): + OnPropertyChanged(nameof(IsExecutable)); + break; + case nameof(IContentPageContext.SelectedItem): + case nameof(IContentPageContext.SelectedItems): + if (context.ShellPage is not null && context.ShellPage.SlimContentPage is not null) + { + var viewModel = context.ShellPage.SlimContentPage.SelectedItemsPropertiesViewModel; + var extensions = context.SelectedItems.Select(selectedItem => selectedItem.FileExtension).Distinct().ToList(); + + viewModel.CheckAllFileExtensions(extensions); + } + + OnPropertyChanged(nameof(IsExecutable)); + break; + } + } + + public abstract Task ExecuteAsync(); + } +} diff --git a/src/Files.App/Actions/Content/Background/SetAsLockscreenBackgroundAction.cs b/src/Files.App/Actions/Content/Background/SetAsLockscreenBackgroundAction.cs index 2a22561ad6b6..0dcb807c6037 100644 --- a/src/Files.App/Actions/Content/Background/SetAsLockscreenBackgroundAction.cs +++ b/src/Files.App/Actions/Content/Background/SetAsLockscreenBackgroundAction.cs @@ -1,63 +1,32 @@ -using CommunityToolkit.Mvvm.ComponentModel; -using CommunityToolkit.Mvvm.DependencyInjection; -using Files.App.Commands; -using Files.App.Contexts; +using Files.App.Commands; using Files.App.Extensions; using Files.App.Helpers; using Files.Shared.Enums; -using System.ComponentModel; -using System.Linq; using System.Threading.Tasks; namespace Files.App.Actions { - internal class SetAsLockscreenBackgroundAction : ObservableObject, IAction + internal class SetAsLockscreenBackgroundAction : BaseSetAsAction { - private readonly IContentPageContext context = Ioc.Default.GetRequiredService(); + public override string Label { get; } = "SetAsLockscreen".GetLocalizedResource(); - public string Label { get; } = "SetAsLockscreen".GetLocalizedResource(); + public override string Description => "TODO: Need to be described."; - public string Description => "TODO: Need to be described."; + public override RichGlyph Glyph { get; } = new("\uEE3F"); - public RichGlyph Glyph { get; } = new("\uEE3F"); + public override bool IsExecutable => base.IsExecutable && + context.SelectedItem is not null; - public bool IsExecutable => context.ShellPage is not null && - context.SelectedItem is not null && - context.PageType is not ContentPageTypes.RecycleBin and not ContentPageTypes.ZipFolder && - (context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false); - - public SetAsLockscreenBackgroundAction() + public SetAsLockscreenBackgroundAction() : base() { - context.PropertyChanged += Context_PropertyChanged; } - public Task ExecuteAsync() + public override Task ExecuteAsync() { if (context.SelectedItem is not null) WallpaperHelpers.SetAsBackground(WallpaperType.LockScreen, context.SelectedItem.ItemPath); return Task.CompletedTask; } - - private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) - { - switch (e.PropertyName) - { - case nameof(IContentPageContext.PageType): - OnPropertyChanged(nameof(IsExecutable)); - break; - case nameof(IContentPageContext.SelectedItem): - if (context.ShellPage is not null && context.ShellPage.SlimContentPage is not null) - { - var viewModel = context.ShellPage.SlimContentPage.SelectedItemsPropertiesViewModel; - var extensions = context.SelectedItems.Select(selectedItem => selectedItem.FileExtension).Distinct().ToList(); - - viewModel.CheckAllFileExtensions(extensions); - } - - OnPropertyChanged(nameof(IsExecutable)); - break; - } - } } } diff --git a/src/Files.App/Actions/Content/Background/SetAsSlideshowBackgroundAction.cs b/src/Files.App/Actions/Content/Background/SetAsSlideshowBackgroundAction.cs index 34049996cf4f..2cd70345f2fc 100644 --- a/src/Files.App/Actions/Content/Background/SetAsSlideshowBackgroundAction.cs +++ b/src/Files.App/Actions/Content/Background/SetAsSlideshowBackgroundAction.cs @@ -1,62 +1,32 @@ -using CommunityToolkit.Mvvm.ComponentModel; -using CommunityToolkit.Mvvm.DependencyInjection; -using Files.App.Commands; -using Files.App.Contexts; +using Files.App.Commands; using Files.App.Extensions; using Files.App.Helpers; -using System.ComponentModel; using System.Linq; using System.Threading.Tasks; namespace Files.App.Actions { - internal class SetAsSlideshowBackgroundAction : ObservableObject, IAction + internal class SetAsSlideshowBackgroundAction : BaseSetAsAction { - private readonly IContentPageContext context = Ioc.Default.GetRequiredService(); + public override string Label { get; } = "SetAsSlideshow".GetLocalizedResource(); - public string Label { get; } = "SetAsSlideshow".GetLocalizedResource(); + public override string Description => "TODO: Need to be described."; - public string Description => "TODO: Need to be described."; + public override RichGlyph Glyph { get; } = new("\uE91B"); - public RichGlyph Glyph { get; } = new("\uE91B"); + public override bool IsExecutable => base.IsExecutable && + context.SelectedItems.Count > 1; - public bool IsExecutable => context.ShellPage is not null && - context.SelectedItems.Count > 1 && - context.PageType is not ContentPageTypes.RecycleBin and not ContentPageTypes.ZipFolder && - (context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false); - - public SetAsSlideshowBackgroundAction() + public SetAsSlideshowBackgroundAction() : base() { - context.PropertyChanged += Context_PropertyChanged; } - public Task ExecuteAsync() + public override Task ExecuteAsync() { var paths = context.SelectedItems.Select(item => item.ItemPath).ToArray(); WallpaperHelpers.SetSlideshow(paths); return Task.CompletedTask; } - - private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) - { - switch (e.PropertyName) - { - case nameof(IContentPageContext.PageType): - OnPropertyChanged(nameof(IsExecutable)); - break; - case nameof(IContentPageContext.SelectedItems): - if (context.ShellPage is not null && context.ShellPage.SlimContentPage is not null) - { - var viewModel = context.ShellPage.SlimContentPage.SelectedItemsPropertiesViewModel; - var extensions = context.SelectedItems.Select(selectedItem => selectedItem.FileExtension).Distinct().ToList(); - - viewModel.CheckAllFileExtensions(extensions); - } - - OnPropertyChanged(nameof(IsExecutable)); - break; - } - } } } diff --git a/src/Files.App/Actions/Content/Background/SetAsWallpaperBackgroundAction.cs b/src/Files.App/Actions/Content/Background/SetAsWallpaperBackgroundAction.cs index 78723cc2271c..5ee9ef6787dd 100644 --- a/src/Files.App/Actions/Content/Background/SetAsWallpaperBackgroundAction.cs +++ b/src/Files.App/Actions/Content/Background/SetAsWallpaperBackgroundAction.cs @@ -1,63 +1,32 @@ -using CommunityToolkit.Mvvm.ComponentModel; -using CommunityToolkit.Mvvm.DependencyInjection; -using Files.App.Commands; -using Files.App.Contexts; +using Files.App.Commands; using Files.App.Extensions; using Files.App.Helpers; using Files.Shared.Enums; -using System.ComponentModel; -using System.Linq; using System.Threading.Tasks; namespace Files.App.Actions { - internal class SetAsWallpaperBackgroundAction : ObservableObject, IAction + internal class SetAsWallpaperBackgroundAction : BaseSetAsAction { - private readonly IContentPageContext context = Ioc.Default.GetRequiredService(); + public override string Label { get; } = "SetAsBackground".GetLocalizedResource(); - public string Label { get; } = "SetAsBackground".GetLocalizedResource(); + public override string Description => "TODO: Need to be described."; - public string Description => "TODO: Need to be described."; + public override RichGlyph Glyph { get; } = new("\uE91B"); - public RichGlyph Glyph { get; } = new("\uE91B"); + public override bool IsExecutable => base.IsExecutable && + context.SelectedItem is not null; - public bool IsExecutable => context.ShellPage is not null && - context.SelectedItem is not null && - context.PageType is not ContentPageTypes.RecycleBin and not ContentPageTypes.ZipFolder && - (context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false); - - public SetAsWallpaperBackgroundAction() + public SetAsWallpaperBackgroundAction() : base() { - context.PropertyChanged += Context_PropertyChanged; } - public Task ExecuteAsync() + public override Task ExecuteAsync() { if (context.SelectedItem is not null) WallpaperHelpers.SetAsBackground(WallpaperType.Desktop, context.SelectedItem.ItemPath); return Task.CompletedTask; } - - private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) - { - switch (e.PropertyName) - { - case nameof(IContentPageContext.PageType): - OnPropertyChanged(nameof(IsExecutable)); - break; - case nameof(IContentPageContext.SelectedItem): - if (context.ShellPage is not null && context.ShellPage.SlimContentPage is not null) - { - var viewModel = context.ShellPage.SlimContentPage.SelectedItemsPropertiesViewModel; - var extensions = context.SelectedItems.Select(selectedItem => selectedItem.FileExtension).Distinct().ToList(); - - viewModel.CheckAllFileExtensions(extensions); - } - - OnPropertyChanged(nameof(IsExecutable)); - break; - } - } } } From a222f00e83aba04dfe48b957f9d74fcfbc312441 Mon Sep 17 00:00:00 2001 From: Marco Franzen Date: Fri, 24 Mar 2023 00:17:41 +0100 Subject: [PATCH 5/8] create BaseRotateAction --- .../Content/ImageEdition/BaseRotateAction.cs | 65 +++++++++++++++++++ .../Content/ImageEdition/RotateLeftAction.cs | 57 ++-------------- .../Content/ImageEdition/RotateRightAction.cs | 57 ++-------------- 3 files changed, 79 insertions(+), 100 deletions(-) create mode 100644 src/Files.App/Actions/Content/ImageEdition/BaseRotateAction.cs diff --git a/src/Files.App/Actions/Content/ImageEdition/BaseRotateAction.cs b/src/Files.App/Actions/Content/ImageEdition/BaseRotateAction.cs new file mode 100644 index 000000000000..1d499bc0c18c --- /dev/null +++ b/src/Files.App/Actions/Content/ImageEdition/BaseRotateAction.cs @@ -0,0 +1,65 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.DependencyInjection; +using Files.App.Commands; +using Files.App.Contexts; +using Files.App.Helpers; +using System.ComponentModel; +using System.Linq; +using System.Threading.Tasks; +using Windows.Graphics.Imaging; + +namespace Files.App.Actions +{ + internal abstract class BaseRotateAction : ObservableObject, IAction + { + private readonly IContentPageContext context = Ioc.Default.GetRequiredService(); + + public abstract string Label { get; } + + public abstract string Description { get; } + + public abstract RichGlyph Glyph { get; } + + protected abstract BitmapRotation Rotation { get; } + + public bool IsExecutable => IsContextPageTypeAdaptedToCommand() && + (context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false); + + public BaseRotateAction() + { + context.PropertyChanged += Context_PropertyChanged; + } + + public async Task ExecuteAsync() + { + foreach (var image in context.SelectedItems) + await BitmapHelper.Rotate(PathNormalization.NormalizePath(image.ItemPath), Rotation); + + context.ShellPage?.SlimContentPage?.ItemManipulationModel?.RefreshItemsThumbnail(); + App.PreviewPaneViewModel.UpdateSelectedItemPreview(); + } + + private bool IsContextPageTypeAdaptedToCommand() + { + return context.PageType is not ContentPageTypes.RecycleBin + and not ContentPageTypes.ZipFolder + and not ContentPageTypes.None; + } + + private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) + { + if (e.PropertyName is nameof(IContentPageContext.SelectedItem)) + { + if (context.ShellPage is not null && context.ShellPage.SlimContentPage is not null) + { + var viewModel = context.ShellPage.SlimContentPage.SelectedItemsPropertiesViewModel; + var extensions = context.SelectedItems.Select(selectedItem => selectedItem.FileExtension).Distinct().ToList(); + + viewModel.CheckAllFileExtensions(extensions); + } + + OnPropertyChanged(nameof(IsExecutable)); + } + } + } +} diff --git a/src/Files.App/Actions/Content/ImageEdition/RotateLeftAction.cs b/src/Files.App/Actions/Content/ImageEdition/RotateLeftAction.cs index 8f3dfed9320f..e77f7df09f3f 100644 --- a/src/Files.App/Actions/Content/ImageEdition/RotateLeftAction.cs +++ b/src/Files.App/Actions/Content/ImageEdition/RotateLeftAction.cs @@ -1,64 +1,21 @@ -using CommunityToolkit.Mvvm.ComponentModel; -using CommunityToolkit.Mvvm.DependencyInjection; -using Files.App.Commands; -using Files.App.Contexts; +using Files.App.Commands; using Files.App.Extensions; -using Files.App.Helpers; -using System.ComponentModel; -using System.Linq; -using System.Threading.Tasks; using Windows.Graphics.Imaging; namespace Files.App.Actions { - internal class RotateLeftAction : ObservableObject, IAction + internal class RotateLeftAction : BaseRotateAction { - private readonly IContentPageContext context = Ioc.Default.GetRequiredService(); + public override string Label { get; } = "RotateLeft".GetLocalizedResource(); - public string Label { get; } = "RotateLeft".GetLocalizedResource(); + public override string Description => "TODO: Need to be described."; - public string Description => "TODO: Need to be described."; + public override RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconRotateLeft"); - public RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconRotateLeft"); + protected override BitmapRotation Rotation => BitmapRotation.Clockwise270Degrees; - public bool IsExecutable => IsContextPageTypeAdaptedToCommand() - && (context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false); - - public RotateLeftAction() - { - context.PropertyChanged += Context_PropertyChanged; - } - - public async Task ExecuteAsync() + public RotateLeftAction() : base() { - foreach (var image in context.SelectedItems) - await BitmapHelper.Rotate(PathNormalization.NormalizePath(image.ItemPath), BitmapRotation.Clockwise270Degrees); - - context.ShellPage?.SlimContentPage?.ItemManipulationModel?.RefreshItemsThumbnail(); - App.PreviewPaneViewModel.UpdateSelectedItemPreview(); - } - - private bool IsContextPageTypeAdaptedToCommand() - { - return context.PageType is not ContentPageTypes.RecycleBin - and not ContentPageTypes.ZipFolder - and not ContentPageTypes.None; - } - - private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) - { - if (e.PropertyName is nameof(IContentPageContext.SelectedItem)) - { - if (context.ShellPage is not null && context.ShellPage.SlimContentPage is not null) - { - var viewModel = context.ShellPage.SlimContentPage.SelectedItemsPropertiesViewModel; - var extensions = context.SelectedItems.Select(selectedItem => selectedItem.FileExtension).Distinct().ToList(); - - viewModel.CheckAllFileExtensions(extensions); - } - - OnPropertyChanged(nameof(IsExecutable)); - } } } } diff --git a/src/Files.App/Actions/Content/ImageEdition/RotateRightAction.cs b/src/Files.App/Actions/Content/ImageEdition/RotateRightAction.cs index c59355809e8d..e72d5cef0206 100644 --- a/src/Files.App/Actions/Content/ImageEdition/RotateRightAction.cs +++ b/src/Files.App/Actions/Content/ImageEdition/RotateRightAction.cs @@ -1,64 +1,21 @@ -using CommunityToolkit.Mvvm.ComponentModel; -using CommunityToolkit.Mvvm.DependencyInjection; -using Files.App.Commands; -using Files.App.Contexts; +using Files.App.Commands; using Files.App.Extensions; -using Files.App.Helpers; -using System.ComponentModel; -using System.Linq; -using System.Threading.Tasks; using Windows.Graphics.Imaging; namespace Files.App.Actions { - internal class RotateRightAction : ObservableObject, IAction + internal class RotateRightAction : BaseRotateAction { - private readonly IContentPageContext context = Ioc.Default.GetRequiredService(); + public override string Label { get; } = "RotateRight".GetLocalizedResource(); - public string Label { get; } = "RotateRight".GetLocalizedResource(); + public override string Description => "TODO: Need to be described."; - public string Description => "TODO: Need to be described."; + public override RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconRotateRight"); - public RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconRotateRight"); + protected override BitmapRotation Rotation => BitmapRotation.Clockwise90Degrees; - public bool IsExecutable => IsContextPageTypeAdaptedToCommand() - && (context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false); - - public RotateRightAction() - { - context.PropertyChanged += Context_PropertyChanged; - } - - public async Task ExecuteAsync() + public RotateRightAction() : base() { - foreach (var image in context.SelectedItems) - await BitmapHelper.Rotate(PathNormalization.NormalizePath(image.ItemPath), BitmapRotation.Clockwise90Degrees); - - context.ShellPage?.SlimContentPage?.ItemManipulationModel?.RefreshItemsThumbnail(); - App.PreviewPaneViewModel.UpdateSelectedItemPreview(); - } - - private bool IsContextPageTypeAdaptedToCommand() - { - return context.PageType is not ContentPageTypes.RecycleBin - and not ContentPageTypes.ZipFolder - and not ContentPageTypes.None; - } - - private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) - { - if (e.PropertyName is nameof(IContentPageContext.SelectedItem)) - { - if (context.ShellPage is not null && context.ShellPage.SlimContentPage is not null) - { - var viewModel = context.ShellPage.SlimContentPage.SelectedItemsPropertiesViewModel; - var extensions = context.SelectedItems.Select(selectedItem => selectedItem.FileExtension).Distinct().ToList(); - - viewModel.CheckAllFileExtensions(extensions); - } - - OnPropertyChanged(nameof(IsExecutable)); - } } } } From cd5d2b05d16549afcadff807e9ae79be59c37639 Mon Sep 17 00:00:00 2001 From: Marco Franzen Date: Tue, 28 Mar 2023 09:54:55 +0200 Subject: [PATCH 6/8] removed constructor --- .../Content/Background/SetAsLockscreenBackgroundAction.cs | 4 ---- .../Content/Background/SetAsSlideshowBackgroundAction.cs | 4 ---- .../Content/Background/SetAsWallpaperBackgroundAction.cs | 4 ---- .../Actions/Content/ImageEdition/RotateLeftAction.cs | 4 ---- .../Actions/Content/ImageEdition/RotateRightAction.cs | 4 ---- 5 files changed, 20 deletions(-) diff --git a/src/Files.App/Actions/Content/Background/SetAsLockscreenBackgroundAction.cs b/src/Files.App/Actions/Content/Background/SetAsLockscreenBackgroundAction.cs index 0dcb807c6037..0b2508c37042 100644 --- a/src/Files.App/Actions/Content/Background/SetAsLockscreenBackgroundAction.cs +++ b/src/Files.App/Actions/Content/Background/SetAsLockscreenBackgroundAction.cs @@ -17,10 +17,6 @@ internal class SetAsLockscreenBackgroundAction : BaseSetAsAction public override bool IsExecutable => base.IsExecutable && context.SelectedItem is not null; - public SetAsLockscreenBackgroundAction() : base() - { - } - public override Task ExecuteAsync() { if (context.SelectedItem is not null) diff --git a/src/Files.App/Actions/Content/Background/SetAsSlideshowBackgroundAction.cs b/src/Files.App/Actions/Content/Background/SetAsSlideshowBackgroundAction.cs index 2cd70345f2fc..00cef0fb9727 100644 --- a/src/Files.App/Actions/Content/Background/SetAsSlideshowBackgroundAction.cs +++ b/src/Files.App/Actions/Content/Background/SetAsSlideshowBackgroundAction.cs @@ -17,10 +17,6 @@ internal class SetAsSlideshowBackgroundAction : BaseSetAsAction public override bool IsExecutable => base.IsExecutable && context.SelectedItems.Count > 1; - public SetAsSlideshowBackgroundAction() : base() - { - } - public override Task ExecuteAsync() { var paths = context.SelectedItems.Select(item => item.ItemPath).ToArray(); diff --git a/src/Files.App/Actions/Content/Background/SetAsWallpaperBackgroundAction.cs b/src/Files.App/Actions/Content/Background/SetAsWallpaperBackgroundAction.cs index 5ee9ef6787dd..9d1da6a814d0 100644 --- a/src/Files.App/Actions/Content/Background/SetAsWallpaperBackgroundAction.cs +++ b/src/Files.App/Actions/Content/Background/SetAsWallpaperBackgroundAction.cs @@ -17,10 +17,6 @@ internal class SetAsWallpaperBackgroundAction : BaseSetAsAction public override bool IsExecutable => base.IsExecutable && context.SelectedItem is not null; - public SetAsWallpaperBackgroundAction() : base() - { - } - public override Task ExecuteAsync() { if (context.SelectedItem is not null) diff --git a/src/Files.App/Actions/Content/ImageEdition/RotateLeftAction.cs b/src/Files.App/Actions/Content/ImageEdition/RotateLeftAction.cs index e77f7df09f3f..a1594277b831 100644 --- a/src/Files.App/Actions/Content/ImageEdition/RotateLeftAction.cs +++ b/src/Files.App/Actions/Content/ImageEdition/RotateLeftAction.cs @@ -13,9 +13,5 @@ internal class RotateLeftAction : BaseRotateAction public override RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconRotateLeft"); protected override BitmapRotation Rotation => BitmapRotation.Clockwise270Degrees; - - public RotateLeftAction() : base() - { - } } } diff --git a/src/Files.App/Actions/Content/ImageEdition/RotateRightAction.cs b/src/Files.App/Actions/Content/ImageEdition/RotateRightAction.cs index e72d5cef0206..4c4861807f22 100644 --- a/src/Files.App/Actions/Content/ImageEdition/RotateRightAction.cs +++ b/src/Files.App/Actions/Content/ImageEdition/RotateRightAction.cs @@ -13,9 +13,5 @@ internal class RotateRightAction : BaseRotateAction public override RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconRotateRight"); protected override BitmapRotation Rotation => BitmapRotation.Clockwise90Degrees; - - public RotateRightAction() : base() - { - } } } From fdc8857ae5e9293bc9ddce221cd229ede3f6ff95 Mon Sep 17 00:00:00 2001 From: Marco Franzen Date: Tue, 28 Mar 2023 17:55:20 +0200 Subject: [PATCH 7/8] renamed directory: ImageEdition -> ImageManipulation --- .../{ImageEdition => ImageManipulation}/BaseRotateAction.cs | 0 .../{ImageEdition => ImageManipulation}/RotateLeftAction.cs | 0 .../{ImageEdition => ImageManipulation}/RotateRightAction.cs | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename src/Files.App/Actions/Content/{ImageEdition => ImageManipulation}/BaseRotateAction.cs (100%) rename src/Files.App/Actions/Content/{ImageEdition => ImageManipulation}/RotateLeftAction.cs (100%) rename src/Files.App/Actions/Content/{ImageEdition => ImageManipulation}/RotateRightAction.cs (100%) diff --git a/src/Files.App/Actions/Content/ImageEdition/BaseRotateAction.cs b/src/Files.App/Actions/Content/ImageManipulation/BaseRotateAction.cs similarity index 100% rename from src/Files.App/Actions/Content/ImageEdition/BaseRotateAction.cs rename to src/Files.App/Actions/Content/ImageManipulation/BaseRotateAction.cs diff --git a/src/Files.App/Actions/Content/ImageEdition/RotateLeftAction.cs b/src/Files.App/Actions/Content/ImageManipulation/RotateLeftAction.cs similarity index 100% rename from src/Files.App/Actions/Content/ImageEdition/RotateLeftAction.cs rename to src/Files.App/Actions/Content/ImageManipulation/RotateLeftAction.cs diff --git a/src/Files.App/Actions/Content/ImageEdition/RotateRightAction.cs b/src/Files.App/Actions/Content/ImageManipulation/RotateRightAction.cs similarity index 100% rename from src/Files.App/Actions/Content/ImageEdition/RotateRightAction.cs rename to src/Files.App/Actions/Content/ImageManipulation/RotateRightAction.cs From 91920ac43e0d8e87b7c57d7431f615354bf3186f Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Tue, 28 Mar 2023 19:50:18 -0400 Subject: [PATCH 8/8] Update CommandCodes.cs --- src/Files.App/Commands/CommandCodes.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App/Commands/CommandCodes.cs b/src/Files.App/Commands/CommandCodes.cs index 5d48ac33e5df..da15c25ef8dc 100644 --- a/src/Files.App/Commands/CommandCodes.cs +++ b/src/Files.App/Commands/CommandCodes.cs @@ -76,7 +76,7 @@ public enum CommandCodes DecompressArchiveHere, DecompressArchiveToChildFolder, - // Image Edition + // Image Manipulation RotateLeft, RotateRight,