From a8bc6cbe054e50b9c2d9d8649003eaa89b41036c Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Wed, 27 Aug 2025 18:43:06 +1000 Subject: [PATCH] set selected file on sln explorer click --- .../SharpIdeFileGodotContainer.cs | 14 ++++++++++++ .../SharpIdeFileGodotContainer.cs.uid | 1 + .../SolutionExplorer/SolutionExplorerPanel.cs | 22 ++++++++++++++++--- src/SharpIDE.Godot/IdeRoot.cs | 6 +++++ 4 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 src/SharpIDE.Godot/Features/SolutionExplorer/SharpIdeFileGodotContainer.cs create mode 100644 src/SharpIDE.Godot/Features/SolutionExplorer/SharpIdeFileGodotContainer.cs.uid diff --git a/src/SharpIDE.Godot/Features/SolutionExplorer/SharpIdeFileGodotContainer.cs b/src/SharpIDE.Godot/Features/SolutionExplorer/SharpIdeFileGodotContainer.cs new file mode 100644 index 0000000..25c96e8 --- /dev/null +++ b/src/SharpIDE.Godot/Features/SolutionExplorer/SharpIdeFileGodotContainer.cs @@ -0,0 +1,14 @@ +using Godot; +using SharpIDE.Application.Features.SolutionDiscovery; + +namespace SharpIDE.Godot.Features.SolutionExplorer; + +public partial class SharpIdeFileGodotContainer : GodotObject +{ + public required SharpIdeFile File { get; init; } +} + +// public partial class GodotContainer(T value) : GodotObject where T : class +// { +// public T Value { get; init; } = value; +// } \ No newline at end of file diff --git a/src/SharpIDE.Godot/Features/SolutionExplorer/SharpIdeFileGodotContainer.cs.uid b/src/SharpIDE.Godot/Features/SolutionExplorer/SharpIdeFileGodotContainer.cs.uid new file mode 100644 index 0000000..3123d61 --- /dev/null +++ b/src/SharpIDE.Godot/Features/SolutionExplorer/SharpIdeFileGodotContainer.cs.uid @@ -0,0 +1 @@ +uid://dixmfygdn8ogt diff --git a/src/SharpIDE.Godot/Features/SolutionExplorer/SolutionExplorerPanel.cs b/src/SharpIDE.Godot/Features/SolutionExplorer/SolutionExplorerPanel.cs index 5261aa1..1143017 100644 --- a/src/SharpIDE.Godot/Features/SolutionExplorer/SolutionExplorerPanel.cs +++ b/src/SharpIDE.Godot/Features/SolutionExplorer/SolutionExplorerPanel.cs @@ -1,3 +1,4 @@ +using Ardalis.GuardClauses; using Godot; using SharpIDE.Application.Features.SolutionDiscovery; using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence; @@ -6,15 +7,28 @@ namespace SharpIDE.Godot.Features.SolutionExplorer; public partial class SolutionExplorerPanel : Panel { + [Signal] + public delegate void FileSelectedEventHandler(SharpIdeFileGodotContainer file); + public SharpIdeSolutionModel SolutionModel { get; set; } = null!; private Tree _tree = null!; public override void _Ready() { _tree = GetNode("Tree"); - var item = _tree.CreateItem(); - item.SetText(0, "Solution Explorer"); + _tree.ItemMouseSelected += TreeOnItemMouseSelected; } - + + private void TreeOnItemMouseSelected(Vector2 mousePosition, long mouseButtonIndex) + { + var selected = _tree.GetSelected(); + if (selected is null) return; + var sharpIdeFileContainer = selected.GetMetadata(0).As(); + if (sharpIdeFileContainer is null) return; + var sharpIdeFile = sharpIdeFileContainer.File; + Guard.Against.Null(sharpIdeFile, nameof(sharpIdeFile)); + EmitSignalFileSelected(sharpIdeFileContainer); + } + public void RepopulateTree() { _tree.Clear(); @@ -92,6 +106,8 @@ public partial class SolutionExplorerPanel : Panel { var fileItem = _tree.CreateItem(parent); fileItem.SetText(0, file.Name); + var container = new SharpIdeFileGodotContainer { File = file }; + fileItem.SetMetadata(0, container); } diff --git a/src/SharpIDE.Godot/IdeRoot.cs b/src/SharpIDE.Godot/IdeRoot.cs index 85806e2..0c1f7dc 100644 --- a/src/SharpIDE.Godot/IdeRoot.cs +++ b/src/SharpIDE.Godot/IdeRoot.cs @@ -38,6 +38,7 @@ public partial class IdeRoot : Control _sharpIdeCodeEdit = GetNode("%SharpIdeCodeEdit"); _fileDialog = GetNode("%OpenSolutionDialog"); _solutionExplorerPanel = GetNode("%SolutionExplorerPanel"); + _solutionExplorerPanel.FileSelected += OnSolutionExplorerPanelOnFileSelected; _fileDialog.FileSelected += OnFileSelected; _runPanel = GetNode("%RunPanel"); _openSlnButton.Pressed += () => _fileDialog.Visible = true; @@ -45,6 +46,11 @@ public partial class IdeRoot : Control OnFileSelected(@"C:\Users\Matthew\Documents\Git\BlazorCodeBreaker\BlazorCodeBreaker.slnx"); } + private async void OnSolutionExplorerPanelOnFileSelected(SharpIdeFileGodotContainer file) + { + await _sharpIdeCodeEdit.SetSharpIdeFile(file.File); + } + private void OnFileSelected(string path) { _ = GodotTask.Run(async () =>