set selected file on sln explorer click

This commit is contained in:
Matt Parker
2025-08-27 18:43:06 +10:00
parent bb03c57df8
commit a8bc6cbe05
4 changed files with 40 additions and 3 deletions

View File

@@ -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>(T value) : GodotObject where T : class
// {
// public T Value { get; init; } = value;
// }

View File

@@ -0,0 +1 @@
uid://dixmfygdn8ogt

View File

@@ -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>("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<SharpIdeFileGodotContainer?>();
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);
}

View File

@@ -38,6 +38,7 @@ public partial class IdeRoot : Control
_sharpIdeCodeEdit = GetNode<SharpIdeCodeEdit>("%SharpIdeCodeEdit");
_fileDialog = GetNode<FileDialog>("%OpenSolutionDialog");
_solutionExplorerPanel = GetNode<SolutionExplorerPanel>("%SolutionExplorerPanel");
_solutionExplorerPanel.FileSelected += OnSolutionExplorerPanelOnFileSelected;
_fileDialog.FileSelected += OnFileSelected;
_runPanel = GetNode<RunPanel>("%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 () =>