add delete directory

This commit is contained in:
Matt Parker
2025-10-20 00:39:08 +10:00
parent e379d064f3
commit 4278b729dc
6 changed files with 51 additions and 3 deletions

View File

@@ -12,4 +12,10 @@ public class IdeFileOperationsService(SharpIdeSolutionModificationService sharpI
Directory.CreateDirectory(newDirectoryPath);
var newFolder = await _sharpIdeSolutionModificationService.AddDirectory(parentFolder, newDirectoryName);
}
public async Task DeleteDirectory(SharpIdeFolder folder)
{
Directory.Delete(folder.Path, true);
await _sharpIdeSolutionModificationService.RemoveDirectory(folder);
}
}

View File

@@ -17,4 +17,11 @@ public class SharpIdeSolutionModificationService
SolutionModel.AllFolders.Add(sharpIdeFolder);
return sharpIdeFolder;
}
public async Task RemoveDirectory(SharpIdeFolder folder)
{
var parentFolderOrProject = (IFolderOrProject)folder.Parent;
parentFolderOrProject.Folders.Remove(folder);
SolutionModel.AllFolders.Remove(folder);
}
}

View File

@@ -5,7 +5,7 @@ using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
namespace SharpIDE.Application.Features.SolutionDiscovery;
public class SharpIdeFolder : ISharpIdeNode, IExpandableSharpIdeNode, IChildSharpIdeNode
public class SharpIdeFolder : ISharpIdeNode, IExpandableSharpIdeNode, IChildSharpIdeNode, IFolderOrProject
{
public required IExpandableSharpIdeNode Parent { get; set; }
public required string Path { get; set; }

View File

@@ -14,6 +14,12 @@ public interface IExpandableSharpIdeNode
{
public bool Expanded { get; set; }
}
public interface IFolderOrProject
{
public ObservableHashSet<SharpIdeFolder> Folders { get; init; }
public ObservableHashSet<SharpIdeFile> Files { get; init; }
}
public interface IChildSharpIdeNode
{
public IExpandableSharpIdeNode Parent { get; set; }

View File

@@ -15,7 +15,7 @@ public static class ObservableTreeExtensions
{
foreach (var existing in hashSet)
{
var viewChangedEvent = new ViewChangedEvent<T, TreeItemContainer>(NotifyCollectionChangedAction.Add, (existing, new TreeItemContainer()), (null!, null!), 0, 0, new SortOperation<T>());
var viewChangedEvent = new ViewChangedEvent<T, TreeItemContainer>(NotifyCollectionChangedAction.Add, (existing, new TreeItemContainer()), (null!, null!), -1, -1, new SortOperation<T>());
func(viewChangedEvent);
}
return hashSet;

View File

@@ -1,4 +1,5 @@
using Godot;
using SharpIDE.Application.Features.FileWatching;
using SharpIDE.Application.Features.SolutionDiscovery;
using SharpIDE.Godot.Features.SolutionExplorer.ContextMenus.Dialogs;
@@ -7,7 +8,8 @@ namespace SharpIDE.Godot.Features.SolutionExplorer;
file enum FolderContextMenuOptions
{
CreateNew = 1,
RevealInFileExplorer = 2
RevealInFileExplorer = 2,
Delete = 3
}
file enum CreateNewSubmenuOptions
@@ -18,6 +20,7 @@ file enum CreateNewSubmenuOptions
public partial class SolutionExplorerPanel
{
[Inject] private readonly IdeFileOperationsService _ideFileOperationsService = null!;
private void OpenContextMenuFolder(SharpIdeFolder folder)
{
var menu = new PopupMenu();
@@ -30,6 +33,7 @@ public partial class SolutionExplorerPanel
createNewSubmenu.IdPressed += id => OnCreateNewSubmenuPressed(id, folder);
menu.AddItem("Reveal in File Explorer", (int)FolderContextMenuOptions.RevealInFileExplorer);
menu.AddItem("Delete", (int)FolderContextMenuOptions.Delete);
menu.PopupHide += () => menu.QueueFree();
menu.IdPressed += id =>
{
@@ -38,6 +42,31 @@ public partial class SolutionExplorerPanel
{
OS.ShellOpen(folder.Path);
}
else if (actionId is FolderContextMenuOptions.Delete)
{
var confirmedTcs = new TaskCompletionSource<bool>();
var confirmationDialog = new ConfirmationDialog();
confirmationDialog.Title = "Delete";
confirmationDialog.DialogText = $"Delete '{folder.Name}' file?";
confirmationDialog.Confirmed += () =>
{
confirmedTcs.SetResult(true);
};
confirmationDialog.Canceled += () =>
{
confirmedTcs.SetResult(false);
};
AddChild(confirmationDialog);
confirmationDialog.PopupCentered();
_ = Task.GodotRun(async () =>
{
var confirmed = await confirmedTcs.Task;
if (confirmed)
{
await _ideFileOperationsService.DeleteDirectory(folder);
}
});
}
};
var globalMousePosition = GetGlobalMousePosition();