handle files from added directories better (?)
This commit is contained in:
@@ -53,25 +53,25 @@ public class IdeFileExternalChangeHandler
|
||||
{
|
||||
// Create a new sharpIdeFile, update SolutionModel
|
||||
var sharpIdeFile = SolutionModel.AllFiles.SingleOrDefault(f => f.Path == filePath);
|
||||
if (sharpIdeFile == null)
|
||||
if (sharpIdeFile is not null)
|
||||
{
|
||||
// If sharpIdeFile is null, it means the file was created externally, and we need to create it and add it to the solution model
|
||||
var createdFileDirectory = Path.GetDirectoryName(filePath)!;
|
||||
|
||||
// TODO: Handle being contained by a project directly
|
||||
//var containingProject = SolutionModel.AllProjects.SingleOrDefault(p => createdFileDirectory == Path.GetDirectoryName(p.FilePath));
|
||||
var containingFolder = SolutionModel.AllFolders.SingleOrDefault(f => f.Path == createdFileDirectory);
|
||||
if (containingFolder is null)
|
||||
{
|
||||
// TODO: Create the folder and add it to the solution model
|
||||
}
|
||||
|
||||
sharpIdeFile = new SharpIdeFile(filePath, Path.GetFileName(filePath), containingFolder, []);
|
||||
containingFolder.Files.Add(sharpIdeFile);
|
||||
SolutionModel.AllFiles.Add(sharpIdeFile);
|
||||
// sharpIdeFile = TODO;
|
||||
// It was likely already created via a parent folder creation
|
||||
return;
|
||||
}
|
||||
Guard.Against.Null(sharpIdeFile, nameof(sharpIdeFile));
|
||||
// If sharpIdeFile is null, it means the file was created externally, and we need to create it and add it to the solution model
|
||||
var createdFileDirectory = Path.GetDirectoryName(filePath)!;
|
||||
|
||||
var containingFolderOrProject = (IFolderOrProject?)SolutionModel.AllFolders.SingleOrDefault(f => f.Path == createdFileDirectory) ?? SolutionModel.AllProjects.SingleOrDefault(s => s.FilePath == createdFileDirectory);
|
||||
if (containingFolderOrProject is null)
|
||||
{
|
||||
Console.WriteLine($"Error - Containing Folder or Project of {filePath} does not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
sharpIdeFile = new SharpIdeFile(filePath, Path.GetFileName(filePath), containingFolderOrProject, []);
|
||||
containingFolderOrProject.Files.Add(sharpIdeFile);
|
||||
SolutionModel.AllFiles.Add(sharpIdeFile);
|
||||
|
||||
await _fileChangedService.SharpIdeFileAdded(sharpIdeFile, await File.ReadAllTextAsync(filePath));
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,10 @@ public class SharpIdeSolutionModificationService(FileChangedService fileChangedS
|
||||
parentFolder.Folders.Add(sharpIdeFolder);
|
||||
SolutionModel.AllFolders.AddRange((IEnumerable<SharpIdeFolder>)[sharpIdeFolder, ..allFolders]);
|
||||
SolutionModel.AllFiles.AddRange(allFiles);
|
||||
foreach (var file in allFiles)
|
||||
{
|
||||
await _fileChangedService.SharpIdeFileAdded(file, await File.ReadAllTextAsync(file.Path));
|
||||
}
|
||||
return sharpIdeFolder;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ public interface IExpandableSharpIdeNode
|
||||
public bool Expanded { get; set; }
|
||||
}
|
||||
|
||||
public interface IFolderOrProject
|
||||
public interface IFolderOrProject : IExpandableSharpIdeNode
|
||||
{
|
||||
public ObservableHashSet<SharpIdeFolder> Folders { get; init; }
|
||||
public ObservableHashSet<SharpIdeFile> Files { get; init; }
|
||||
@@ -84,12 +84,12 @@ public class SharpIdeSolutionFolder : ISharpIdeNode, IExpandableSharpIdeNode, IC
|
||||
Projects = new ObservableHashSet<SharpIdeProjectModel>(intermediateModel.Projects.Select(x => new SharpIdeProjectModel(x, allProjects, allFiles, allFolders, this)));
|
||||
}
|
||||
}
|
||||
public class SharpIdeProjectModel : ISharpIdeNode, IExpandableSharpIdeNode, IChildSharpIdeNode
|
||||
public class SharpIdeProjectModel : ISharpIdeNode, IExpandableSharpIdeNode, IChildSharpIdeNode, IFolderOrProject
|
||||
{
|
||||
public required string Name { get; set; }
|
||||
public required string FilePath { get; set; }
|
||||
public required ObservableHashSet<SharpIdeFolder> Folders { get; set; }
|
||||
public required ObservableHashSet<SharpIdeFile> Files { get; set; }
|
||||
public required ObservableHashSet<SharpIdeFolder> Folders { get; init; }
|
||||
public required ObservableHashSet<SharpIdeFile> Files { get; init; }
|
||||
public bool Expanded { get; set; }
|
||||
public required IExpandableSharpIdeNode Parent { get; set; }
|
||||
public bool Running { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user