Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/Files.App/Actions/Content/Background/BaseSetAsAction.cs
Original file line number Diff line number Diff line change
@@ -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<IContentPageContext>();

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();
}
}
Original file line number Diff line number Diff line change
@@ -1,54 +1,28 @@
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.Threading.Tasks;

namespace Files.App.Actions
{
internal class SetAsLockscreenBackgroundAction : ObservableObject, IAction
internal class SetAsLockscreenBackgroundAction : BaseSetAsAction
{
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();
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;

private bool isExecutable;
public bool IsExecutable => isExecutable;

public SetAsLockscreenBackgroundAction()
{
isExecutable = GetIsExecutable();
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 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));
break;
}
return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,55 +1,28 @@
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<IContentPageContext>();
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;

private bool isExecutable;
public bool IsExecutable => isExecutable;

public SetAsSlideshowBackgroundAction()
{
isExecutable = GetIsExecutable();
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 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));
break;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,54 +1,28 @@
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.Threading.Tasks;

namespace Files.App.Actions
{
internal class SetAsWallpaperBackgroundAction : ObservableObject, IAction
internal class SetAsWallpaperBackgroundAction : BaseSetAsAction
{
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();
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;

private bool isExecutable;
public bool IsExecutable => isExecutable;

public SetAsWallpaperBackgroundAction()
{
isExecutable = GetIsExecutable();
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 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));
break;
}
return Task.CompletedTask;
}
}
}
65 changes: 0 additions & 65 deletions src/Files.App/Actions/Content/ImageEdition/RotateRightAction.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Extensions;
using Files.App.Helpers;
using Files.App.ViewModels;
using System.ComponentModel;
Expand All @@ -12,28 +11,30 @@

namespace Files.App.Actions
{
internal class RotateLeftAction : ObservableObject, IAction
internal abstract class BaseRotateAction : ObservableObject, IAction
{
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();

public string Label { get; } = "RotateLeft".GetLocalizedResource();
public abstract string Label { get; }

public string Description => "TODO: Need to be described.";
public abstract string Description { get; }

public RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconRotateLeft");
public abstract RichGlyph Glyph { get; }

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

public RotateLeftAction()
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), BitmapRotation.Clockwise270Degrees);
await BitmapHelper.Rotate(PathNormalization.NormalizePath(image.ItemPath), Rotation);

context.ShellPage?.SlimContentPage?.ItemManipulationModel?.RefreshItemsThumbnail();
Ioc.Default.GetRequiredService<PreviewPaneViewModel>().UpdateSelectedItemPreview();
Expand All @@ -48,7 +49,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)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Files.App.Commands;
using Files.App.Extensions;
using Windows.Graphics.Imaging;

namespace Files.App.Actions
{
internal class RotateLeftAction : BaseRotateAction
{
public override string Label { get; } = "RotateLeft".GetLocalizedResource();

public override string Description => "TODO: Need to be described.";

public override RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconRotateLeft");

protected override BitmapRotation Rotation => BitmapRotation.Clockwise270Degrees;
}
}
Loading