diff --git a/src/SharpIDE.Application/Features/FileWatching/IdeFileExternalChangeHandler.cs b/src/SharpIDE.Application/Features/FileWatching/IdeFileExternalChangeHandler.cs index 2a9bd8b..894e91e 100644 --- a/src/SharpIDE.Application/Features/FileWatching/IdeFileExternalChangeHandler.cs +++ b/src/SharpIDE.Application/Features/FileWatching/IdeFileExternalChangeHandler.cs @@ -14,6 +14,28 @@ public class IdeFileExternalChangeHandler _fileChangedService = fileChangedService; GlobalEvents.Instance.FileSystemWatcherInternal.FileChanged.Subscribe(OnFileChanged); GlobalEvents.Instance.FileSystemWatcherInternal.FileCreated.Subscribe(OnFileCreated); + GlobalEvents.Instance.FileSystemWatcherInternal.DirectoryCreated.Subscribe(OnFolderCreated); + } + + private async Task OnFolderCreated(string folderPath) + { + var sharpIdeFolder = SolutionModel.AllFolders.SingleOrDefault(f => f.Path == folderPath); + if (sharpIdeFolder is not null) + { + Console.WriteLine($"Error - Folder {folderPath} already exists"); + return; + } + var containingFolderPath = Path.GetDirectoryName(folderPath)!; + var containingFolder = SolutionModel.AllFolders.SingleOrDefault(f => f.Path == containingFolderPath); + if (containingFolder is null) + { + 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); } private async Task OnFileCreated(string filePath) diff --git a/src/SharpIDE.Application/Features/FileWatching/IdeFileWatcher.cs b/src/SharpIDE.Application/Features/FileWatching/IdeFileWatcher.cs index 0d5b59d..8809f89 100644 --- a/src/SharpIDE.Application/Features/FileWatching/IdeFileWatcher.cs +++ b/src/SharpIDE.Application/Features/FileWatching/IdeFileWatcher.cs @@ -73,9 +73,16 @@ public sealed class IdeFileWatcher : IDisposable private void HandleCreated(string fullPath) { - if (Path.HasExtension(fullPath) is false) return; // we don't care about directory changes + var isDirectory = Path.HasExtension(fullPath) is false; + if (isDirectory) + { + GlobalEvents.Instance.FileSystemWatcherInternal.DirectoryCreated.InvokeParallelFireAndForget(fullPath); + } + else + { + GlobalEvents.Instance.FileSystemWatcherInternal.FileCreated.InvokeParallelFireAndForget(fullPath); + } //Console.WriteLine($"FileSystemWatcher: Created - {fullPath}"); - GlobalEvents.Instance.FileSystemWatcherInternal.FileCreated.InvokeParallelFireAndForget(fullPath); } // The only changed event we care about is files, not directories diff --git a/src/SharpIDE.Godot/Features/Common/TreeItemContainer.cs b/src/SharpIDE.Godot/Features/Common/TreeItemContainer.cs index 5e77335..cb01708 100644 --- a/src/SharpIDE.Godot/Features/Common/TreeItemContainer.cs +++ b/src/SharpIDE.Godot/Features/Common/TreeItemContainer.cs @@ -1,7 +1,6 @@ using System.Collections.Specialized; using Godot; using ObservableCollections; -using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence; namespace SharpIDE.Godot.Features.Common;