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);
}
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 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

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, []);
parentNode.Files.Add(sharpIdeFile);
SolutionModel.AllFiles.Add(sharpIdeFile);
await _fileChangedService.SharpIdeFileAdded(sharpIdeFile, contents);
return sharpIdeFile;
}
public async Task RemoveFile(SharpIdeFile file)