set selected file on sln explorer click
This commit is contained in:
@@ -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;
|
||||
// }
|
||||
@@ -0,0 +1 @@
|
||||
uid://dixmfygdn8ogt
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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 () =>
|
||||
|
||||
Reference in New Issue
Block a user