diff --git a/src/SharpIDE.Application/Features/FileWatching/IdeFileExternalChangeHandler.cs b/src/SharpIDE.Application/Features/FileWatching/IdeFileExternalChangeHandler.cs index 894e91e..312ff5c 100644 --- a/src/SharpIDE.Application/Features/FileWatching/IdeFileExternalChangeHandler.cs +++ b/src/SharpIDE.Application/Features/FileWatching/IdeFileExternalChangeHandler.cs @@ -8,10 +8,12 @@ namespace SharpIDE.Application.Features.FileWatching; public class IdeFileExternalChangeHandler { private readonly FileChangedService _fileChangedService; + private readonly SharpIdeSolutionModificationService _sharpIdeSolutionModificationService; public SharpIdeSolutionModel SolutionModel { get; set; } = null!; - public IdeFileExternalChangeHandler(FileChangedService fileChangedService) + public IdeFileExternalChangeHandler(FileChangedService fileChangedService, SharpIdeSolutionModificationService sharpIdeSolutionModificationService) { _fileChangedService = fileChangedService; + _sharpIdeSolutionModificationService = sharpIdeSolutionModificationService; GlobalEvents.Instance.FileSystemWatcherInternal.FileChanged.Subscribe(OnFileChanged); GlobalEvents.Instance.FileSystemWatcherInternal.FileCreated.Subscribe(OnFileCreated); GlobalEvents.Instance.FileSystemWatcherInternal.DirectoryCreated.Subscribe(OnFolderCreated); @@ -32,10 +34,7 @@ public class IdeFileExternalChangeHandler Console.WriteLine($"Error - Containing Folder of {folderPath} does not exist"); return; } - // Passing [] to allFiles and allFolders, as we assume that a brand new folder has no subfolders or files yet - sharpIdeFolder = new SharpIdeFolder(new DirectoryInfo(folderPath), containingFolder, [], []); - containingFolder.Folders.Add(sharpIdeFolder); - SolutionModel.AllFolders.Add(sharpIdeFolder); + await _sharpIdeSolutionModificationService.CreateDirectory(containingFolder, folderPath); } private async Task OnFileCreated(string filePath) diff --git a/src/SharpIDE.Application/Features/FileWatching/IdeFileOperationsService.cs b/src/SharpIDE.Application/Features/FileWatching/IdeFileOperationsService.cs new file mode 100644 index 0000000..f51a768 --- /dev/null +++ b/src/SharpIDE.Application/Features/FileWatching/IdeFileOperationsService.cs @@ -0,0 +1,14 @@ +using SharpIDE.Application.Features.SolutionDiscovery; + +namespace SharpIDE.Application.Features.FileWatching; + +public class IdeFileOperationsService(SharpIdeSolutionModificationService sharpIdeSolutionModificationService) +{ + private readonly SharpIdeSolutionModificationService _sharpIdeSolutionModificationService = sharpIdeSolutionModificationService; + + public async Task CreateDirectory(SharpIdeFolder parentFolder, string directoryPath) + { + var newFolder = await _sharpIdeSolutionModificationService.CreateDirectory(parentFolder, directoryPath); + Directory.CreateDirectory(directoryPath); + } +} diff --git a/src/SharpIDE.Application/Features/FileWatching/SharpIdeSolutionModificationService.cs b/src/SharpIDE.Application/Features/FileWatching/SharpIdeSolutionModificationService.cs new file mode 100644 index 0000000..9989ea4 --- /dev/null +++ b/src/SharpIDE.Application/Features/FileWatching/SharpIdeSolutionModificationService.cs @@ -0,0 +1,18 @@ +using SharpIDE.Application.Features.SolutionDiscovery; +using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence; + +namespace SharpIDE.Application.Features.FileWatching; + +public class SharpIdeSolutionModificationService +{ + public SharpIdeSolutionModel SolutionModel { get; set; } = null!; + + public async Task CreateDirectory(SharpIdeFolder parentFolder, string directoryPath) + { + // Passing [] to allFiles and allFolders, as we assume that a brand new folder has no subfolders or files yet + var sharpIdeFolder = new SharpIdeFolder(new DirectoryInfo(directoryPath), parentFolder, [], []); + parentFolder.Folders.Add(sharpIdeFolder); + SolutionModel.AllFolders.Add(sharpIdeFolder); + return sharpIdeFolder; + } +} diff --git a/src/SharpIDE.Godot/DiAutoload.cs b/src/SharpIDE.Godot/DiAutoload.cs index 8bb9d19..cf918be 100644 --- a/src/SharpIDE.Godot/DiAutoload.cs +++ b/src/SharpIDE.Godot/DiAutoload.cs @@ -30,6 +30,8 @@ public partial class DiAutoload : Node services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); + services.AddScoped(); _serviceProvider = services.BuildServiceProvider(); GetTree().NodeAdded += OnNodeAdded;