Added modular selection actions
This commit is contained in:
parent
49077e7023
commit
b2929fe211
7 changed files with 107 additions and 34 deletions
|
@ -52,9 +52,11 @@ public class FileManagerFeature : MoonlightFeature
|
|||
// Register default file manager actions in plugin service
|
||||
var pluginService = context.Application.Services.GetRequiredService<PluginService>();
|
||||
|
||||
await pluginService.RegisterImplementation<IFileManagerAction>(new RenameFileManagerAction());
|
||||
await pluginService.RegisterImplementation<IFileManagerAction>(new DownloadFileManagerAction());
|
||||
await pluginService.RegisterImplementation<IFileManagerAction>(new DeleteFileManagerAction());
|
||||
await pluginService.RegisterImplementation<IFileManagerAction>(new RenameAction());
|
||||
await pluginService.RegisterImplementation<IFileManagerAction>(new DownloadAction());
|
||||
await pluginService.RegisterImplementation<IFileManagerAction>(new DeleteAction());
|
||||
|
||||
await pluginService.RegisterImplementation<IFileManagerSelectionAction>(new DeleteSelectionAction());
|
||||
}
|
||||
|
||||
public override async Task OnSessionInitialized(SessionInitContext context)
|
||||
|
|
|
@ -5,7 +5,7 @@ using Moonlight.Features.FileManager.UI.NewFileManager;
|
|||
|
||||
namespace Moonlight.Features.FileManager.Implementations;
|
||||
|
||||
public class DeleteFileManagerAction : IFileManagerAction
|
||||
public class DeleteAction : IFileManagerAction
|
||||
{
|
||||
public string Name => "Delete";
|
||||
public string Icon => "bxs-trash";
|
|
@ -0,0 +1,34 @@
|
|||
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 DeleteSelectionAction : IFileManagerSelectionAction
|
||||
{
|
||||
public string Name => "Delete";
|
||||
public string Color => "danger";
|
||||
|
||||
public async Task Execute(BaseFileAccess access, FileView view, FileEntry[] entries, IServiceProvider provider)
|
||||
{
|
||||
var alertService = provider.GetRequiredService<AlertService>();
|
||||
var toastService = provider.GetRequiredService<ToastService>();
|
||||
|
||||
if(!await alertService.YesNo($"Do you really want to delete {entries.Length} item(s)?"))
|
||||
return;
|
||||
|
||||
await toastService.CreateProgress("fileManagerSelectionDelete", "Deleting items");
|
||||
|
||||
foreach (var entry in entries)
|
||||
{
|
||||
await toastService.ModifyProgress("fileManagerSelectionDelete", $"Deleting '{entry.Name}'");
|
||||
|
||||
await access.Delete(entry);
|
||||
}
|
||||
|
||||
await toastService.RemoveProgress("fileManagerSelectionDelete");
|
||||
|
||||
await toastService.Success($"Successfully deleted selection");
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ using Moonlight.Features.FileManager.UI.NewFileManager;
|
|||
|
||||
namespace Moonlight.Features.FileManager.Implementations;
|
||||
|
||||
public class DownloadFileManagerAction : IFileManagerAction
|
||||
public class DownloadAction : IFileManagerAction
|
||||
{
|
||||
public string Name => "Download";
|
||||
public string Icon => "bxs-cloud-download";
|
|
@ -5,7 +5,7 @@ using Moonlight.Features.FileManager.UI.NewFileManager;
|
|||
|
||||
namespace Moonlight.Features.FileManager.Implementations;
|
||||
|
||||
public class RenameFileManagerAction : IFileManagerAction
|
||||
public class RenameAction : IFileManagerAction
|
||||
{
|
||||
public string Name => "Rename";
|
||||
public string Icon => "bxs-rename";
|
|
@ -0,0 +1,12 @@
|
|||
using Moonlight.Features.FileManager.Models.Abstractions.FileAccess;
|
||||
using Moonlight.Features.FileManager.UI.NewFileManager;
|
||||
|
||||
namespace Moonlight.Features.FileManager.Interfaces;
|
||||
|
||||
public interface IFileManagerSelectionAction
|
||||
{
|
||||
public string Name { get; }
|
||||
public string Color { get; }
|
||||
|
||||
public Task Execute(BaseFileAccess access, FileView view, FileEntry[] entries, IServiceProvider provider);
|
||||
}
|
|
@ -45,6 +45,17 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="d-flex justify-content-center justify-content-md-end align-items-center">
|
||||
@if (View != null && View.Selection.Any())
|
||||
{
|
||||
foreach (var action in SelectionActions)
|
||||
{
|
||||
var cssClass = $"btn btn-{action.Color} mx-2";
|
||||
|
||||
<WButton Text="@action.Name" CssClasses="@cssClass" OnClick="() => InvokeSelectionAction(action)" />
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<WButton OnClick="ManualRefresh" CssClasses="btn btn-icon btn-light-info">
|
||||
<i class="bx bx-sm bx-refresh"></i>
|
||||
</WButton>
|
||||
|
@ -69,6 +80,7 @@
|
|||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -86,6 +98,7 @@ else
|
|||
FileAccess="FileAccess"
|
||||
OnEntryClicked="OnEntryClicked"
|
||||
OnNavigateUpClicked="OnNavigateUpClicked"
|
||||
OnSelectionChanged="OnSelectionChanged"
|
||||
EnableContextMenu="true">
|
||||
<ContextMenuTemplate>
|
||||
@foreach (var action in Actions)
|
||||
|
@ -138,6 +151,7 @@ else
|
|||
private string Path = "/";
|
||||
|
||||
private IFileManagerAction[] Actions;
|
||||
private IFileManagerSelectionAction[] SelectionActions;
|
||||
|
||||
// Editor
|
||||
private FileEditor Editor;
|
||||
|
@ -156,8 +170,12 @@ else
|
|||
|
||||
private Timer? UploadTokenTimer;
|
||||
|
||||
protected override void OnInitialized()
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
// Load plugin ui and options
|
||||
Actions = await PluginService.GetImplementations<IFileManagerAction>();
|
||||
SelectionActions = await PluginService.GetImplementations<IFileManagerSelectionAction>();
|
||||
|
||||
OnFolderClicked = async entry =>
|
||||
{
|
||||
await MoveAccess.ChangeDirectory(entry.Name);
|
||||
|
@ -175,9 +193,6 @@ else
|
|||
if (!firstRender)
|
||||
return;
|
||||
|
||||
// Load plugin ui and options
|
||||
Actions = await PluginService.GetImplementations<IFileManagerAction>();
|
||||
|
||||
|
||||
// Setup upload url update timer
|
||||
UploadTokenTimer = new(async _ =>
|
||||
|
@ -233,6 +248,16 @@ else
|
|||
await action.Execute(FileAccess, View, entry, ServiceProvider);
|
||||
}
|
||||
|
||||
private async Task InvokeSelectionAction(IFileManagerSelectionAction action)
|
||||
{
|
||||
await action.Execute(FileAccess, View, View.Selection, ServiceProvider);
|
||||
|
||||
// Refresh resets the selection
|
||||
await View.Refresh();
|
||||
}
|
||||
|
||||
private async Task OnSelectionChanged(FileEntry[] _) => await InvokeAsync(StateHasChanged);
|
||||
|
||||
#region Navigation & Refreshing
|
||||
|
||||
private async Task OnNavigateUpClicked()
|
||||
|
|
Loading…
Reference in a new issue