ide delete file

This commit is contained in:
Matt Parker
2025-10-20 20:00:01 +10:00
parent e114e2c524
commit 0c3a3f7265
3 changed files with 45 additions and 6 deletions

View File

@@ -20,11 +20,11 @@ public class IdeFileOperationsService(SharpIdeSolutionModificationService sharpI
await _sharpIdeSolutionModificationService.RemoveDirectory(folder); await _sharpIdeSolutionModificationService.RemoveDirectory(folder);
} }
// public async Task DeleteFile(SharpIdeFile file) public async Task DeleteFile(SharpIdeFile file)
// { {
// File.Delete(file.Path); File.Delete(file.Path);
// await _sharpIdeSolutionModificationService.RemoveFile(file); await _sharpIdeSolutionModificationService.RemoveFile(file);
// } }
public async Task CreateCsFile(SharpIdeFolder parentFolder, string newFileName) public async Task CreateCsFile(SharpIdeFolder parentFolder, string newFileName)
{ {

View File

@@ -68,4 +68,12 @@ public class SharpIdeSolutionModificationService(FileChangedService fileChangedS
SolutionModel.AllFiles.Add(sharpIdeFile); SolutionModel.AllFiles.Add(sharpIdeFile);
await _fileChangedService.SharpIdeFileAdded(sharpIdeFile, contents); 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);
}
} }

View File

@@ -1,5 +1,6 @@
using Godot; using Godot;
using SharpIDE.Application.Features.SolutionDiscovery; using SharpIDE.Application.Features.SolutionDiscovery;
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
namespace SharpIDE.Godot.Features.SolutionExplorer; namespace SharpIDE.Godot.Features.SolutionExplorer;
@@ -7,7 +8,8 @@ file enum FileContextMenuOptions
{ {
Open = 0, Open = 0,
RevealInFileExplorer = 1, RevealInFileExplorer = 1,
CopyFullPath = 2 CopyFullPath = 2,
Delete = 3
} }
public partial class SolutionExplorerPanel public partial class SolutionExplorerPanel
@@ -20,6 +22,9 @@ public partial class SolutionExplorerPanel
menu.AddItem("Reveal in File Explorer", (int)FileContextMenuOptions.RevealInFileExplorer); menu.AddItem("Reveal in File Explorer", (int)FileContextMenuOptions.RevealInFileExplorer);
menu.AddSeparator(); menu.AddSeparator();
menu.AddItem("Copy Full Path", (int)FileContextMenuOptions.CopyFullPath); 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.PopupHide += () => menu.QueueFree();
menu.IdPressed += id => menu.IdPressed += id =>
{ {
@@ -36,6 +41,32 @@ public partial class SolutionExplorerPanel
{ {
DisplayServer.ClipboardSet(file.Path); DisplayServer.ClipboardSet(file.Path);
} }
else if (actionId is FileContextMenuOptions.Delete)
{
var confirmedTcs = new TaskCompletionSource<bool>();
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(); var globalMousePosition = GetGlobalMousePosition();