From ae68b206db7217de146dfc5812ac23357a188510 Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Sun, 17 Aug 2025 16:09:43 +1000 Subject: [PATCH] select sln node in tree view externally --- .../Components/Problems/ProblemsPanel.razor | 7 ++-- .../Problems/ProjectProblemComponent.razor | 7 ++-- .../Components/SolutionExplorer.razor | 31 +++------------- src/SharpIDE.Photino/Layout/MainLayout.razor | 35 +++++++++++++++---- 4 files changed, 38 insertions(+), 42 deletions(-) diff --git a/src/SharpIDE.Photino/Components/Problems/ProblemsPanel.razor b/src/SharpIDE.Photino/Components/Problems/ProblemsPanel.razor index e6f8366..8532d5d 100644 --- a/src/SharpIDE.Photino/Components/Problems/ProblemsPanel.razor +++ b/src/SharpIDE.Photino/Components/Problems/ProblemsPanel.razor @@ -5,7 +5,7 @@ @foreach (var project in SolutionModel.AllProjects) { - + } @@ -14,9 +14,6 @@ [Parameter, EditorRequired] public SharpIdeSolutionModel SolutionModel { get; set; } = null!; - [Parameter, EditorRequired] - public SharpIdeFile SelectedFile { get; set; } = null!; - [Parameter] - public EventCallback SelectedFileChanged { get; set; } + public EventCallback OnFileSelected { get; set; } } diff --git a/src/SharpIDE.Photino/Components/Problems/ProjectProblemComponent.razor b/src/SharpIDE.Photino/Components/Problems/ProjectProblemComponent.razor index eada17e..c9df6c4 100644 --- a/src/SharpIDE.Photino/Components/Problems/ProjectProblemComponent.razor +++ b/src/SharpIDE.Photino/Components/Problems/ProjectProblemComponent.razor @@ -25,11 +25,8 @@ [Parameter, EditorRequired] public SharpIdeProjectModel ProjectModel { get; set; } = null!; - [Parameter, EditorRequired] - public SharpIdeFile SelectedFile { get; set; } = null!; - [Parameter] - public EventCallback SelectedFileChanged { get; set; } + public EventCallback OnFileSelected { get; set; } private ImmutableArray _diagnostics = []; @@ -48,7 +45,7 @@ .Concat(ProjectModel.Folders.SelectMany(f => f.GetAllFiles())) .Single(s => s.Path == diagnostic.Location.SourceTree?.GetMappedLineSpan(diagnostic.Location.SourceSpan).Path); - await SelectedFileChanged.InvokeAsync(file); + await OnFileSelected.InvokeAsync(file); } protected override async Task OnInitializedAsync() diff --git a/src/SharpIDE.Photino/Components/SolutionExplorer.razor b/src/SharpIDE.Photino/Components/SolutionExplorer.razor index 78a5c6f..ffd863c 100644 --- a/src/SharpIDE.Photino/Components/SolutionExplorer.razor +++ b/src/SharpIDE.Photino/Components/SolutionExplorer.razor @@ -18,7 +18,7 @@ } - + @foreach (var folder in SolutionModel.Folders) { @@ -44,34 +44,14 @@ public SharpIdeSolutionModel SolutionModel { get; set; } = null!; [Parameter, EditorRequired] - public SharpIdeFile SelectedFile { get; set; } = null!; + public ISharpIdeNode? SelectedNode { get; set; } = null!; [Parameter] - public EventCallback SelectedFileChanged { get; set; } + public EventCallback SelectedNodeChanged { get; set; } private MudMenu _contextMenuRef = null!; private SharpIdeProjectModel? _contextMenuProject; - - protected override async Task OnParametersSetAsync() - { - if (SelectedFile is null) return; - var parent = SelectedFile.Parent; - parent.Expanded = true; - while (parent is IChildSharpIdeNode childNode) - { - if (childNode is not IExpandableSharpIdeNode expandableNode) throw new InvalidOperationException("Parent node must implement IExpandableSharpIdeNode"); - expandableNode.Expanded = true; - parent = childNode.Parent; - } - if (parent is not SharpIdeSolutionModel solutionModel) throw new InvalidOperationException("Parent node must be a SharpIdeSolutionModel"); - solutionModel.Expanded = true; - } - - private async Task InvokeSelectedFileChanged(SharpIdeFile file) - { - SelectedFile = file; - await SelectedFileChanged.InvokeAsync(file); - } + private MudTreeView _treeViewRef = null!; private async Task OpenProjectContextMenu(MouseEventArgs args, SharpIdeProjectModel project) { @@ -147,8 +127,7 @@ private RenderFragment GetFileFragment(SharpIdeFile file) => @ - + ; - } diff --git a/src/SharpIDE.Photino/Layout/MainLayout.razor b/src/SharpIDE.Photino/Layout/MainLayout.razor index 699cabc..6eb89f3 100644 --- a/src/SharpIDE.Photino/Layout/MainLayout.razor +++ b/src/SharpIDE.Photino/Layout/MainLayout.razor @@ -1,10 +1,8 @@ -@using Microsoft.Build.Tasks -@using SharpIDE.Application.Features.Analysis +@using SharpIDE.Application.Features.Analysis @using SharpIDE.Application.Features.Build @using SharpIDE.Application.Features.Events @using SharpIDE.Application.Features.SolutionDiscovery @using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence -@using SharpIDE.Photino.Components.Problems @using SharpIDE.Photino.Models @inherits LayoutComponentBase @@ -66,7 +64,7 @@ @if (_solutionFilePath is not null) { - + }
@@ -83,7 +81,7 @@ @if (_solutionFilePath is not null) { - + @@ -107,6 +105,7 @@ private string? _solutionFilePath; private SharpIdeSolutionModel? _solutionModel; + private ISharpIdeNode? _selectedNode; private SharpIdeFile? _selectedFile; private BottomPanelType? _selectedBottomPanel = null; @@ -140,6 +139,31 @@ GlobalEvents.StartedRunningProject += OnStartedRunningProject; } + private void OnProblemSelected(SharpIdeFile file) + { + _selectedFile = file; + _selectedNode = file; + var parent = _selectedFile.Parent; + parent.Expanded = true; + while (parent is IChildSharpIdeNode childNode) + { + if (childNode is not IExpandableSharpIdeNode expandableParent) throw new InvalidOperationException("Parent node must implement IExpandableSharpIdeNode"); + expandableParent.Expanded = true; + parent = childNode.Parent; + } + if (parent is not SharpIdeSolutionModel solutionModel) throw new InvalidOperationException("Parent node must be a SharpIdeSolutionModel"); + solutionModel.Expanded = true; + StateHasChanged(); + } + + private void AfterSelectedNodeChanged() + { + if (_selectedNode is SharpIdeFile file) + { + _selectedFile = file; + } + } + private async Task OnStartedRunningProject() { SelectBottomPanel(BottomPanelType.Run); @@ -180,5 +204,4 @@ { var dialogRef = await DialogService.ShowAsync("SharpIDE Settings", new DialogOptions { MaxWidth = MaxWidth.Medium, CloseButton = true }); } - }