From 0441f6a3dacddcdae2bf336a79039bdbae418db8 Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Sun, 10 Sep 2023 02:19:11 -0500 Subject: [PATCH] New folder creation. Allow deletion of selected items. --- .../FileManagerComponents/FileManager.razor | 54 +++++++++++++++++-- .../NewFolderModal.razor | 34 ++++++++++++ 2 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 LANCommander/Components/FileManagerComponents/NewFolderModal.razor diff --git a/LANCommander/Components/FileManagerComponents/FileManager.razor b/LANCommander/Components/FileManagerComponents/FileManager.razor index 7d73c23..1eb9933 100644 --- a/LANCommander/Components/FileManagerComponents/FileManager.razor +++ b/LANCommander/Components/FileManagerComponents/FileManager.razor @@ -1,5 +1,6 @@ @using AntDesign.TableModels; @inject ArchiveService ArchiveService +@inject IMessageService MessageService
@@ -21,7 +22,7 @@ -
+ + @code { [Parameter] public Guid ArchiveId { get; set; } [Parameter] public string WorkingDirectory { get; set; } @@ -125,6 +128,8 @@ List Entries { get; set; } = new List(); HashSet Directories { get; set; } = new HashSet(); + NewFolderModal NewFolderModal; + Dictionary OnRow(RowData row) => new() { ["data-path"] = row.Data.Path, @@ -313,8 +318,47 @@ ChangeDirectory(Path.Parent, true); } - void NewFolder() + void Refresh() { - + ChangeDirectory(Path, false); + } + + void AddFolder(string name) + { + try + { + Directory.CreateDirectory(System.IO.Path.Combine(Path.Path, name)); + + Refresh(); + + MessageService.Success("Folder created!"); + } + catch + { + MessageService.Error("Error creating folder!"); + } + } + + void Delete() + { + try + { + foreach (var entry in Selected) + { + if (entry is FileManagerDirectory) + Directory.Delete(entry.Path); + else if (entry is FileManagerFile) + File.Delete(entry.Path); + } + + Selected = new List(); + MessageService.Success("Deleted!"); + } + catch + { + MessageService.Error("Error deleting!"); + } + + Refresh(); } } diff --git a/LANCommander/Components/FileManagerComponents/NewFolderModal.razor b/LANCommander/Components/FileManagerComponents/NewFolderModal.razor new file mode 100644 index 0000000..5df4468 --- /dev/null +++ b/LANCommander/Components/FileManagerComponents/NewFolderModal.razor @@ -0,0 +1,34 @@ + + + + +@code { + [Parameter] public EventCallback OnFolderNameEntered { get; set; } + + bool Visible { get; set; } = false; + string Name { get; set; } + + protected override async Task OnInitializedAsync() + { + Name = ""; + } + + public void Open() + { + Name = ""; + Visible = true; + } + + public void Close() + { + Visible = false; + } + + async Task OnOk(MouseEventArgs e) + { + if (OnFolderNameEntered.HasDelegate) + await OnFolderNameEntered.InvokeAsync(Name); + + Close(); + } +}