Skip to content

Commit 7b76c45

Browse files
Bug: Fixed issue where Rotate Image & Set as Wallpaper were sometimes not displayed (#11813)
1 parent 344a890 commit 7b76c45

File tree

9 files changed

+126
-181
lines changed

9 files changed

+126
-181
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using CommunityToolkit.Mvvm.ComponentModel;
2+
using CommunityToolkit.Mvvm.DependencyInjection;
3+
using Files.App.Commands;
4+
using Files.App.Contexts;
5+
using System.ComponentModel;
6+
using System.Linq;
7+
using System.Threading.Tasks;
8+
9+
namespace Files.App.Actions
10+
{
11+
internal abstract class BaseSetAsAction : ObservableObject, IAction
12+
{
13+
protected readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();
14+
15+
public abstract string Label { get; }
16+
17+
public abstract string Description { get; }
18+
19+
public abstract RichGlyph Glyph { get; }
20+
21+
public virtual bool IsExecutable => context.ShellPage is not null &&
22+
context.PageType is not ContentPageTypes.RecycleBin and not ContentPageTypes.ZipFolder &&
23+
(context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false);
24+
25+
public BaseSetAsAction()
26+
{
27+
context.PropertyChanged += Context_PropertyChanged;
28+
}
29+
30+
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
31+
{
32+
switch (e.PropertyName)
33+
{
34+
case nameof(IContentPageContext.PageType):
35+
OnPropertyChanged(nameof(IsExecutable));
36+
break;
37+
case nameof(IContentPageContext.SelectedItem):
38+
case nameof(IContentPageContext.SelectedItems):
39+
if (context.ShellPage is not null && context.ShellPage.SlimContentPage is not null)
40+
{
41+
var viewModel = context.ShellPage.SlimContentPage.SelectedItemsPropertiesViewModel;
42+
var extensions = context.SelectedItems.Select(selectedItem => selectedItem.FileExtension).Distinct().ToList();
43+
44+
viewModel.CheckAllFileExtensions(extensions);
45+
}
46+
47+
OnPropertyChanged(nameof(IsExecutable));
48+
break;
49+
}
50+
}
51+
52+
public abstract Task ExecuteAsync();
53+
}
54+
}
Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,28 @@
1-
using CommunityToolkit.Mvvm.ComponentModel;
2-
using CommunityToolkit.Mvvm.DependencyInjection;
3-
using Files.App.Commands;
4-
using Files.App.Contexts;
1+
using Files.App.Commands;
52
using Files.App.Extensions;
63
using Files.App.Helpers;
74
using Files.Shared.Enums;
8-
using System.ComponentModel;
95
using System.Threading.Tasks;
106

117
namespace Files.App.Actions
128
{
13-
internal class SetAsLockscreenBackgroundAction : ObservableObject, IAction
9+
internal class SetAsLockscreenBackgroundAction : BaseSetAsAction
1410
{
15-
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();
11+
public override string Label { get; } = "SetAsLockscreen".GetLocalizedResource();
1612

17-
public string Label { get; } = "SetAsLockscreen".GetLocalizedResource();
13+
public override string Description => "TODO: Need to be described.";
1814

19-
public string Description => "TODO: Need to be described.";
15+
public override RichGlyph Glyph { get; } = new("\uEE3F");
2016

21-
public RichGlyph Glyph { get; } = new("\uEE3F");
17+
public override bool IsExecutable => base.IsExecutable &&
18+
context.SelectedItem is not null;
2219

23-
private bool isExecutable;
24-
public bool IsExecutable => isExecutable;
25-
26-
public SetAsLockscreenBackgroundAction()
27-
{
28-
isExecutable = GetIsExecutable();
29-
context.PropertyChanged += Context_PropertyChanged;
30-
}
31-
32-
public Task ExecuteAsync()
20+
public override Task ExecuteAsync()
3321
{
3422
if (context.SelectedItem is not null)
3523
WallpaperHelpers.SetAsBackground(WallpaperType.LockScreen, context.SelectedItem.ItemPath);
36-
return Task.CompletedTask;
37-
}
38-
39-
private bool GetIsExecutable() => context.ShellPage is not null && context.SelectedItem is not null
40-
&& context.PageType is not ContentPageTypes.RecycleBin and not ContentPageTypes.ZipFolder
41-
&& (context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false);
4224

43-
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
44-
{
45-
switch (e.PropertyName)
46-
{
47-
case nameof(IContentPageContext.PageType):
48-
case nameof(IContentPageContext.SelectedItem):
49-
SetProperty(ref isExecutable, GetIsExecutable(), nameof(IsExecutable));
50-
break;
51-
}
25+
return Task.CompletedTask;
5226
}
5327
}
5428
}
Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,28 @@
1-
using CommunityToolkit.Mvvm.ComponentModel;
2-
using CommunityToolkit.Mvvm.DependencyInjection;
3-
using Files.App.Commands;
4-
using Files.App.Contexts;
1+
using Files.App.Commands;
52
using Files.App.Extensions;
63
using Files.App.Helpers;
7-
using System.ComponentModel;
84
using System.Linq;
95
using System.Threading.Tasks;
106

117
namespace Files.App.Actions
128
{
13-
internal class SetAsSlideshowBackgroundAction : ObservableObject, IAction
9+
internal class SetAsSlideshowBackgroundAction : BaseSetAsAction
1410
{
15-
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();
11+
public override string Label { get; } = "SetAsSlideshow".GetLocalizedResource();
1612

17-
public string Label { get; } = "SetAsSlideshow".GetLocalizedResource();
13+
public override string Description => "TODO: Need to be described.";
1814

19-
public string Description => "TODO: Need to be described.";
15+
public override RichGlyph Glyph { get; } = new("\uE91B");
2016

21-
public RichGlyph Glyph { get; } = new("\uE91B");
17+
public override bool IsExecutable => base.IsExecutable &&
18+
context.SelectedItems.Count > 1;
2219

23-
private bool isExecutable;
24-
public bool IsExecutable => isExecutable;
25-
26-
public SetAsSlideshowBackgroundAction()
27-
{
28-
isExecutable = GetIsExecutable();
29-
context.PropertyChanged += Context_PropertyChanged;
30-
}
31-
32-
public Task ExecuteAsync()
20+
public override Task ExecuteAsync()
3321
{
3422
var paths = context.SelectedItems.Select(item => item.ItemPath).ToArray();
3523
WallpaperHelpers.SetSlideshow(paths);
3624

3725
return Task.CompletedTask;
3826
}
39-
40-
private bool GetIsExecutable() => context.ShellPage is not null && context.SelectedItems.Count > 1
41-
&& context.PageType is not ContentPageTypes.RecycleBin and not ContentPageTypes.ZipFolder
42-
&& (context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false);
43-
44-
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
45-
{
46-
switch (e.PropertyName)
47-
{
48-
case nameof(IContentPageContext.PageType):
49-
case nameof(IContentPageContext.SelectedItems):
50-
SetProperty(ref isExecutable, GetIsExecutable(), nameof(IsExecutable));
51-
break;
52-
}
53-
}
5427
}
5528
}
Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,28 @@
1-
using CommunityToolkit.Mvvm.ComponentModel;
2-
using CommunityToolkit.Mvvm.DependencyInjection;
3-
using Files.App.Commands;
4-
using Files.App.Contexts;
1+
using Files.App.Commands;
52
using Files.App.Extensions;
63
using Files.App.Helpers;
74
using Files.Shared.Enums;
8-
using System.ComponentModel;
95
using System.Threading.Tasks;
106

117
namespace Files.App.Actions
128
{
13-
internal class SetAsWallpaperBackgroundAction : ObservableObject, IAction
9+
internal class SetAsWallpaperBackgroundAction : BaseSetAsAction
1410
{
15-
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();
11+
public override string Label { get; } = "SetAsBackground".GetLocalizedResource();
1612

17-
public string Label { get; } = "SetAsBackground".GetLocalizedResource();
13+
public override string Description => "TODO: Need to be described.";
1814

19-
public string Description => "TODO: Need to be described.";
15+
public override RichGlyph Glyph { get; } = new("\uE91B");
2016

21-
public RichGlyph Glyph { get; } = new("\uE91B");
17+
public override bool IsExecutable => base.IsExecutable &&
18+
context.SelectedItem is not null;
2219

23-
private bool isExecutable;
24-
public bool IsExecutable => isExecutable;
25-
26-
public SetAsWallpaperBackgroundAction()
27-
{
28-
isExecutable = GetIsExecutable();
29-
context.PropertyChanged += Context_PropertyChanged;
30-
}
31-
32-
public Task ExecuteAsync()
20+
public override Task ExecuteAsync()
3321
{
3422
if (context.SelectedItem is not null)
3523
WallpaperHelpers.SetAsBackground(WallpaperType.Desktop, context.SelectedItem.ItemPath);
36-
return Task.CompletedTask;
37-
}
38-
39-
private bool GetIsExecutable() => context.ShellPage is not null && context.SelectedItem is not null
40-
&& context.PageType is not ContentPageTypes.RecycleBin and not ContentPageTypes.ZipFolder
41-
&& (context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false);
4224

43-
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
44-
{
45-
switch (e.PropertyName)
46-
{
47-
case nameof(IContentPageContext.PageType):
48-
case nameof(IContentPageContext.SelectedItem):
49-
SetProperty(ref isExecutable, GetIsExecutable(), nameof(IsExecutable));
50-
break;
51-
}
25+
return Task.CompletedTask;
5226
}
5327
}
5428
}

src/Files.App/Actions/Content/ImageEdition/RotateRightAction.cs

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/Files.App/Actions/Content/ImageEdition/RotateLeftAction.cs renamed to src/Files.App/Actions/Content/ImageManipulation/BaseRotateAction.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using CommunityToolkit.Mvvm.DependencyInjection;
33
using Files.App.Commands;
44
using Files.App.Contexts;
5-
using Files.App.Extensions;
65
using Files.App.Helpers;
76
using Files.App.ViewModels;
87
using System.ComponentModel;
@@ -12,28 +11,30 @@
1211

1312
namespace Files.App.Actions
1413
{
15-
internal class RotateLeftAction : ObservableObject, IAction
14+
internal abstract class BaseRotateAction : ObservableObject, IAction
1615
{
1716
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();
1817

19-
public string Label { get; } = "RotateLeft".GetLocalizedResource();
18+
public abstract string Label { get; }
2019

21-
public string Description => "TODO: Need to be described.";
20+
public abstract string Description { get; }
2221

23-
public RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconRotateLeft");
22+
public abstract RichGlyph Glyph { get; }
2423

25-
public bool IsExecutable => IsContextPageTypeAdaptedToCommand()
26-
&& (context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false);
24+
protected abstract BitmapRotation Rotation { get; }
2725

28-
public RotateLeftAction()
26+
public bool IsExecutable => IsContextPageTypeAdaptedToCommand() &&
27+
(context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false);
28+
29+
public BaseRotateAction()
2930
{
3031
context.PropertyChanged += Context_PropertyChanged;
3132
}
3233

3334
public async Task ExecuteAsync()
3435
{
3536
foreach (var image in context.SelectedItems)
36-
await BitmapHelper.Rotate(PathNormalization.NormalizePath(image.ItemPath), BitmapRotation.Clockwise270Degrees);
37+
await BitmapHelper.Rotate(PathNormalization.NormalizePath(image.ItemPath), Rotation);
3738

3839
context.ShellPage?.SlimContentPage?.ItemManipulationModel?.RefreshItemsThumbnail();
3940
Ioc.Default.GetRequiredService<PreviewPaneViewModel>().UpdateSelectedItemPreview();
@@ -48,7 +49,7 @@ and not ContentPageTypes.ZipFolder
4849

4950
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
5051
{
51-
if (e.PropertyName is nameof(IContentPageContext.HasSelection))
52+
if (e.PropertyName is nameof(IContentPageContext.SelectedItem))
5253
{
5354
if (context.ShellPage is not null && context.ShellPage.SlimContentPage is not null)
5455
{
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Files.App.Commands;
2+
using Files.App.Extensions;
3+
using Windows.Graphics.Imaging;
4+
5+
namespace Files.App.Actions
6+
{
7+
internal class RotateLeftAction : BaseRotateAction
8+
{
9+
public override string Label { get; } = "RotateLeft".GetLocalizedResource();
10+
11+
public override string Description => "TODO: Need to be described.";
12+
13+
public override RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconRotateLeft");
14+
15+
protected override BitmapRotation Rotation => BitmapRotation.Clockwise270Degrees;
16+
}
17+
}

0 commit comments

Comments
 (0)