add folder to solution model on create

This commit is contained in:
Matt Parker
2025-10-19 22:56:14 +10:00
parent 45df81afe6
commit 8a02d6a519
3 changed files with 31 additions and 3 deletions

View File

@@ -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)

View File

@@ -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