open new file on create
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public partial class SolutionExplorerPanel
|
||||
}
|
||||
else if (actionId is FileContextMenuOptions.Delete)
|
||||
{
|
||||
var confirmedTcs = new TaskCompletionSource<bool>();
|
||||
var confirmedTcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var confirmationDialog = new ConfirmationDialog();
|
||||
confirmationDialog.Title = "Delete";
|
||||
confirmationDialog.DialogText = $"Delete '{file.Name}' file?";
|
||||
|
||||
@@ -45,7 +45,7 @@ public partial class SolutionExplorerPanel
|
||||
}
|
||||
else if (actionId is FolderContextMenuOptions.Delete)
|
||||
{
|
||||
var confirmedTcs = new TaskCompletionSource<bool>();
|
||||
var confirmedTcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var confirmationDialog = new ConfirmationDialog();
|
||||
confirmationDialog.Title = "Delete";
|
||||
confirmationDialog.DialogText = $"Delete '{folder.Name}' file?";
|
||||
|
||||
Reference in New Issue
Block a user