From 0a913a8e26c0d3963ddc54c9d188eb0281de784b Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Mon, 20 Oct 2025 21:48:59 +1000 Subject: [PATCH] open new file on create --- .../Features/FileWatching/IdeFileOperationsService.cs | 5 +++-- .../FileWatching/SharpIdeSolutionModificationService.cs | 3 ++- .../ContextMenus/Dialogs/NewCsharpFileDialog.cs | 5 +++-- .../SolutionExplorer/ContextMenus/FileContextMenu.cs | 2 +- .../SolutionExplorer/ContextMenus/FolderContextMenu.cs | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/SharpIDE.Application/Features/FileWatching/IdeFileOperationsService.cs b/src/SharpIDE.Application/Features/FileWatching/IdeFileOperationsService.cs index 7d0bc14..9bd54d3 100644 --- a/src/SharpIDE.Application/Features/FileWatching/IdeFileOperationsService.cs +++ b/src/SharpIDE.Application/Features/FileWatching/IdeFileOperationsService.cs @@ -26,14 +26,15 @@ public class IdeFileOperationsService(SharpIdeSolutionModificationService sharpI await _sharpIdeSolutionModificationService.RemoveFile(file); } - public async Task CreateCsFile(IFolderOrProject parentNode, string newFileName) + public async Task CreateCsFile(IFolderOrProject parentNode, string newFileName) { var newFilePath = Path.Combine(GetFileParentNodePath(parentNode), newFileName); var className = Path.GetFileNameWithoutExtension(newFileName); var @namespace = NewFileTemplates.ComputeNamespace(parentNode); var fileText = NewFileTemplates.CsharpClass(className, @namespace); await File.WriteAllTextAsync(newFilePath, fileText); - await _sharpIdeSolutionModificationService.CreateFile(parentNode, newFilePath, newFileName, fileText); + var sharpIdeFile = await _sharpIdeSolutionModificationService.CreateFile(parentNode, newFilePath, newFileName, fileText); + return sharpIdeFile; } private static string GetFileParentNodePath(IFolderOrProject parentNode) => parentNode switch diff --git a/src/SharpIDE.Application/Features/FileWatching/SharpIdeSolutionModificationService.cs b/src/SharpIDE.Application/Features/FileWatching/SharpIdeSolutionModificationService.cs index bab7f07..d8eee21 100644 --- a/src/SharpIDE.Application/Features/FileWatching/SharpIdeSolutionModificationService.cs +++ b/src/SharpIDE.Application/Features/FileWatching/SharpIdeSolutionModificationService.cs @@ -60,12 +60,13 @@ public class SharpIdeSolutionModificationService(FileChangedService fileChangedS } } - public async Task CreateFile(IFolderOrProject parentNode, string newFilePath, string fileName, string contents) + public async Task CreateFile(IFolderOrProject parentNode, string newFilePath, string fileName, string contents) { var sharpIdeFile = new SharpIdeFile(newFilePath, fileName, parentNode, []); parentNode.Files.Add(sharpIdeFile); SolutionModel.AllFiles.Add(sharpIdeFile); await _fileChangedService.SharpIdeFileAdded(sharpIdeFile, contents); + return sharpIdeFile; } public async Task RemoveFile(SharpIdeFile file) diff --git a/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/Dialogs/NewCsharpFileDialog.cs b/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/Dialogs/NewCsharpFileDialog.cs index 33bd3f2..f6d80ff 100644 --- a/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/Dialogs/NewCsharpFileDialog.cs +++ b/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/Dialogs/NewCsharpFileDialog.cs @@ -73,12 +73,13 @@ public partial class NewCsharpFileDialog : ConfirmationDialog _ = Task.GodotRun(async () => { - await _ideFileOperationsService.CreateCsFile(ParentNode, fileName); + var sharpIdeFile = await _ideFileOperationsService.CreateCsFile(ParentNode, fileName); + GodotGlobalEvents.Instance.FileExternallySelected.InvokeParallelFireAndForget(sharpIdeFile, null); }); QueueFree(); } - private bool IsNameInvalid(string name) + private static bool IsNameInvalid(string name) { return string.IsNullOrWhiteSpace(name); } diff --git a/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/FileContextMenu.cs b/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/FileContextMenu.cs index 0422111..190a104 100644 --- a/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/FileContextMenu.cs +++ b/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/FileContextMenu.cs @@ -43,7 +43,7 @@ public partial class SolutionExplorerPanel } else if (actionId is FileContextMenuOptions.Delete) { - var confirmedTcs = new TaskCompletionSource(); + var confirmedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var confirmationDialog = new ConfirmationDialog(); confirmationDialog.Title = "Delete"; confirmationDialog.DialogText = $"Delete '{file.Name}' file?"; diff --git a/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/FolderContextMenu.cs b/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/FolderContextMenu.cs index 85b6f68..ee610a4 100644 --- a/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/FolderContextMenu.cs +++ b/src/SharpIDE.Godot/Features/SolutionExplorer/ContextMenus/FolderContextMenu.cs @@ -45,7 +45,7 @@ public partial class SolutionExplorerPanel } else if (actionId is FolderContextMenuOptions.Delete) { - var confirmedTcs = new TaskCompletionSource(); + var confirmedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var confirmationDialog = new ConfirmationDialog(); confirmationDialog.Title = "Delete"; confirmationDialog.DialogText = $"Delete '{folder.Name}' file?";