Skip to content

Commit

Permalink
Code Quality: Create alike RichCommands inheritance (files-community#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ferrariofilippo authored Aug 15, 2023
1 parent bd8c78f commit 2b4132f
Show file tree
Hide file tree
Showing 23 changed files with 417 additions and 521 deletions.
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

0 comments on commit 2b4132f

Please sign in to comment.