Create cs file v2
This commit is contained in:
@@ -18,4 +18,19 @@ public class IdeFileOperationsService(SharpIdeSolutionModificationService sharpI
|
|||||||
Directory.Delete(folder.Path, true);
|
Directory.Delete(folder.Path, true);
|
||||||
await _sharpIdeSolutionModificationService.RemoveDirectory(folder);
|
await _sharpIdeSolutionModificationService.RemoveDirectory(folder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public async Task DeleteFile(SharpIdeFile file)
|
||||||
|
// {
|
||||||
|
// File.Delete(file.Path);
|
||||||
|
// await _sharpIdeSolutionModificationService.RemoveFile(file);
|
||||||
|
// }
|
||||||
|
|
||||||
|
public async Task CreateCsFile(SharpIdeFolder parentFolder, string newFileName, string @namespace)
|
||||||
|
{
|
||||||
|
var newFilePath = Path.Combine(parentFolder.Path, newFileName);
|
||||||
|
var className = Path.GetFileNameWithoutExtension(newFileName);
|
||||||
|
var fileText = NewFileTemplates.CsharpClass(className, @namespace);
|
||||||
|
await File.WriteAllTextAsync(newFilePath, fileText);
|
||||||
|
await _sharpIdeSolutionModificationService.CreateFile(parentFolder, newFileName, fileText);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
namespace SharpIDE.Application.Features.FileWatching;
|
||||||
|
|
||||||
|
public static class NewFileTemplates
|
||||||
|
{
|
||||||
|
public static string CsharpClass(string className, string @namespace)
|
||||||
|
{
|
||||||
|
var text = $$"""
|
||||||
|
namespace {{@namespace}};
|
||||||
|
|
||||||
|
public class {{className}}
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -59,4 +59,13 @@ public class SharpIdeSolutionModificationService(FileChangedService fileChangedS
|
|||||||
await _fileChangedService.SharpIdeFileRemoved(file);
|
await _fileChangedService.SharpIdeFileRemoved(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task CreateFile(SharpIdeFolder parentFolder, string fileName, string contents)
|
||||||
|
{
|
||||||
|
var newFilePath = Path.Combine(parentFolder.Path, fileName);
|
||||||
|
var sharpIdeFile = new SharpIdeFile(newFilePath, fileName, parentFolder, []);
|
||||||
|
parentFolder.Files.Add(sharpIdeFile);
|
||||||
|
SolutionModel.AllFiles.Add(sharpIdeFile);
|
||||||
|
await _fileChangedService.SharpIdeFileAdded(sharpIdeFile, contents);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public partial class NewCsharpFileDialog : ConfirmationDialog
|
|||||||
|
|
||||||
_ = Task.GodotRun(async () =>
|
_ = Task.GodotRun(async () =>
|
||||||
{
|
{
|
||||||
//await _ideFileOperationsService.CreateCSharpFile(ParentFolder, fileName);
|
await _ideFileOperationsService.CreateCsFile(ParentFolder, fileName, "asdf");
|
||||||
});
|
});
|
||||||
QueueFree();
|
QueueFree();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user