add services
This commit is contained in:
@@ -8,10 +8,12 @@ namespace SharpIDE.Application.Features.FileWatching;
|
||||
public class IdeFileExternalChangeHandler
|
||||
{
|
||||
private readonly FileChangedService _fileChangedService;
|
||||
private readonly SharpIdeSolutionModificationService _sharpIdeSolutionModificationService;
|
||||
public SharpIdeSolutionModel SolutionModel { get; set; } = null!;
|
||||
public IdeFileExternalChangeHandler(FileChangedService fileChangedService)
|
||||
public IdeFileExternalChangeHandler(FileChangedService fileChangedService, SharpIdeSolutionModificationService sharpIdeSolutionModificationService)
|
||||
{
|
||||
_fileChangedService = fileChangedService;
|
||||
_sharpIdeSolutionModificationService = sharpIdeSolutionModificationService;
|
||||
GlobalEvents.Instance.FileSystemWatcherInternal.FileChanged.Subscribe(OnFileChanged);
|
||||
GlobalEvents.Instance.FileSystemWatcherInternal.FileCreated.Subscribe(OnFileCreated);
|
||||
GlobalEvents.Instance.FileSystemWatcherInternal.DirectoryCreated.Subscribe(OnFolderCreated);
|
||||
@@ -32,10 +34,7 @@ public class IdeFileExternalChangeHandler
|
||||
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);
|
||||
await _sharpIdeSolutionModificationService.CreateDirectory(containingFolder, folderPath);
|
||||
}
|
||||
|
||||
private async Task OnFileCreated(string filePath)
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using SharpIDE.Application.Features.SolutionDiscovery;
|
||||
|
||||
namespace SharpIDE.Application.Features.FileWatching;
|
||||
|
||||
public class IdeFileOperationsService(SharpIdeSolutionModificationService sharpIdeSolutionModificationService)
|
||||
{
|
||||
private readonly SharpIdeSolutionModificationService _sharpIdeSolutionModificationService = sharpIdeSolutionModificationService;
|
||||
|
||||
public async Task CreateDirectory(SharpIdeFolder parentFolder, string directoryPath)
|
||||
{
|
||||
var newFolder = await _sharpIdeSolutionModificationService.CreateDirectory(parentFolder, directoryPath);
|
||||
Directory.CreateDirectory(directoryPath);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using SharpIDE.Application.Features.SolutionDiscovery;
|
||||
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
|
||||
|
||||
namespace SharpIDE.Application.Features.FileWatching;
|
||||
|
||||
public class SharpIdeSolutionModificationService
|
||||
{
|
||||
public SharpIdeSolutionModel SolutionModel { get; set; } = null!;
|
||||
|
||||
public async Task<SharpIdeFolder> CreateDirectory(SharpIdeFolder parentFolder, string directoryPath)
|
||||
{
|
||||
// Passing [] to allFiles and allFolders, as we assume that a brand new folder has no subfolders or files yet
|
||||
var sharpIdeFolder = new SharpIdeFolder(new DirectoryInfo(directoryPath), parentFolder, [], []);
|
||||
parentFolder.Folders.Add(sharpIdeFolder);
|
||||
SolutionModel.AllFolders.Add(sharpIdeFolder);
|
||||
return sharpIdeFolder;
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,8 @@ public partial class DiAutoload : Node
|
||||
services.AddScoped<IdeFileWatcher>();
|
||||
services.AddScoped<IdeOpenTabsFileManager>();
|
||||
services.AddScoped<RoslynAnalysis>();
|
||||
services.AddScoped<IdeFileOperationsService>();
|
||||
services.AddScoped<SharpIdeSolutionModificationService>();
|
||||
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
GetTree().NodeAdded += OnNodeAdded;
|
||||
|
||||
Reference in New Issue
Block a user