diff --git a/src/SharpIDE.Application/Features/FileWatching/IdeFileExternalChangeHandler.cs b/src/SharpIDE.Application/Features/FileWatching/IdeFileExternalChangeHandler.cs index 96d00f1..22a3cd9 100644 --- a/src/SharpIDE.Application/Features/FileWatching/IdeFileExternalChangeHandler.cs +++ b/src/SharpIDE.Application/Features/FileWatching/IdeFileExternalChangeHandler.cs @@ -17,6 +17,17 @@ public class IdeFileExternalChangeHandler GlobalEvents.Instance.FileSystemWatcherInternal.FileChanged.Subscribe(OnFileChanged); GlobalEvents.Instance.FileSystemWatcherInternal.FileCreated.Subscribe(OnFileCreated); GlobalEvents.Instance.FileSystemWatcherInternal.DirectoryCreated.Subscribe(OnFolderCreated); + GlobalEvents.Instance.FileSystemWatcherInternal.DirectoryDeleted.Subscribe(OnFolderDeleted); + } + + private async Task OnFolderDeleted(string folderPath) + { + var sharpIdeFolder = SolutionModel.AllFolders.SingleOrDefault(f => f.Path == folderPath); + if (sharpIdeFolder is null) + { + return; + } + await _sharpIdeSolutionModificationService.RemoveDirectory(sharpIdeFolder); } private async Task OnFolderCreated(string folderPath) diff --git a/src/SharpIDE.Application/Features/FileWatching/IdeFileWatcher.cs b/src/SharpIDE.Application/Features/FileWatching/IdeFileWatcher.cs index 8809f89..2708383 100644 --- a/src/SharpIDE.Application/Features/FileWatching/IdeFileWatcher.cs +++ b/src/SharpIDE.Application/Features/FileWatching/IdeFileWatcher.cs @@ -68,7 +68,16 @@ public sealed class IdeFileWatcher : IDisposable private void HandleDeleted(string fullPath) { - Console.WriteLine($"FileSystemWatcher: Deleted - {fullPath}"); + var isDirectory = Path.HasExtension(fullPath) is false; + if (isDirectory) + { + GlobalEvents.Instance.FileSystemWatcherInternal.DirectoryDeleted.InvokeParallelFireAndForget(fullPath); + } + else + { + GlobalEvents.Instance.FileSystemWatcherInternal.FileDeleted.InvokeParallelFireAndForget(fullPath); + } + //Console.WriteLine($"FileSystemWatcher: Deleted - {fullPath}"); } private void HandleCreated(string fullPath) diff --git a/src/SharpIDE.Application/Features/FileWatching/SharpIdeSolutionModificationService.cs b/src/SharpIDE.Application/Features/FileWatching/SharpIdeSolutionModificationService.cs index ee704ce..df69956 100644 --- a/src/SharpIDE.Application/Features/FileWatching/SharpIdeSolutionModificationService.cs +++ b/src/SharpIDE.Application/Features/FileWatching/SharpIdeSolutionModificationService.cs @@ -3,6 +3,7 @@ using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence; namespace SharpIDE.Application.Features.FileWatching; +/// Does not do any file system operations, only modifies the in-memory solution model public class SharpIdeSolutionModificationService { public SharpIdeSolutionModel SolutionModel { get; set; } = null!;