Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Quality: Clean up Files.Actions phase 1 #12677

Merged
merged 14 commits into from Jul 6, 2023
10 changes: 5 additions & 5 deletions src/Files.App/Actions/BaseUIAction.cs
@@ -1,15 +1,15 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using CommunityToolkit.Mvvm.ComponentModel;
using Files.App.Helpers;
using System.ComponentModel;

namespace Files.App.Actions
{
/// <summary>
/// Represents base class for the UI Actions.
/// </summary>
internal abstract class BaseUIAction : ObservableObject
{
public virtual bool IsExecutable => UIHelpers.CanShowDialog;
public virtual bool IsExecutable
=> UIHelpers.CanShowDialog;

public BaseUIAction()
{
Expand Down
@@ -1,7 +1,6 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Contexts;
using Files.App.Dialogs;
using Files.App.Filesystem.Archive;
using Microsoft.UI.Xaml.Controls;
Expand Down
@@ -1,7 +1,6 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Contexts;
using Files.App.Filesystem.Archive;

namespace Files.App.Actions
Expand Down
@@ -1,7 +1,6 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Contexts;
using Files.App.Filesystem.Archive;

namespace Files.App.Actions
Expand Down
11 changes: 2 additions & 9 deletions src/Files.App/Actions/Content/Archives/DecompressArchive.cs
@@ -1,15 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Extensions;
using Files.App.Helpers;
using Files.Backend.Helpers;
using System.ComponentModel;
using System.IO;
using System.Threading.Tasks;

namespace Files.App.Actions
{
Expand All @@ -23,7 +15,8 @@ public string Label
public string Description
=> "DecompressArchiveDescription".GetLocalizedResource();

public HotKey HotKey { get; } = new(Keys.E, KeyModifiers.Ctrl);
public HotKey HotKey
=> new(Keys.E, KeyModifiers.Ctrl);

public override bool IsExecutable =>
(IsContextPageTypeAdaptedToCommand() &&
Expand Down
@@ -1,13 +1,6 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Contexts;
using Files.App.Extensions;
using Files.App.Helpers;
using System.ComponentModel;
using System.Threading.Tasks;

namespace Files.App.Actions
{
internal class DecompressArchiveHere : BaseUIAction, IAction
Expand All @@ -27,7 +20,7 @@ public string Description

public DecompressArchiveHere()
{
context = Ioc.Default.GetRequiredService<IContentPageContext>()
context = Ioc.Default.GetRequiredService<IContentPageContext>();

context.PropertyChanged += Context_PropertyChanged;
}
Expand Down
@@ -1,8 +1,6 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Contexts;

namespace Files.App.Actions
{
internal class DecompressArchiveToChildFolderAction : BaseUIAction, IAction
Expand Down
12 changes: 2 additions & 10 deletions src/Files.App/Actions/Content/Background/BaseSetAsAction.cs
@@ -1,14 +1,6 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

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
Expand All @@ -34,6 +26,8 @@ public BaseSetAsAction()
context.PropertyChanged += Context_PropertyChanged;
}

public abstract Task ExecuteAsync();

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
Expand All @@ -57,7 +51,5 @@ private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
}
}
}

public abstract Task ExecuteAsync();
}
}
@@ -1,12 +1,6 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Commands;
using Files.App.Extensions;
using Files.App.Helpers;
using Files.Shared.Enums;
using System.Threading.Tasks;

namespace Files.App.Actions
{
internal class SetAsLockscreenBackgroundAction : BaseSetAsAction
Expand All @@ -17,9 +11,11 @@ public override string Label
public override string Description
=> "SetAsLockscreenBackgroundDescription".GetLocalizedResource();

public override RichGlyph Glyph { get; } = new("\uEE3F");
public override RichGlyph Glyph
=> new("\uEE3F");

public override bool IsExecutable => base.IsExecutable &&
public override bool IsExecutable =>
base.IsExecutable &&
context.SelectedItem is not null;

public override Task ExecuteAsync()
Expand Down
@@ -1,12 +1,6 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Commands;
using Files.App.Extensions;
using Files.App.Helpers;
using System.Linq;
using System.Threading.Tasks;

namespace Files.App.Actions
{
internal class SetAsSlideshowBackgroundAction : BaseSetAsAction
Expand Down
@@ -1,12 +1,6 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Commands;
using Files.App.Extensions;
using Files.App.Helpers;
using Files.Shared.Enums;
using System.Threading.Tasks;

namespace Files.App.Actions
{
internal class SetAsWallpaperBackgroundAction : BaseSetAsAction
Expand All @@ -17,7 +11,8 @@ public override string Label
public override string Description
=> "SetAsWallpaperBackgroundDescription".GetLocalizedResource();

public override RichGlyph Glyph { get; } = new("\uE91B");
public override RichGlyph Glyph
=> new("\uE91B");

public override bool IsExecutable =>
base.IsExecutable &&
Expand Down
@@ -1,15 +1,6 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Helpers;
using Files.App.ViewModels;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using Windows.Graphics.Imaging;

namespace Files.App.Actions
Expand All @@ -18,6 +9,8 @@ internal abstract class BaseRotateAction : ObservableObject, IAction
{
private readonly IContentPageContext context;

private readonly PreviewPaneViewModel _previewPaneViewModel;

public abstract string Label { get; }

public abstract string Description { get; }
Expand All @@ -33,6 +26,7 @@ internal abstract class BaseRotateAction : ObservableObject, IAction
public BaseRotateAction()
{
context = Ioc.Default.GetRequiredService<IContentPageContext>();
_previewPaneViewModel = Ioc.Default.GetRequiredService<PreviewPaneViewModel>();

context.PropertyChanged += Context_PropertyChanged;
}
Expand All @@ -44,7 +38,7 @@ public async Task ExecuteAsync()

context.ShellPage?.SlimContentPage?.ItemManipulationModel?.RefreshItemsThumbnail();

Ioc.Default.GetRequiredService<PreviewPaneViewModel>().UpdateSelectedItemPreview();
await _previewPaneViewModel.UpdateSelectedItemPreview();
}

private bool IsContextPageTypeAdaptedToCommand()
Expand Down
@@ -1,8 +1,6 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Commands;
using Files.App.Extensions;
using Windows.Graphics.Imaging;

namespace Files.App.Actions
Expand All @@ -16,7 +14,7 @@ public override string Description
=> "RotateLeftDescription".GetLocalizedResource();

public override RichGlyph Glyph
=> new RichGlyph(opacityStyle: "ColorIconRotateLeft");
=> new(opacityStyle: "ColorIconRotateLeft");

protected override BitmapRotation Rotation
=> BitmapRotation.Clockwise270Degrees;
Expand Down
@@ -1,8 +1,6 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Commands;
using Files.App.Extensions;
using Windows.Graphics.Imaging;

namespace Files.App.Actions
Expand All @@ -16,7 +14,7 @@ public override string Description
=> "RotateRightDescription".GetLocalizedResource();

public override RichGlyph Glyph
=> new RichGlyph(opacityStyle: "ColorIconRotateRight");
=> new(opacityStyle: "ColorIconRotateRight");

protected override BitmapRotation Rotation
=> BitmapRotation.Clockwise90Degrees;
Expand Down
@@ -1,10 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Shell;
using Files.Backend.Helpers;

namespace Files.App.Actions
{
Expand Down
@@ -1,8 +1,6 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Shell;

namespace Files.App.Actions
Expand Down
13 changes: 6 additions & 7 deletions src/Files.App/Actions/Content/PlayAllAction.cs
@@ -1,23 +1,20 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Commands;
using Files.App.Contexts;

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

public string Label
{ get; } = "PlayAll".GetLocalizedResource();
=> "PlayAll".GetLocalizedResource();

public string Description
{ get; } = "PlayAllDescription".GetLocalizedResource();
=> "PlayAllDescription".GetLocalizedResource();

public RichGlyph Glyph
{ get; } = new("\uE768");
=> new("\uE768");

public bool IsExecutable =>
context.PageType != ContentPageTypes.RecycleBin &&
Expand All @@ -26,6 +23,8 @@ public RichGlyph Glyph

public PlayAllAction()
{
context = Ioc.Default.GetRequiredService<IContentPageContext>();

context.PropertyChanged += Context_PropertyChanged;
}

Expand Down
@@ -1,9 +1,6 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Commands;
using Files.App.Contexts;

namespace Files.App.Actions
{
internal class LaunchPreviewPopupAction : ObservableObject, IAction
Expand All @@ -28,6 +25,7 @@ public HotKey HotKey

public LaunchPreviewPopupAction()
{
context = Ioc.Default.GetRequiredService<IContentPageContext>();
previewPopupService = Ioc.Default.GetRequiredService<IPreviewPopupService>();

context.PropertyChanged += Context_PropertyChanged;
Expand All @@ -42,17 +40,6 @@ public async Task ExecuteAsync()
await provider.TogglePreviewPopup(context.SelectedItem!.ItemPath);
}

public void Context_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IContentPageContext.SelectedItems):
OnPropertyChanged(nameof(IsExecutable));
var _ = SwitchPopupPreview();
break;
}
}

private async Task SwitchPopupPreview()
{
if (IsExecutable)
Expand All @@ -64,5 +51,16 @@ private async Task SwitchPopupPreview()
await provider.SwitchPreview(context.SelectedItem!.ItemPath);
}
}

public void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IContentPageContext.SelectedItems):
OnPropertyChanged(nameof(IsExecutable));
var _ = SwitchPopupPreview();
break;
}
}
}
}