add folder to solution model on create
This commit is contained in:
@@ -14,6 +14,28 @@ public class IdeFileExternalChangeHandler
|
|||||||
_fileChangedService = fileChangedService;
|
_fileChangedService = fileChangedService;
|
||||||
GlobalEvents.Instance.FileSystemWatcherInternal.FileChanged.Subscribe(OnFileChanged);
|
GlobalEvents.Instance.FileSystemWatcherInternal.FileChanged.Subscribe(OnFileChanged);
|
||||||
GlobalEvents.Instance.FileSystemWatcherInternal.FileCreated.Subscribe(OnFileCreated);
|
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)
|
private async Task OnFileCreated(string filePath)
|
||||||
|
|||||||
@@ -73,9 +73,16 @@ public sealed class IdeFileWatcher : IDisposable
|
|||||||
|
|
||||||
private void HandleCreated(string fullPath)
|
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}");
|
//Console.WriteLine($"FileSystemWatcher: Created - {fullPath}");
|
||||||
GlobalEvents.Instance.FileSystemWatcherInternal.FileCreated.InvokeParallelFireAndForget(fullPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The only changed event we care about is files, not directories
|
// The only changed event we care about is files, not directories
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using Godot;
|
using Godot;
|
||||||
using ObservableCollections;
|
using ObservableCollections;
|
||||||
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
|
|
||||||
|
|
||||||
namespace SharpIDE.Godot.Features.Common;
|
namespace SharpIDE.Godot.Features.Common;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user