open new file on create

This commit is contained in:
Matt Parker
2025-10-20 21:48:59 +10:00
parent 8ac96b3835
commit 0a913a8e26
5 changed files with 10 additions and 7 deletions

View File

@@ -26,14 +26,15 @@ public class IdeFileOperationsService(SharpIdeSolutionModificationService sharpI
await _sharpIdeSolutionModificationService.RemoveFile(file); await _sharpIdeSolutionModificationService.RemoveFile(file);
} }
public async Task CreateCsFile(IFolderOrProject parentNode, string newFileName) public async Task<SharpIdeFile> CreateCsFile(IFolderOrProject parentNode, string newFileName)
{ {
var newFilePath = Path.Combine(GetFileParentNodePath(parentNode), newFileName); var newFilePath = Path.Combine(GetFileParentNodePath(parentNode), newFileName);
var className = Path.GetFileNameWithoutExtension(newFileName); var className = Path.GetFileNameWithoutExtension(newFileName);
var @namespace = NewFileTemplates.ComputeNamespace(parentNode); var @namespace = NewFileTemplates.ComputeNamespace(parentNode);
var fileText = NewFileTemplates.CsharpClass(className, @namespace); var fileText = NewFileTemplates.CsharpClass(className, @namespace);
await File.WriteAllTextAsync(newFilePath, fileText); 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 private static string GetFileParentNodePath(IFolderOrProject parentNode) => parentNode switch

View File

@@ -60,12 +60,13 @@ public class SharpIdeSolutionModificationService(FileChangedService fileChangedS
} }
} }
public async Task CreateFile(IFolderOrProject parentNode, string newFilePath, string fileName, string contents) public async Task<SharpIdeFile> CreateFile(IFolderOrProject parentNode, string newFilePath, string fileName, string contents)
{ {
var sharpIdeFile = new SharpIdeFile(newFilePath, fileName, parentNode, []); var sharpIdeFile = new SharpIdeFile(newFilePath, fileName, parentNode, []);
parentNode.Files.Add(sharpIdeFile); parentNode.Files.Add(sharpIdeFile);
SolutionModel.AllFiles.Add(sharpIdeFile); SolutionModel.AllFiles.Add(sharpIdeFile);
await _fileChangedService.SharpIdeFileAdded(sharpIdeFile, contents); await _fileChangedService.SharpIdeFileAdded(sharpIdeFile, contents);
return sharpIdeFile;
} }
public async Task RemoveFile(SharpIdeFile file) public async Task RemoveFile(SharpIdeFile file)

View File

@@ -73,12 +73,13 @@ public partial class NewCsharpFileDialog : ConfirmationDialog
_ = Task.GodotRun(async () => _ = Task.GodotRun(async () =>
{ {
await _ideFileOperationsService.CreateCsFile(ParentNode, fileName); var sharpIdeFile = await _ideFileOperationsService.CreateCsFile(ParentNode, fileName);
GodotGlobalEvents.Instance.FileExternallySelected.InvokeParallelFireAndForget(sharpIdeFile, null);
}); });
QueueFree(); QueueFree();
} }
private bool IsNameInvalid(string name) private static bool IsNameInvalid(string name)
{ {
return string.IsNullOrWhiteSpace(name); return string.IsNullOrWhiteSpace(name);
} }

View File

@@ -43,7 +43,7 @@ public partial class SolutionExplorerPanel
} }
else if (actionId is FileContextMenuOptions.Delete) else if (actionId is FileContextMenuOptions.Delete)
{ {
var confirmedTcs = new TaskCompletionSource<bool>(); var confirmedTcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
var confirmationDialog = new ConfirmationDialog(); var confirmationDialog = new ConfirmationDialog();
confirmationDialog.Title = "Delete"; confirmationDialog.Title = "Delete";
confirmationDialog.DialogText = $"Delete '{file.Name}' file?"; confirmationDialog.DialogText = $"Delete '{file.Name}' file?";

View File

@@ -45,7 +45,7 @@ public partial class SolutionExplorerPanel
} }
else if (actionId is FolderContextMenuOptions.Delete) else if (actionId is FolderContextMenuOptions.Delete)
{ {
var confirmedTcs = new TaskCompletionSource<bool>(); var confirmedTcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
var confirmationDialog = new ConfirmationDialog(); var confirmationDialog = new ConfirmationDialog();
confirmationDialog.Title = "Delete"; confirmationDialog.Title = "Delete";
confirmationDialog.DialogText = $"Delete '{folder.Name}' file?"; confirmationDialog.DialogText = $"Delete '{folder.Name}' file?";