Implemented modular create actions

This commit is contained in:
Marcel Baumgartner
2024-03-30 22:26:52 +01:00
parent b2929fe211
commit cdc2954d0b
9 changed files with 112 additions and 87 deletions

View File

@@ -0,0 +1,30 @@
using MoonCoreUI.Services;
using Moonlight.Features.FileManager.Interfaces;
using Moonlight.Features.FileManager.Models.Abstractions.FileAccess;
using Moonlight.Features.FileManager.UI.NewFileManager;
namespace Moonlight.Features.FileManager.Implementations;
public class RenameContextAction : IFileManagerContextAction
{
public string Name => "Rename";
public string Icon => "bxs-rename";
public string Color => "info";
public Func<FileEntry, bool> Filter => _ => true;
public async Task Execute(BaseFileAccess access, FileView view, FileEntry entry, IServiceProvider provider)
{
var alertService = provider.GetRequiredService<AlertService>();
var toastService = provider.GetRequiredService<ToastService>();
var newName = await alertService.Text($"Enter a new name for '{entry.Name}'", "", entry.Name);
if (string.IsNullOrEmpty(newName))
return;
await access.Rename(entry.Name, newName);
await view.Refresh();
await toastService.Success("Successfully renamed file");
}
}