Use generic ref counted container for metadata
This commit is contained in:
@@ -1,20 +0,0 @@
|
|||||||
using Godot;
|
|
||||||
using Microsoft.CodeAnalysis;
|
|
||||||
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
|
|
||||||
|
|
||||||
namespace SharpIDE.Godot.Features.Problems;
|
|
||||||
|
|
||||||
// public partial class GenericContainer<T>(T item) : RefCounted
|
|
||||||
// {
|
|
||||||
// public T Item { get; } = item;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public partial class DiagnosticMetadataContainer(Diagnostic diagnostic) : RefCounted
|
|
||||||
{
|
|
||||||
public Diagnostic Diagnostic { get; } = diagnostic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public partial class ProjectContainer(SharpIdeProjectModel project) : RefCounted
|
|
||||||
{
|
|
||||||
public SharpIdeProjectModel Project { get; } = project;
|
|
||||||
}
|
|
||||||
@@ -64,7 +64,7 @@ public partial class ProblemsPanel : Control
|
|||||||
var treeItem = tree.CreateItem(parent);
|
var treeItem = tree.CreateItem(parent);
|
||||||
treeItem.SetText(0, e.NewItem.Value.Name);
|
treeItem.SetText(0, e.NewItem.Value.Name);
|
||||||
treeItem.SetIcon(0, CsprojIcon);
|
treeItem.SetIcon(0, CsprojIcon);
|
||||||
treeItem.SetMetadata(0, new ProjectContainer(e.NewItem.Value));
|
treeItem.SetMetadata(0, new RefCountedContainer<SharpIdeProjectModel>(e.NewItem.Value));
|
||||||
e.NewItem.View.Value = treeItem;
|
e.NewItem.View.Value = treeItem;
|
||||||
|
|
||||||
Observable.EveryValueChanged(e.NewItem.Value, s => s.Diagnostics.Count).Subscribe(s => treeItem.Visible = s is not 0).AddTo(this);
|
Observable.EveryValueChanged(e.NewItem.Value, s => s.Diagnostics.Count).Subscribe(s => treeItem.Visible = s is not 0).AddTo(this);
|
||||||
@@ -86,7 +86,7 @@ public partial class ProblemsPanel : Control
|
|||||||
{
|
{
|
||||||
var diagItem = tree.CreateItem(parent);
|
var diagItem = tree.CreateItem(parent);
|
||||||
diagItem.SetText(0, e.NewItem.Value.GetMessage());
|
diagItem.SetText(0, e.NewItem.Value.GetMessage());
|
||||||
diagItem.SetMetadata(0, new DiagnosticMetadataContainer(e.NewItem.Value));
|
diagItem.SetMetadata(0, new RefCountedContainer<Diagnostic>(e.NewItem.Value));
|
||||||
diagItem.SetIcon(0, e.NewItem.Value.Severity switch
|
diagItem.SetIcon(0, e.NewItem.Value.Severity switch
|
||||||
{
|
{
|
||||||
DiagnosticSeverity.Error => ErrorIcon,
|
DiagnosticSeverity.Error => ErrorIcon,
|
||||||
@@ -108,13 +108,13 @@ public partial class ProblemsPanel : Control
|
|||||||
private void TreeOnItemActivated()
|
private void TreeOnItemActivated()
|
||||||
{
|
{
|
||||||
var selected = _tree.GetSelected();
|
var selected = _tree.GetSelected();
|
||||||
var diagnosticContainer = selected.GetMetadata(0).As<DiagnosticMetadataContainer?>();
|
var diagnosticContainer = selected.GetMetadata(0).As<RefCountedContainer<Diagnostic>?>();
|
||||||
if (diagnosticContainer is null) return;
|
if (diagnosticContainer is null) return;
|
||||||
var diagnostic = diagnosticContainer.Diagnostic;
|
var diagnostic = diagnosticContainer.Item;
|
||||||
var parentTreeItem = selected.GetParent();
|
var parentTreeItem = selected.GetParent();
|
||||||
var projectContainer = parentTreeItem.GetMetadata(0).As<ProjectContainer?>();
|
var projectContainer = parentTreeItem.GetMetadata(0).As<RefCountedContainer<SharpIdeProjectModel>?>();
|
||||||
if (projectContainer is null) return;
|
if (projectContainer is null) return;
|
||||||
var projectModel = projectContainer.Project;
|
var projectModel = projectContainer.Item;
|
||||||
OpenDocumentContainingDiagnostic(diagnostic, projectModel);
|
OpenDocumentContainingDiagnostic(diagnostic, projectModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
10
src/SharpIDE.Godot/Features/Problems/RefCountedContainer.cs
Normal file
10
src/SharpIDE.Godot/Features/Problems/RefCountedContainer.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using Godot;
|
||||||
|
using Microsoft.CodeAnalysis;
|
||||||
|
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
|
||||||
|
|
||||||
|
namespace SharpIDE.Godot.Features.Problems;
|
||||||
|
|
||||||
|
public partial class RefCountedContainer<T>(T item) : RefCounted
|
||||||
|
{
|
||||||
|
public T Item { get; } = item;
|
||||||
|
}
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
using Godot;
|
|
||||||
using SharpIDE.Application.Features.SolutionDiscovery;
|
|
||||||
|
|
||||||
namespace SharpIDE.Godot.Features.SolutionExplorer;
|
|
||||||
|
|
||||||
public partial class SharpIdeFileGodotContainer : RefCounted
|
|
||||||
{
|
|
||||||
public required SharpIdeFile File { get; init; }
|
|
||||||
}
|
|
||||||
|
|
||||||
// public partial class GodotContainer<T>(T value) : GodotObject where T : class
|
|
||||||
// {
|
|
||||||
// public T Value { get; init; } = value;
|
|
||||||
// }
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
uid://dixmfygdn8ogt
|
|
||||||
@@ -3,6 +3,7 @@ using Godot;
|
|||||||
using SharpIDE.Application.Features.Analysis;
|
using SharpIDE.Application.Features.Analysis;
|
||||||
using SharpIDE.Application.Features.SolutionDiscovery;
|
using SharpIDE.Application.Features.SolutionDiscovery;
|
||||||
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
|
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
|
||||||
|
using SharpIDE.Godot.Features.Problems;
|
||||||
|
|
||||||
namespace SharpIDE.Godot.Features.SolutionExplorer;
|
namespace SharpIDE.Godot.Features.SolutionExplorer;
|
||||||
|
|
||||||
@@ -32,9 +33,9 @@ public partial class SolutionExplorerPanel : MarginContainer
|
|||||||
{
|
{
|
||||||
var selected = _tree.GetSelected();
|
var selected = _tree.GetSelected();
|
||||||
if (selected is null) return;
|
if (selected is null) return;
|
||||||
var sharpIdeFileContainer = selected.GetMetadata(0).As<SharpIdeFileGodotContainer?>();
|
var sharpIdeFileContainer = selected.GetMetadata(0).As<RefCountedContainer<SharpIdeFile>?>();
|
||||||
if (sharpIdeFileContainer is null) return;
|
if (sharpIdeFileContainer is null) return;
|
||||||
var sharpIdeFile = sharpIdeFileContainer.File;
|
var sharpIdeFile = sharpIdeFileContainer.Item;
|
||||||
Guard.Against.Null(sharpIdeFile, nameof(sharpIdeFile));
|
Guard.Against.Null(sharpIdeFile, nameof(sharpIdeFile));
|
||||||
GodotGlobalEvents.Instance.InvokeFileSelected(sharpIdeFile);
|
GodotGlobalEvents.Instance.InvokeFileSelected(sharpIdeFile);
|
||||||
}
|
}
|
||||||
@@ -60,7 +61,7 @@ public partial class SolutionExplorerPanel : MarginContainer
|
|||||||
private static TreeItem? FindItemRecursive(TreeItem item, SharpIdeFile file)
|
private static TreeItem? FindItemRecursive(TreeItem item, SharpIdeFile file)
|
||||||
{
|
{
|
||||||
var metadata = item.GetMetadata(0);
|
var metadata = item.GetMetadata(0);
|
||||||
if (metadata.As<SharpIdeFileGodotContainer?>()?.File == file)
|
if (metadata.As<RefCountedContainer<SharpIdeFile>?>()?.Item == file)
|
||||||
return item;
|
return item;
|
||||||
|
|
||||||
var child = item.GetFirstChild();
|
var child = item.GetFirstChild();
|
||||||
@@ -160,7 +161,7 @@ public partial class SolutionExplorerPanel : MarginContainer
|
|||||||
var fileItem = _tree.CreateItem(parent);
|
var fileItem = _tree.CreateItem(parent);
|
||||||
fileItem.SetText(0, file.Name);
|
fileItem.SetText(0, file.Name);
|
||||||
fileItem.SetIcon(0, CsharpFileIcon);
|
fileItem.SetIcon(0, CsharpFileIcon);
|
||||||
var container = new SharpIdeFileGodotContainer { File = file };
|
var container = new RefCountedContainer<SharpIdeFile>(file);
|
||||||
fileItem.SetMetadata(0, container);
|
fileItem.SetMetadata(0, container);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user