add delete directory
This commit is contained in:
@@ -12,4 +12,10 @@ public class IdeFileOperationsService(SharpIdeSolutionModificationService sharpI
|
|||||||
Directory.CreateDirectory(newDirectoryPath);
|
Directory.CreateDirectory(newDirectoryPath);
|
||||||
var newFolder = await _sharpIdeSolutionModificationService.AddDirectory(parentFolder, newDirectoryName);
|
var newFolder = await _sharpIdeSolutionModificationService.AddDirectory(parentFolder, newDirectoryName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task DeleteDirectory(SharpIdeFolder folder)
|
||||||
|
{
|
||||||
|
Directory.Delete(folder.Path, true);
|
||||||
|
await _sharpIdeSolutionModificationService.RemoveDirectory(folder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,4 +17,11 @@ public class SharpIdeSolutionModificationService
|
|||||||
SolutionModel.AllFolders.Add(sharpIdeFolder);
|
SolutionModel.AllFolders.Add(sharpIdeFolder);
|
||||||
return sharpIdeFolder;
|
return sharpIdeFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task RemoveDirectory(SharpIdeFolder folder)
|
||||||
|
{
|
||||||
|
var parentFolderOrProject = (IFolderOrProject)folder.Parent;
|
||||||
|
parentFolderOrProject.Folders.Remove(folder);
|
||||||
|
SolutionModel.AllFolders.Remove(folder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
|
|||||||
|
|
||||||
namespace SharpIDE.Application.Features.SolutionDiscovery;
|
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 IExpandableSharpIdeNode Parent { get; set; }
|
||||||
public required string Path { get; set; }
|
public required string Path { get; set; }
|
||||||
|
|||||||
@@ -14,6 +14,12 @@ public interface IExpandableSharpIdeNode
|
|||||||
{
|
{
|
||||||
public bool Expanded { get; set; }
|
public bool Expanded { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface IFolderOrProject
|
||||||
|
{
|
||||||
|
public ObservableHashSet<SharpIdeFolder> Folders { get; init; }
|
||||||
|
public ObservableHashSet<SharpIdeFile> Files { get; init; }
|
||||||
|
}
|
||||||
public interface IChildSharpIdeNode
|
public interface IChildSharpIdeNode
|
||||||
{
|
{
|
||||||
public IExpandableSharpIdeNode Parent { get; set; }
|
public IExpandableSharpIdeNode Parent { get; set; }
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public static class ObservableTreeExtensions
|
|||||||
{
|
{
|
||||||
foreach (var existing in hashSet)
|
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);
|
func(viewChangedEvent);
|
||||||
}
|
}
|
||||||
return hashSet;
|
return hashSet;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using SharpIDE.Application.Features.FileWatching;
|
||||||
using SharpIDE.Application.Features.SolutionDiscovery;
|
using SharpIDE.Application.Features.SolutionDiscovery;
|
||||||
using SharpIDE.Godot.Features.SolutionExplorer.ContextMenus.Dialogs;
|
using SharpIDE.Godot.Features.SolutionExplorer.ContextMenus.Dialogs;
|
||||||
|
|
||||||
@@ -7,7 +8,8 @@ namespace SharpIDE.Godot.Features.SolutionExplorer;
|
|||||||
file enum FolderContextMenuOptions
|
file enum FolderContextMenuOptions
|
||||||
{
|
{
|
||||||
CreateNew = 1,
|
CreateNew = 1,
|
||||||
RevealInFileExplorer = 2
|
RevealInFileExplorer = 2,
|
||||||
|
Delete = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
file enum CreateNewSubmenuOptions
|
file enum CreateNewSubmenuOptions
|
||||||
@@ -18,6 +20,7 @@ file enum CreateNewSubmenuOptions
|
|||||||
|
|
||||||
public partial class SolutionExplorerPanel
|
public partial class SolutionExplorerPanel
|
||||||
{
|
{
|
||||||
|
[Inject] private readonly IdeFileOperationsService _ideFileOperationsService = null!;
|
||||||
private void OpenContextMenuFolder(SharpIdeFolder folder)
|
private void OpenContextMenuFolder(SharpIdeFolder folder)
|
||||||
{
|
{
|
||||||
var menu = new PopupMenu();
|
var menu = new PopupMenu();
|
||||||
@@ -30,6 +33,7 @@ public partial class SolutionExplorerPanel
|
|||||||
createNewSubmenu.IdPressed += id => OnCreateNewSubmenuPressed(id, folder);
|
createNewSubmenu.IdPressed += id => OnCreateNewSubmenuPressed(id, folder);
|
||||||
|
|
||||||
menu.AddItem("Reveal in File Explorer", (int)FolderContextMenuOptions.RevealInFileExplorer);
|
menu.AddItem("Reveal in File Explorer", (int)FolderContextMenuOptions.RevealInFileExplorer);
|
||||||
|
menu.AddItem("Delete", (int)FolderContextMenuOptions.Delete);
|
||||||
menu.PopupHide += () => menu.QueueFree();
|
menu.PopupHide += () => menu.QueueFree();
|
||||||
menu.IdPressed += id =>
|
menu.IdPressed += id =>
|
||||||
{
|
{
|
||||||
@@ -38,6 +42,31 @@ public partial class SolutionExplorerPanel
|
|||||||
{
|
{
|
||||||
OS.ShellOpen(folder.Path);
|
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();
|
var globalMousePosition = GetGlobalMousePosition();
|
||||||
|
|||||||
Reference in New Issue
Block a user