diff --git a/Moonlight/Features/FileManager/FileManagerFeature.cs b/Moonlight/Features/FileManager/FileManagerFeature.cs index 395fe1d..b97cec7 100644 --- a/Moonlight/Features/FileManager/FileManagerFeature.cs +++ b/Moonlight/Features/FileManager/FileManagerFeature.cs @@ -52,11 +52,14 @@ public class FileManagerFeature : MoonlightFeature // Register default file manager actions in plugin service var pluginService = context.Application.Services.GetRequiredService(); - await pluginService.RegisterImplementation(new RenameAction()); - await pluginService.RegisterImplementation(new DownloadAction()); - await pluginService.RegisterImplementation(new DeleteAction()); + await pluginService.RegisterImplementation(new RenameContextAction()); + await pluginService.RegisterImplementation(new DownloadContextAction()); + await pluginService.RegisterImplementation(new DeleteContextAction()); await pluginService.RegisterImplementation(new DeleteSelectionAction()); + + await pluginService.RegisterImplementation(new CreateFileAction()); + await pluginService.RegisterImplementation(new CreateFolderAction()); } public override async Task OnSessionInitialized(SessionInitContext context) diff --git a/Moonlight/Features/FileManager/Implementations/CreateFileAction.cs b/Moonlight/Features/FileManager/Implementations/CreateFileAction.cs new file mode 100644 index 0000000..45fccbd --- /dev/null +++ b/Moonlight/Features/FileManager/Implementations/CreateFileAction.cs @@ -0,0 +1,37 @@ +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 CreateFileAction : IFileManagerCreateAction +{ + public string Name => "File"; + public string Icon => "bx-file"; + public string Color => "primary"; + + public async Task Execute(BaseFileAccess access, FileView view, IServiceProvider provider) + { + var alertService = provider.GetRequiredService(); + + var name = await alertService.Text("Enter a name for the new file"); + + if (string.IsNullOrEmpty(name) || name.Contains("..")) + return; + + await access.CreateFile(name); + + /* + + // We build a virtual entry here so we dont need to fetch one + await OpenEditor(new() + { + Name = name, + Size = 0, + IsFile = true, + IsDirectory = false, + LastModifiedAt = DateTime.UtcNow + });*/ + } +} \ No newline at end of file diff --git a/Moonlight/Features/FileManager/Implementations/CreateFolderAction.cs b/Moonlight/Features/FileManager/Implementations/CreateFolderAction.cs new file mode 100644 index 0000000..78d7679 --- /dev/null +++ b/Moonlight/Features/FileManager/Implementations/CreateFolderAction.cs @@ -0,0 +1,29 @@ +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 CreateFolderAction : IFileManagerCreateAction +{ + public string Name => "Folder"; + public string Icon => "bx-folder"; + public string Color => "primary"; + + public async Task Execute(BaseFileAccess access, FileView view, IServiceProvider provider) + { + var alertService = provider.GetRequiredService(); + var toastService = provider.GetRequiredService(); + + var name = await alertService.Text("Enter a name for the new directory"); + + if (string.IsNullOrEmpty(name) || name.Contains("..")) + return; + + await access.CreateDirectory(name); + + await toastService.Success("Successfully created directory"); + await view.Refresh(); + } +} \ No newline at end of file diff --git a/Moonlight/Features/FileManager/Implementations/DeleteAction.cs b/Moonlight/Features/FileManager/Implementations/DeleteContextAction.cs similarity index 92% rename from Moonlight/Features/FileManager/Implementations/DeleteAction.cs rename to Moonlight/Features/FileManager/Implementations/DeleteContextAction.cs index fc32cf9..7e31caf 100644 --- a/Moonlight/Features/FileManager/Implementations/DeleteAction.cs +++ b/Moonlight/Features/FileManager/Implementations/DeleteContextAction.cs @@ -5,7 +5,7 @@ using Moonlight.Features.FileManager.UI.NewFileManager; namespace Moonlight.Features.FileManager.Implementations; -public class DeleteAction : IFileManagerAction +public class DeleteContextAction : IFileManagerContextAction { public string Name => "Delete"; public string Icon => "bxs-trash"; diff --git a/Moonlight/Features/FileManager/Implementations/DownloadAction.cs b/Moonlight/Features/FileManager/Implementations/DownloadContextAction.cs similarity index 95% rename from Moonlight/Features/FileManager/Implementations/DownloadAction.cs rename to Moonlight/Features/FileManager/Implementations/DownloadContextAction.cs index 6ebc597..88a69ff 100644 --- a/Moonlight/Features/FileManager/Implementations/DownloadAction.cs +++ b/Moonlight/Features/FileManager/Implementations/DownloadContextAction.cs @@ -8,7 +8,7 @@ using Moonlight.Features.FileManager.UI.NewFileManager; namespace Moonlight.Features.FileManager.Implementations; -public class DownloadAction : IFileManagerAction +public class DownloadContextAction : IFileManagerContextAction { public string Name => "Download"; public string Icon => "bxs-cloud-download"; diff --git a/Moonlight/Features/FileManager/Implementations/RenameAction.cs b/Moonlight/Features/FileManager/Implementations/RenameContextAction.cs similarity index 94% rename from Moonlight/Features/FileManager/Implementations/RenameAction.cs rename to Moonlight/Features/FileManager/Implementations/RenameContextAction.cs index 56dda46..804173f 100644 --- a/Moonlight/Features/FileManager/Implementations/RenameAction.cs +++ b/Moonlight/Features/FileManager/Implementations/RenameContextAction.cs @@ -5,7 +5,7 @@ using Moonlight.Features.FileManager.UI.NewFileManager; namespace Moonlight.Features.FileManager.Implementations; -public class RenameAction : IFileManagerAction +public class RenameContextAction : IFileManagerContextAction { public string Name => "Rename"; public string Icon => "bxs-rename"; diff --git a/Moonlight/Features/FileManager/Interfaces/IFileManagerAction.cs b/Moonlight/Features/FileManager/Interfaces/IFileManagerContextAction.cs similarity index 90% rename from Moonlight/Features/FileManager/Interfaces/IFileManagerAction.cs rename to Moonlight/Features/FileManager/Interfaces/IFileManagerContextAction.cs index c2e0598..d32106d 100644 --- a/Moonlight/Features/FileManager/Interfaces/IFileManagerAction.cs +++ b/Moonlight/Features/FileManager/Interfaces/IFileManagerContextAction.cs @@ -3,7 +3,7 @@ using Moonlight.Features.FileManager.UI.NewFileManager; namespace Moonlight.Features.FileManager.Interfaces; -public interface IFileManagerAction +public interface IFileManagerContextAction { public string Name { get; } public string Icon { get; } diff --git a/Moonlight/Features/FileManager/Interfaces/IFileManagerCreateAction.cs b/Moonlight/Features/FileManager/Interfaces/IFileManagerCreateAction.cs new file mode 100644 index 0000000..7ed2328 --- /dev/null +++ b/Moonlight/Features/FileManager/Interfaces/IFileManagerCreateAction.cs @@ -0,0 +1,13 @@ +using Moonlight.Features.FileManager.Models.Abstractions.FileAccess; +using Moonlight.Features.FileManager.UI.NewFileManager; + +namespace Moonlight.Features.FileManager.Interfaces; + +public interface IFileManagerCreateAction +{ + public string Name { get; } + public string Icon { get; } + public string Color { get; } + + public Task Execute(BaseFileAccess access, FileView view, IServiceProvider provider); +} \ No newline at end of file diff --git a/Moonlight/Features/FileManager/UI/NewFileManager/FileManager.razor b/Moonlight/Features/FileManager/UI/NewFileManager/FileManager.razor index 12a6d33..0a3c736 100644 --- a/Moonlight/Features/FileManager/UI/NewFileManager/FileManager.razor +++ b/Moonlight/Features/FileManager/UI/NewFileManager/FileManager.razor @@ -65,19 +65,16 @@ -