generate namespace for new file
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using SharpIDE.Application.Features.SolutionDiscovery;
|
||||
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
|
||||
|
||||
namespace SharpIDE.Application.Features.FileWatching;
|
||||
|
||||
@@ -25,10 +26,11 @@ public class IdeFileOperationsService(SharpIdeSolutionModificationService sharpI
|
||||
// await _sharpIdeSolutionModificationService.RemoveFile(file);
|
||||
// }
|
||||
|
||||
public async Task CreateCsFile(SharpIdeFolder parentFolder, string newFileName, string @namespace)
|
||||
public async Task CreateCsFile(SharpIdeFolder parentFolder, string newFileName)
|
||||
{
|
||||
var newFilePath = Path.Combine(parentFolder.Path, newFileName);
|
||||
var className = Path.GetFileNameWithoutExtension(newFileName);
|
||||
var @namespace = NewFileTemplates.ComputeNamespace(parentFolder);
|
||||
var fileText = NewFileTemplates.CsharpClass(className, @namespace);
|
||||
await File.WriteAllTextAsync(newFilePath, fileText);
|
||||
await _sharpIdeSolutionModificationService.CreateFile(parentFolder, newFileName, fileText);
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
namespace SharpIDE.Application.Features.FileWatching;
|
||||
using SharpIDE.Application.Features.SolutionDiscovery;
|
||||
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
|
||||
|
||||
namespace SharpIDE.Application.Features.FileWatching;
|
||||
|
||||
public static class NewFileTemplates
|
||||
{
|
||||
@@ -14,4 +17,17 @@ public static class NewFileTemplates
|
||||
""";
|
||||
return text;
|
||||
}
|
||||
|
||||
public static string ComputeNamespace(SharpIdeFolder folder)
|
||||
{
|
||||
var names = new List<string>();
|
||||
IFolderOrProject? current = folder;
|
||||
while (current is not null)
|
||||
{
|
||||
names.Add(current.Name);
|
||||
current = current.Parent as IFolderOrProject;
|
||||
}
|
||||
names.Reverse();
|
||||
return string.Join('.', names);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,11 @@ public interface IExpandableSharpIdeNode
|
||||
public bool Expanded { get; set; }
|
||||
}
|
||||
|
||||
public interface IFolderOrProject : IExpandableSharpIdeNode
|
||||
public interface IFolderOrProject : IExpandableSharpIdeNode, IChildSharpIdeNode
|
||||
{
|
||||
public ObservableHashSet<SharpIdeFolder> Folders { get; init; }
|
||||
public ObservableHashSet<SharpIdeFile> Files { get; init; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
public interface IChildSharpIdeNode
|
||||
{
|
||||
|
||||
@@ -72,7 +72,7 @@ public partial class NewCsharpFileDialog : ConfirmationDialog
|
||||
|
||||
_ = Task.GodotRun(async () =>
|
||||
{
|
||||
await _ideFileOperationsService.CreateCsFile(ParentFolder, fileName, "asdf");
|
||||
await _ideFileOperationsService.CreateCsFile(ParentFolder, fileName);
|
||||
});
|
||||
QueueFree();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user