ide delete file
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<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();
|
||||
|
||||
Reference in New Issue
Block a user