From e53bde1776800c0768fff833383d391ab11e0ce3 Mon Sep 17 00:00:00 2001 From: "Matt Parker [SSW]" <61717342+MattParkerDev@users.noreply.github.com> Date: Fri, 10 Jan 2025 19:56:26 +1000 Subject: [PATCH] kinda working --- .../Features/SolutionDiscovery/Folder.cs | 5 +- .../SolutionDiscovery/GetNodesInSolution.cs | 57 +++++++++++++++++++ src/SharpIDE.Photino/Pages/Home.razor | 24 +++++--- 3 files changed, 77 insertions(+), 9 deletions(-) diff --git a/src/SharpIDE.Application/Features/SolutionDiscovery/Folder.cs b/src/SharpIDE.Application/Features/SolutionDiscovery/Folder.cs index cf8f5a7..295c6b2 100644 --- a/src/SharpIDE.Application/Features/SolutionDiscovery/Folder.cs +++ b/src/SharpIDE.Application/Features/SolutionDiscovery/Folder.cs @@ -3,8 +3,9 @@ public class Folder { public required string Name { get; set; } - public List Folders { get; set; } = []; - public List Files { get; set; } = []; + public required string FullName { get; set; } + public required Folder? ParentFolder { get; set; } + public required List Files { get; set; } = []; } public class MyFile diff --git a/src/SharpIDE.Application/Features/SolutionDiscovery/GetNodesInSolution.cs b/src/SharpIDE.Application/Features/SolutionDiscovery/GetNodesInSolution.cs index 03e9083..638dbf5 100644 --- a/src/SharpIDE.Application/Features/SolutionDiscovery/GetNodesInSolution.cs +++ b/src/SharpIDE.Application/Features/SolutionDiscovery/GetNodesInSolution.cs @@ -37,4 +37,61 @@ public static class GetNodesInSolution .ToList(); return files; } + + public static List GetFoldersInProject(string projectPath) + { + var files = GetFilesInProject(projectPath); + var rootDirectoryOfProject = new DirectoryInfo(Path.GetDirectoryName(projectPath)!); + + var grouped = files.GroupBy(s => s.Directory!.FullName); + var folders = grouped.Select(s => new Folder + { + Name = Path.GetFileName(s.Key), + FullName = s.Key, + ParentFolder = null, + Files = s.Select(f => new MyFile + { + Name = f.Name + }).ToList() + }).ToList(); + + foreach (var folder in folders) + { + var directoryInfo = new DirectoryInfo(folder.FullName); + if (directoryInfo.FullName == rootDirectoryOfProject.FullName) continue; + + var parent = directoryInfo.Parent; + try + { + var parentFolder = folders.SingleOrDefault(f => f.FullName == parent!.FullName); + folder.ParentFolder = parentFolder; + } + catch (Exception e) + { + Console.WriteLine(e); + } + } + + return folders; + } } + + + + + + + + + + + + + + + + + + + + diff --git a/src/SharpIDE.Photino/Pages/Home.razor b/src/SharpIDE.Photino/Pages/Home.razor index 3d031c4..1326910 100644 --- a/src/SharpIDE.Photino/Pages/Home.razor +++ b/src/SharpIDE.Photino/Pages/Home.razor @@ -13,7 +13,7 @@ return; } - + @foreach(var project in _rootNodes) { @GetProjectFragment(project) @@ -34,18 +34,23 @@ { @GetProjectFragment(child) } - @GetFolderFragment(project) + @GetFolderFragment(_folders.GetValueOrDefault(project.ProjectGuid, [])) ; - private RenderFragment GetFolderFragment(ProjectInSolution project) => + private RenderFragment GetFolderFragment(List folders) => @ - @foreach (var folder in _folders.GetValueOrDefault(project.ProjectGuid, [])) + @foreach (var folder in folders.Where(s => s.ParentFolder is null)) { - + + @GetFolderFragment(folders.Where(s => s.ParentFolder == folder).ToList()) + @foreach(var file in folder.Files) + { + + } } - ; + ; protected override async Task OnInitializedAsync() { @@ -55,7 +60,12 @@ var rootNodes = solutionFile.ProjectsByGuid.Values.Where(p => p.ParentProjectGuid == null).OrderBy(s => s.ProjectName).ToList(); _rootNodes = rootNodes; - + var folders2 = _solutionFile.ProjectsByGuid.Values + .Where(s => s.ProjectType == SolutionProjectType.KnownToBeMSBuildFormat) + .Take(2) + .Select(s => (s, GetNodesInSolution.GetFoldersInProject(s.AbsolutePath))) + .ToDictionary(s => s.s.ProjectGuid, s => s.Item2); + _folders = folders2; } }