From 5eef6424f8ffb0b21574ec8c09ba60422994c7b2 Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Mon, 20 Oct 2025 19:00:11 +1000 Subject: [PATCH] delete directory from disk --- .../FileWatching/IdeFileExternalChangeHandler.cs | 11 +++++++++++ .../Features/FileWatching/IdeFileWatcher.cs | 11 ++++++++++- .../SharpIdeSolutionModificationService.cs | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) 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!;