From 0c3a3f7265b141b55649450d60b9e9b792fc7cf2 Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Mon, 20 Oct 2025 20:00:01 +1000 Subject: [PATCH] ide delete file --- .../FileWatching/IdeFileOperationsService.cs | 10 +++--- .../SharpIdeSolutionModificationService.cs | 8 +++++ .../ContextMenus/FileContextMenu.cs | 33 ++++++++++++++++++- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/SharpIDE.Application/Features/FileWatching/IdeFileOperationsService.cs b/src/SharpIDE.Application/Features/FileWatching/IdeFileOperationsService.cs index 1c18412..fcd76cf 100644 --- a/src/SharpIDE.Application/Features/FileWatching/IdeFileOperationsService.cs +++ b/src/SharpIDE.Application/Features/FileWatching/IdeFileOperationsService.cs @@ -20,11 +20,11 @@ public class IdeFileOperationsService(SharpIdeSolutionModificationService sharpI await _sharpIdeSolutionModificationService.RemoveDirectory(folder); } - // public async Task DeleteFile(SharpIdeFile file) - // { - // File.Delete(file.Path); - // await _sharpIdeSolutionModificationService.RemoveFile(file); - // } + public async Task DeleteFile(SharpIdeFile file) + { + File.Delete(file.Path); + await _sharpIdeSolutionModificationService.RemoveFile(file); + } public async Task CreateCsFile(SharpIdeFolder parentFolder, string newFileName) { diff --git a/src/SharpIDE.Application/Features/FileWatching/SharpIdeSolutionModificationService.cs b/src/SharpIDE.Application/Features/FileWatching/SharpIdeSolutionModificationService.cs index e9f20e4..8be443b 100644 --- a/src/SharpIDE.Application/Features/FileWatching/SharpIdeSolutionModificationService.cs +++ b/src/SharpIDE.Application/Features/FileWatching/SharpIdeSolutionModificationService.cs @@ -68,4 +68,12 @@ public class SharpIdeSolutionModificationService(FileChangedService fileChangedS SolutionModel.AllFiles.Add(sharpIdeFile); await _fileChangedService.SharpIdeFileAdded(sharpIdeFile, contents); } + + public async Task RemoveFile(SharpIdeFile file) + { + var parentFolderOrProject = (IFolderOrProject)file.Parent; + parentFolderOrProject.Files.Remove(file); + SolutionModel.AllFiles.Remove(file); + await _fileChangedService.SharpIdeFileRemoved(file); + } } diff --git a/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/FileContextMenu.cs b/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/FileContextMenu.cs index 61de879..0422111 100644 --- a/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/FileContextMenu.cs +++ b/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/FileContextMenu.cs @@ -1,5 +1,6 @@ using Godot; using SharpIDE.Application.Features.SolutionDiscovery; +using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence; namespace SharpIDE.Godot.Features.SolutionExplorer; @@ -7,7 +8,8 @@ file enum FileContextMenuOptions { Open = 0, RevealInFileExplorer = 1, - CopyFullPath = 2 + CopyFullPath = 2, + Delete = 3 } public partial class SolutionExplorerPanel @@ -20,6 +22,9 @@ public partial class SolutionExplorerPanel menu.AddItem("Reveal in File Explorer", (int)FileContextMenuOptions.RevealInFileExplorer); menu.AddSeparator(); menu.AddItem("Copy Full Path", (int)FileContextMenuOptions.CopyFullPath); + menu.AddSeparator(); + menu.AddItem("Delete", (int)FileContextMenuOptions.Delete); + if (file.Parent is SharpIdeSolutionFolder) menu.SetItemDisabled((int)FileContextMenuOptions.Delete, true); menu.PopupHide += () => menu.QueueFree(); menu.IdPressed += id => { @@ -36,6 +41,32 @@ public partial class SolutionExplorerPanel { DisplayServer.ClipboardSet(file.Path); } + else if (actionId is FileContextMenuOptions.Delete) + { + var confirmedTcs = new TaskCompletionSource(); + var confirmationDialog = new ConfirmationDialog(); + confirmationDialog.Title = "Delete"; + confirmationDialog.DialogText = $"Delete '{file.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.DeleteFile(file); + } + }); + } }; var globalMousePosition = GetGlobalMousePosition();