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: Create alike RichCommands inheritance #13155

Merged
merged 6 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,27 @@

namespace Files.App.Actions
{
internal class DecompressArchiveHere : BaseUIAction, IAction
internal abstract class BaseCompressArchiveAction : BaseUIAction, IAction
{
private readonly IContentPageContext context;
protected readonly IContentPageContext context;

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

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

public override bool IsExecutable =>
IsContextPageTypeAdaptedToCommand() &&
ArchiveHelpers.CanDecompress(context.SelectedItems) &&
ArchiveHelpers.CanCompress(context.SelectedItems) &&
UIHelpers.CanShowDialog;

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

context.PropertyChanged += Context_PropertyChanged;
}

public Task ExecuteAsync()
{
return ArchiveHelpers.DecompressArchiveHere(context.ShellPage);
}
public abstract Task ExecuteAsync();

private bool IsContextPageTypeAdaptedToCommand()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Dialogs;
using Microsoft.UI.Xaml.Controls;

namespace Files.App.Actions
{
internal sealed class CompressIntoArchiveAction : BaseCompressArchiveAction
{
public override string Label
=> "CreateArchive".GetLocalizedResource();

public override string Description
=> "CompressIntoArchiveDescription".GetLocalizedResource();

public CompressIntoArchiveAction()
{
}

public override async Task ExecuteAsync()
{
var (sources, directory, fileName) = ArchiveHelpers.GetCompressDestination(context.ShellPage);

var dialog = new CreateArchiveDialog
{
FileName = fileName,
};

var result = await dialog.TryShowAsync();

if (!dialog.CanCreate || result != ContentDialogResult.Primary)
return;

IArchiveCreator creator = new ArchiveCreator
{
Sources = sources,
Directory = directory,
FileName = dialog.FileName,
Password = dialog.Password,
FileFormat = dialog.FileFormat,
CompressionLevel = dialog.CompressionLevel,
SplittingSize = dialog.SplittingSize,
};

await ArchiveHelpers.CompressArchiveAsync(creator);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

namespace Files.App.Actions
{
internal sealed class CompressIntoSevenZipAction : BaseCompressArchiveAction
{
public override string Label
=> string.Format("CreateNamedArchive".GetLocalizedResource(), $"{ArchiveHelpers.DetermineArchiveNameFromSelection(context.SelectedItems)}.7z");

public override string Description
=> "CompressIntoSevenZipDescription".GetLocalizedResource();

public CompressIntoSevenZipAction()
{
}

public override Task ExecuteAsync()
{
var (sources, directory, fileName) = ArchiveHelpers.GetCompressDestination(context.ShellPage);

IArchiveCreator creator = new ArchiveCreator
{
Sources = sources,
Directory = directory,
FileName = fileName,
FileFormat = ArchiveFormats.SevenZip,
};

return ArchiveHelpers.CompressArchiveAsync(creator);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

namespace Files.App.Actions
{
internal sealed class CompressIntoZipAction : BaseCompressArchiveAction
{
public override string Label
=> string.Format("CreateNamedArchive".GetLocalizedResource(), $"{ArchiveHelpers.DetermineArchiveNameFromSelection(context.SelectedItems)}.zip");

public override string Description
=> "CompressIntoZipDescription".GetLocalizedResource();

public CompressIntoZipAction()
{
}

public override Task ExecuteAsync()
{
var (sources, directory, fileName) = ArchiveHelpers.GetCompressDestination(context.ShellPage);

IArchiveCreator creator = new ArchiveCreator
{
Sources = sources,
Directory = directory,
FileName = fileName,
FileFormat = ArchiveFormats.Zip,
};

return ArchiveHelpers.CompressArchiveAsync(creator);
}
}
}

This file was deleted.

This file was deleted.

63 changes: 0 additions & 63 deletions src/Files.App/Actions/Content/Archives/CompressIntoZipAction.cs

This file was deleted.

Loading