convert to tabs
This commit is contained in:
@@ -5,21 +5,21 @@ namespace SharpIDE.Godot.Features.Nuget;
|
|||||||
|
|
||||||
public static class ImageTextureHelper
|
public static class ImageTextureHelper
|
||||||
{
|
{
|
||||||
public static ImageTexture? GetImageTextureFromBytes(byte[]? imageBytes, NugetPackageIconFormat? format)
|
public static ImageTexture? GetImageTextureFromBytes(byte[]? imageBytes, NugetPackageIconFormat? format)
|
||||||
{
|
{
|
||||||
if (imageBytes is null || format is null) return null;
|
if (imageBytes is null || format is null) return null;
|
||||||
var image = new Image();
|
var image = new Image();
|
||||||
var error = format switch
|
var error = format switch
|
||||||
{
|
{
|
||||||
NugetPackageIconFormat.Png => image.LoadPngFromBuffer(imageBytes),
|
NugetPackageIconFormat.Png => image.LoadPngFromBuffer(imageBytes),
|
||||||
NugetPackageIconFormat.Jpg => image.LoadJpgFromBuffer(imageBytes),
|
NugetPackageIconFormat.Jpg => image.LoadJpgFromBuffer(imageBytes),
|
||||||
_ => Error.FileUnrecognized
|
_ => Error.FileUnrecognized
|
||||||
};
|
};
|
||||||
if (error is Error.Ok)
|
if (error is Error.Ok)
|
||||||
{
|
{
|
||||||
image.Resize(32, 32, Image.Interpolation.Lanczos); // Probably should cache resized images instead
|
image.Resize(32, 32, Image.Interpolation.Lanczos); // Probably should cache resized images instead
|
||||||
return ImageTexture.CreateFromImage(image);
|
return ImageTexture.CreateFromImage(image);
|
||||||
}
|
}
|
||||||
return null!;
|
return null!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,71 +6,71 @@ namespace SharpIDE.Godot.Features.Nuget;
|
|||||||
|
|
||||||
public partial class NugetPackageDetails : VBoxContainer
|
public partial class NugetPackageDetails : VBoxContainer
|
||||||
{
|
{
|
||||||
private TextureRect _packageIconTextureRect = null!;
|
private TextureRect _packageIconTextureRect = null!;
|
||||||
private Label _packageNameLabel = null!;
|
private Label _packageNameLabel = null!;
|
||||||
private OptionButton _versionOptionButton = null!;
|
private OptionButton _versionOptionButton = null!;
|
||||||
private OptionButton _nugetSourceOptionButton = null!;
|
private OptionButton _nugetSourceOptionButton = null!;
|
||||||
|
|
||||||
private IdePackageResult? _package;
|
private IdePackageResult? _package;
|
||||||
|
|
||||||
private readonly Texture2D _defaultIconTextureRect = ResourceLoader.Load<Texture2D>("uid://b5ih61vdjv5e6");
|
private readonly Texture2D _defaultIconTextureRect = ResourceLoader.Load<Texture2D>("uid://b5ih61vdjv5e6");
|
||||||
private readonly Texture2D _warningIconTextureRect = ResourceLoader.Load<Texture2D>("uid://pd3h5qfjn8pb");
|
private readonly Texture2D _warningIconTextureRect = ResourceLoader.Load<Texture2D>("uid://pd3h5qfjn8pb");
|
||||||
|
|
||||||
[Inject] private readonly NugetPackageIconCacheService _nugetPackageIconCacheService = null!;
|
[Inject] private readonly NugetPackageIconCacheService _nugetPackageIconCacheService = null!;
|
||||||
[Inject] private readonly NugetClientService _nugetClientService = null!;
|
[Inject] private readonly NugetClientService _nugetClientService = null!;
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_packageIconTextureRect = GetNode<TextureRect>("%PackageIconTextureRect");
|
_packageIconTextureRect = GetNode<TextureRect>("%PackageIconTextureRect");
|
||||||
_packageNameLabel = GetNode<Label>("%PackageNameLabel");
|
_packageNameLabel = GetNode<Label>("%PackageNameLabel");
|
||||||
_versionOptionButton = GetNode<OptionButton>("%VersionOptionButton");
|
_versionOptionButton = GetNode<OptionButton>("%VersionOptionButton");
|
||||||
_nugetSourceOptionButton = GetNode<OptionButton>("%NugetSourceOptionButton");
|
_nugetSourceOptionButton = GetNode<OptionButton>("%NugetSourceOptionButton");
|
||||||
_nugetSourceOptionButton.ItemSelected += OnNugetSourceSelected;
|
_nugetSourceOptionButton.ItemSelected += OnNugetSourceSelected;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetPackage(IdePackageResult package)
|
public async Task SetPackage(IdePackageResult package)
|
||||||
{
|
{
|
||||||
_package = package;
|
_package = package;
|
||||||
var iconTask = _nugetPackageIconCacheService.GetNugetPackageIcon(_package.PackageId, _package.PackageFromSources.First().PackageSearchMetadata.IconUrl);
|
var iconTask = _nugetPackageIconCacheService.GetNugetPackageIcon(_package.PackageId, _package.PackageFromSources.First().PackageSearchMetadata.IconUrl);
|
||||||
await this.InvokeAsync(() =>
|
await this.InvokeAsync(() =>
|
||||||
{
|
{
|
||||||
_packageNameLabel.Text = package.PackageId;
|
_packageNameLabel.Text = package.PackageId;
|
||||||
Visible = true;
|
Visible = true;
|
||||||
});
|
});
|
||||||
var (iconBytes, iconFormat) = await iconTask;
|
var (iconBytes, iconFormat) = await iconTask;
|
||||||
var imageTexture = ImageTextureHelper.GetImageTextureFromBytes(iconBytes, iconFormat) ?? _defaultIconTextureRect;
|
var imageTexture = ImageTextureHelper.GetImageTextureFromBytes(iconBytes, iconFormat) ?? _defaultIconTextureRect;
|
||||||
await this.InvokeAsync(() =>
|
await this.InvokeAsync(() =>
|
||||||
{
|
{
|
||||||
_packageIconTextureRect.Texture = imageTexture;
|
_packageIconTextureRect.Texture = imageTexture;
|
||||||
|
|
||||||
_versionOptionButton.Clear();
|
_versionOptionButton.Clear();
|
||||||
_nugetSourceOptionButton.Clear();
|
_nugetSourceOptionButton.Clear();
|
||||||
foreach (var packageFromSource in package.PackageFromSources)
|
foreach (var packageFromSource in package.PackageFromSources)
|
||||||
{
|
{
|
||||||
_nugetSourceOptionButton.AddItem(packageFromSource.Source.Name);
|
_nugetSourceOptionButton.AddItem(packageFromSource.Source.Name);
|
||||||
}
|
}
|
||||||
_nugetSourceOptionButton.Selected = 0;
|
_nugetSourceOptionButton.Selected = 0;
|
||||||
OnNugetSourceSelected(0);
|
OnNugetSourceSelected(0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetProjects(HashSet<SharpIdeProjectModel> projects)
|
public async Task SetProjects(HashSet<SharpIdeProjectModel> projects)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void OnNugetSourceSelected(long sourceIndex)
|
private async void OnNugetSourceSelected(long sourceIndex)
|
||||||
{
|
{
|
||||||
var source = _package!.PackageFromSources[(int)sourceIndex];
|
var source = _package!.PackageFromSources[(int)sourceIndex];
|
||||||
var results = await _nugetClientService.GetAllVersionsOfPackageInSource(source.PackageSearchMetadata.Identity.Id, source.Source);
|
var results = await _nugetClientService.GetAllVersionsOfPackageInSource(source.PackageSearchMetadata.Identity.Id, source.Source);
|
||||||
await this.InvokeAsync(() =>
|
await this.InvokeAsync(() =>
|
||||||
{
|
{
|
||||||
_versionOptionButton.Clear();
|
_versionOptionButton.Clear();
|
||||||
foreach (var (index, metadata) in results.Index())
|
foreach (var (index, metadata) in results.Index())
|
||||||
{
|
{
|
||||||
_versionOptionButton.AddItem(metadata.Identity.Version.ToNormalizedString());
|
_versionOptionButton.AddItem(metadata.Identity.Version.ToNormalizedString());
|
||||||
//_versionOptionButton.SetItemIcon(index, _warningIconTextureRect);
|
//_versionOptionButton.SetItemIcon(index, _warningIconTextureRect);
|
||||||
}
|
}
|
||||||
_versionOptionButton.Selected = 0;
|
_versionOptionButton.Selected = 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,156 +7,156 @@ namespace SharpIDE.Godot.Features.Nuget;
|
|||||||
|
|
||||||
public partial class NugetPanel : Control
|
public partial class NugetPanel : Control
|
||||||
{
|
{
|
||||||
private VBoxContainer _installedPackagesVboxContainer = null!;
|
private VBoxContainer _installedPackagesVboxContainer = null!;
|
||||||
private VBoxContainer _implicitlyInstalledPackagesItemList = null!;
|
private VBoxContainer _implicitlyInstalledPackagesItemList = null!;
|
||||||
private VBoxContainer _availablePackagesItemList = null!;
|
private VBoxContainer _availablePackagesItemList = null!;
|
||||||
private OptionButton _solutionOrProjectOptionButton = null!;
|
private OptionButton _solutionOrProjectOptionButton = null!;
|
||||||
|
|
||||||
private Label _installedPackagesSlnOrProjectNameLabel = null!;
|
private Label _installedPackagesSlnOrProjectNameLabel = null!;
|
||||||
private Label _installedPackagesResultCountLabel = null!;
|
private Label _installedPackagesResultCountLabel = null!;
|
||||||
private Label _implicitlyInstalledPackagesSlnOrProjectNameLabel = null!;
|
private Label _implicitlyInstalledPackagesSlnOrProjectNameLabel = null!;
|
||||||
private Label _implicitlyInstalledPackagesResultCountLabel = null!;
|
private Label _implicitlyInstalledPackagesResultCountLabel = null!;
|
||||||
|
|
||||||
private NugetPackageDetails _nugetPackageDetails = null!;
|
private NugetPackageDetails _nugetPackageDetails = null!;
|
||||||
|
|
||||||
private SharpIdeSolutionModel? _solution;
|
private SharpIdeSolutionModel? _solution;
|
||||||
|
|
||||||
[Inject] private readonly NugetClientService _nugetClientService = null!;
|
[Inject] private readonly NugetClientService _nugetClientService = null!;
|
||||||
[Inject] private readonly SharpIdeSolutionAccessor _sharpIdeSolutionAccessor;
|
[Inject] private readonly SharpIdeSolutionAccessor _sharpIdeSolutionAccessor;
|
||||||
|
|
||||||
private readonly PackedScene _packageEntryScene = ResourceLoader.Load<PackedScene>("uid://cqc2xlt81ju8s");
|
private readonly PackedScene _packageEntryScene = ResourceLoader.Load<PackedScene>("uid://cqc2xlt81ju8s");
|
||||||
private readonly Texture2D _csprojIcon = ResourceLoader.Load<Texture2D>("uid://cqt30ma6xgder");
|
private readonly Texture2D _csprojIcon = ResourceLoader.Load<Texture2D>("uid://cqt30ma6xgder");
|
||||||
|
|
||||||
private IdePackageResult? _selectedPackage;
|
private IdePackageResult? _selectedPackage;
|
||||||
// we use this to access the project for the dropdown
|
// we use this to access the project for the dropdown
|
||||||
private List<SharpIdeProjectModel?> _projects = null!;
|
private List<SharpIdeProjectModel?> _projects = null!;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_installedPackagesVboxContainer = GetNode<VBoxContainer>("%InstalledPackagesVBoxContainer");
|
_installedPackagesVboxContainer = GetNode<VBoxContainer>("%InstalledPackagesVBoxContainer");
|
||||||
_implicitlyInstalledPackagesItemList = GetNode<VBoxContainer>("%ImplicitlyInstalledPackagesVBoxContainer");
|
_implicitlyInstalledPackagesItemList = GetNode<VBoxContainer>("%ImplicitlyInstalledPackagesVBoxContainer");
|
||||||
_availablePackagesItemList = GetNode<VBoxContainer>("%AvailablePackagesVBoxContainer");
|
_availablePackagesItemList = GetNode<VBoxContainer>("%AvailablePackagesVBoxContainer");
|
||||||
_solutionOrProjectOptionButton = GetNode<OptionButton>("%SolutionOrProjectOptionButton");
|
_solutionOrProjectOptionButton = GetNode<OptionButton>("%SolutionOrProjectOptionButton");
|
||||||
_nugetPackageDetails = GetNode<NugetPackageDetails>("%NugetPackageDetails");
|
_nugetPackageDetails = GetNode<NugetPackageDetails>("%NugetPackageDetails");
|
||||||
_installedPackagesSlnOrProjectNameLabel = GetNode<Label>("%InstalledPackagesSlnOrProjectNameLabel");
|
_installedPackagesSlnOrProjectNameLabel = GetNode<Label>("%InstalledPackagesSlnOrProjectNameLabel");
|
||||||
_installedPackagesResultCountLabel = GetNode<Label>("%InstalledPackagesResultCountLabel");
|
_installedPackagesResultCountLabel = GetNode<Label>("%InstalledPackagesResultCountLabel");
|
||||||
_implicitlyInstalledPackagesSlnOrProjectNameLabel = GetNode<Label>("%ImplicitlyInstalledPackagesSlnOrProjectNameLabel");
|
_implicitlyInstalledPackagesSlnOrProjectNameLabel = GetNode<Label>("%ImplicitlyInstalledPackagesSlnOrProjectNameLabel");
|
||||||
_implicitlyInstalledPackagesResultCountLabel = GetNode<Label>("%ImplicitlyInstalledPackagesResultCountLabel");
|
_implicitlyInstalledPackagesResultCountLabel = GetNode<Label>("%ImplicitlyInstalledPackagesResultCountLabel");
|
||||||
_nugetPackageDetails.Visible = false;
|
_nugetPackageDetails.Visible = false;
|
||||||
_installedPackagesVboxContainer.QueueFreeChildren();
|
_installedPackagesVboxContainer.QueueFreeChildren();
|
||||||
_implicitlyInstalledPackagesItemList.QueueFreeChildren();
|
_implicitlyInstalledPackagesItemList.QueueFreeChildren();
|
||||||
_availablePackagesItemList.QueueFreeChildren();
|
_availablePackagesItemList.QueueFreeChildren();
|
||||||
|
|
||||||
_ = Task.GodotRun(_AsyncReady);
|
_ = Task.GodotRun(_AsyncReady);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task _AsyncReady()
|
private async Task _AsyncReady()
|
||||||
{
|
{
|
||||||
await _sharpIdeSolutionAccessor.SolutionReadyTcs.Task;
|
await _sharpIdeSolutionAccessor.SolutionReadyTcs.Task;
|
||||||
_solution = _sharpIdeSolutionAccessor.SolutionModel;
|
_solution = _sharpIdeSolutionAccessor.SolutionModel;
|
||||||
_projects = [null!, .._solution!.AllProjects.OrderBy(s => s.Name)]; // So that index 0 is solution // Probably should use Item Metadata instead of this
|
_projects = [null!, .._solution!.AllProjects.OrderBy(s => s.Name)]; // So that index 0 is solution // Probably should use Item Metadata instead of this
|
||||||
await this.InvokeAsync(() =>
|
await this.InvokeAsync(() =>
|
||||||
{
|
{
|
||||||
foreach (var project in _projects.Skip(1))
|
foreach (var project in _projects.Skip(1))
|
||||||
{
|
{
|
||||||
_solutionOrProjectOptionButton.AddIconItem(_csprojIcon, project.Name);
|
_solutionOrProjectOptionButton.AddIconItem(_csprojIcon, project.Name);
|
||||||
}
|
}
|
||||||
_solutionOrProjectOptionButton.ItemSelected += OnSolutionOrProjectSelected;
|
_solutionOrProjectOptionButton.ItemSelected += OnSolutionOrProjectSelected;
|
||||||
});
|
});
|
||||||
OnSolutionOrProjectSelected(0);
|
OnSolutionOrProjectSelected(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSolutionOrProjectSelected(long index)
|
private void OnSolutionOrProjectSelected(long index)
|
||||||
{
|
{
|
||||||
var slnOrProject = (ISolutionOrProject?)_projects[(int)index] ?? _solution!;
|
var slnOrProject = (ISolutionOrProject?)_projects[(int)index] ?? _solution!;
|
||||||
_ = Task.GodotRun(async () =>
|
_ = Task.GodotRun(async () =>
|
||||||
{
|
{
|
||||||
if (_solution is null) throw new InvalidOperationException("Solution is null but should not be");
|
if (_solution is null) throw new InvalidOperationException("Solution is null but should not be");
|
||||||
_ = Task.GodotRun(() => SetSolutionOrProjectNameLabels(slnOrProject));
|
_ = Task.GodotRun(() => SetSolutionOrProjectNameLabels(slnOrProject));
|
||||||
_ = Task.GodotRun(() => SetDetailsProjects(slnOrProject));
|
_ = Task.GodotRun(() => SetDetailsProjects(slnOrProject));
|
||||||
_ = Task.GodotRun(PopulateSearchResults);
|
_ = Task.GodotRun(PopulateSearchResults);
|
||||||
_ = Task.GodotRun(PopulateInstalledPackages);
|
_ = Task.GodotRun(PopulateInstalledPackages);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task OnPackageSelected(IdePackageResult packageResult)
|
private async Task OnPackageSelected(IdePackageResult packageResult)
|
||||||
{
|
{
|
||||||
_selectedPackage = packageResult;
|
_selectedPackage = packageResult;
|
||||||
await _nugetPackageDetails.SetPackage(packageResult);
|
await _nugetPackageDetails.SetPackage(packageResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SetDetailsProjects(ISolutionOrProject slnOrProject)
|
private async Task SetDetailsProjects(ISolutionOrProject slnOrProject)
|
||||||
{
|
{
|
||||||
var projects = slnOrProject switch
|
var projects = slnOrProject switch
|
||||||
{
|
{
|
||||||
SharpIdeSolutionModel solutionModel => solutionModel.AllProjects,
|
SharpIdeSolutionModel solutionModel => solutionModel.AllProjects,
|
||||||
SharpIdeProjectModel projectModel => [projectModel],
|
SharpIdeProjectModel projectModel => [projectModel],
|
||||||
_ => throw new InvalidOperationException("Unknown solution or project type")
|
_ => throw new InvalidOperationException("Unknown solution or project type")
|
||||||
};
|
};
|
||||||
await _nugetPackageDetails.SetProjects(projects);
|
await _nugetPackageDetails.SetProjects(projects);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SetSolutionOrProjectNameLabels(ISolutionOrProject slnOrProject)
|
private async Task SetSolutionOrProjectNameLabels(ISolutionOrProject slnOrProject)
|
||||||
{
|
{
|
||||||
var text = slnOrProject switch
|
var text = slnOrProject switch
|
||||||
{
|
{
|
||||||
SharpIdeSolutionModel => "Solution",
|
SharpIdeSolutionModel => "Solution",
|
||||||
SharpIdeProjectModel projectModel => projectModel.Name,
|
SharpIdeProjectModel projectModel => projectModel.Name,
|
||||||
_ => throw new InvalidOperationException("Unknown solution or project type")
|
_ => throw new InvalidOperationException("Unknown solution or project type")
|
||||||
};
|
};
|
||||||
await this.InvokeAsync(() =>
|
await this.InvokeAsync(() =>
|
||||||
{
|
{
|
||||||
_installedPackagesSlnOrProjectNameLabel.Text = text;
|
_installedPackagesSlnOrProjectNameLabel.Text = text;
|
||||||
_implicitlyInstalledPackagesSlnOrProjectNameLabel.Text = text;
|
_implicitlyInstalledPackagesSlnOrProjectNameLabel.Text = text;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task PopulateSearchResults()
|
private async Task PopulateSearchResults()
|
||||||
{
|
{
|
||||||
var result = await _nugetClientService.GetTop100Results(_solution!.DirectoryPath);
|
var result = await _nugetClientService.GetTop100Results(_solution!.DirectoryPath);
|
||||||
var scenes = result.Select(s =>
|
var scenes = result.Select(s =>
|
||||||
{
|
{
|
||||||
var scene = _packageEntryScene.Instantiate<PackageEntry>();
|
var scene = _packageEntryScene.Instantiate<PackageEntry>();
|
||||||
scene.PackageResult = s;
|
scene.PackageResult = s;
|
||||||
scene.PackageSelected += OnPackageSelected;
|
scene.PackageSelected += OnPackageSelected;
|
||||||
return scene;
|
return scene;
|
||||||
}).ToList();
|
}).ToList();
|
||||||
await this.InvokeAsync(() =>
|
await this.InvokeAsync(() =>
|
||||||
{
|
{
|
||||||
foreach (var scene in scenes)
|
foreach (var scene in scenes)
|
||||||
{
|
{
|
||||||
_availablePackagesItemList.AddChild(scene);
|
_availablePackagesItemList.AddChild(scene);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task PopulateInstalledPackages()
|
private async Task PopulateInstalledPackages()
|
||||||
{
|
{
|
||||||
var project = _solution!.AllProjects.First(s => s.Name == "ProjectA");
|
var project = _solution!.AllProjects.First(s => s.Name == "ProjectA");
|
||||||
await project.MsBuildEvaluationProjectTask;
|
await project.MsBuildEvaluationProjectTask;
|
||||||
var installedPackages = await ProjectEvaluation.GetPackageReferencesForProject(project);
|
var installedPackages = await ProjectEvaluation.GetPackageReferencesForProject(project);
|
||||||
var idePackageResult = await _nugetClientService.GetPackagesForInstalledPackages(project.ChildNodeBasePath, installedPackages);
|
var idePackageResult = await _nugetClientService.GetPackagesForInstalledPackages(project.ChildNodeBasePath, installedPackages);
|
||||||
var scenes = idePackageResult.Select(s =>
|
var scenes = idePackageResult.Select(s =>
|
||||||
{
|
{
|
||||||
var scene = _packageEntryScene.Instantiate<PackageEntry>();
|
var scene = _packageEntryScene.Instantiate<PackageEntry>();
|
||||||
scene.PackageResult = s;
|
scene.PackageResult = s;
|
||||||
scene.PackageSelected += OnPackageSelected;
|
scene.PackageSelected += OnPackageSelected;
|
||||||
return scene;
|
return scene;
|
||||||
}).ToList();
|
}).ToList();
|
||||||
var transitiveScenes = scenes.Where(s => s.PackageResult.InstalledNugetPackageInfo!.IsTransitive).ToList();
|
var transitiveScenes = scenes.Where(s => s.PackageResult.InstalledNugetPackageInfo!.IsTransitive).ToList();
|
||||||
var directScenes = scenes.Except(transitiveScenes).ToList();
|
var directScenes = scenes.Except(transitiveScenes).ToList();
|
||||||
await this.InvokeAsync(() =>
|
await this.InvokeAsync(() =>
|
||||||
{
|
{
|
||||||
foreach (var transitiveScene in transitiveScenes)
|
foreach (var transitiveScene in transitiveScenes)
|
||||||
{
|
{
|
||||||
_implicitlyInstalledPackagesItemList.AddChild(transitiveScene);
|
_implicitlyInstalledPackagesItemList.AddChild(transitiveScene);
|
||||||
}
|
}
|
||||||
foreach (var directScene in directScenes)
|
foreach (var directScene in directScenes)
|
||||||
{
|
{
|
||||||
_installedPackagesVboxContainer.AddChild(directScene);
|
_installedPackagesVboxContainer.AddChild(directScene);
|
||||||
}
|
}
|
||||||
_installedPackagesResultCountLabel.Text = directScenes.Count.ToString();
|
_installedPackagesResultCountLabel.Text = directScenes.Count.ToString();
|
||||||
_implicitlyInstalledPackagesResultCountLabel.Text = transitiveScenes.Count.ToString();
|
_implicitlyInstalledPackagesResultCountLabel.Text = transitiveScenes.Count.ToString();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,91 +7,91 @@ namespace SharpIDE.Godot.Features.Nuget;
|
|||||||
|
|
||||||
public partial class PackageEntry : MarginContainer
|
public partial class PackageEntry : MarginContainer
|
||||||
{
|
{
|
||||||
private Button _button;
|
private Button _button;
|
||||||
private Label _packageNameLabel = null!;
|
private Label _packageNameLabel = null!;
|
||||||
private Label _installedVersionLabel = null!;
|
private Label _installedVersionLabel = null!;
|
||||||
private Label _latestVersionLabel = null!;
|
private Label _latestVersionLabel = null!;
|
||||||
private HBoxContainer _sourceNamesContainer = null!;
|
private HBoxContainer _sourceNamesContainer = null!;
|
||||||
private TextureRect _packageIconTextureRect = null!;
|
private TextureRect _packageIconTextureRect = null!;
|
||||||
|
|
||||||
private static readonly Color Source_1_Color = new Color("629655");
|
private static readonly Color Source_1_Color = new Color("629655");
|
||||||
private static readonly Color Source_2_Color = new Color("008989");
|
private static readonly Color Source_2_Color = new Color("008989");
|
||||||
private static readonly Color Source_3_Color = new Color("8d75a8");
|
private static readonly Color Source_3_Color = new Color("8d75a8");
|
||||||
private static readonly Color Source_4_Color = new Color("966a00");
|
private static readonly Color Source_4_Color = new Color("966a00");
|
||||||
private static readonly Color Source_5_Color = new Color("efaeae");
|
private static readonly Color Source_5_Color = new Color("efaeae");
|
||||||
|
|
||||||
private static readonly ImmutableArray<Color> SourceColors =
|
private static readonly ImmutableArray<Color> SourceColors =
|
||||||
[
|
[
|
||||||
Source_1_Color,
|
Source_1_Color,
|
||||||
Source_2_Color,
|
Source_2_Color,
|
||||||
Source_3_Color,
|
Source_3_Color,
|
||||||
Source_4_Color,
|
Source_4_Color,
|
||||||
Source_5_Color
|
Source_5_Color
|
||||||
];
|
];
|
||||||
|
|
||||||
public event Func<IdePackageResult, Task> PackageSelected = null!;
|
public event Func<IdePackageResult, Task> PackageSelected = null!;
|
||||||
|
|
||||||
[Inject] private readonly NugetPackageIconCacheService _nugetPackageIconCacheService = null!;
|
[Inject] private readonly NugetPackageIconCacheService _nugetPackageIconCacheService = null!;
|
||||||
|
|
||||||
public IdePackageResult PackageResult { get; set; } = null!;
|
public IdePackageResult PackageResult { get; set; } = null!;
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_button = GetNode<Button>("Button");
|
_button = GetNode<Button>("Button");
|
||||||
_packageNameLabel = GetNode<Label>("%PackageNameLabel");
|
_packageNameLabel = GetNode<Label>("%PackageNameLabel");
|
||||||
_installedVersionLabel = GetNode<Label>("%InstalledVersionLabel");
|
_installedVersionLabel = GetNode<Label>("%InstalledVersionLabel");
|
||||||
_latestVersionLabel = GetNode<Label>("%LatestVersionLabel");
|
_latestVersionLabel = GetNode<Label>("%LatestVersionLabel");
|
||||||
_sourceNamesContainer = GetNode<HBoxContainer>("%SourceNamesHBoxContainer");
|
_sourceNamesContainer = GetNode<HBoxContainer>("%SourceNamesHBoxContainer");
|
||||||
_packageIconTextureRect = GetNode<TextureRect>("%PackageIconTextureRect");
|
_packageIconTextureRect = GetNode<TextureRect>("%PackageIconTextureRect");
|
||||||
_latestVersionLabel.Text = string.Empty;
|
_latestVersionLabel.Text = string.Empty;
|
||||||
ApplyValues();
|
ApplyValues();
|
||||||
_button.Pressed += async () => await PackageSelected.Invoke(PackageResult);
|
_button.Pressed += async () => await PackageSelected.Invoke(PackageResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ApplyValues()
|
private void ApplyValues()
|
||||||
{
|
{
|
||||||
if (PackageResult is null) return;
|
if (PackageResult is null) return;
|
||||||
_packageNameLabel.Text = PackageResult.PackageId;
|
_packageNameLabel.Text = PackageResult.PackageId;
|
||||||
var installedPackagedInfo = PackageResult.InstalledNugetPackageInfo;
|
var installedPackagedInfo = PackageResult.InstalledNugetPackageInfo;
|
||||||
if (installedPackagedInfo?.DependentPackages is not null && installedPackagedInfo.IsTransitive)
|
if (installedPackagedInfo?.DependentPackages is not null && installedPackagedInfo.IsTransitive)
|
||||||
{
|
{
|
||||||
var transitiveOriginsGroupedByVersion = installedPackagedInfo.DependentPackages
|
var transitiveOriginsGroupedByVersion = installedPackagedInfo.DependentPackages
|
||||||
.GroupBy(t => t.RequestedVersion)
|
.GroupBy(t => t.RequestedVersion)
|
||||||
.Select(g => new
|
.Select(g => new
|
||||||
{
|
{
|
||||||
RequestedVersion = g.Key,
|
RequestedVersion = g.Key,
|
||||||
PackageNames = g.Select(t => t.PackageName).ToList()
|
PackageNames = g.Select(t => t.PackageName).ToList()
|
||||||
})
|
})
|
||||||
.ToList();
|
.ToList();
|
||||||
_button.TooltipText = $"""
|
_button.TooltipText = $"""
|
||||||
Implicitly Referenced Versions
|
Implicitly Referenced Versions
|
||||||
{string.Join("\n", transitiveOriginsGroupedByVersion.Select(t => $"{t.RequestedVersion.ToString("p", VersionRangeFormatter.Instance)} by {string.Join(", ", t.PackageNames)}"))}
|
{string.Join("\n", transitiveOriginsGroupedByVersion.Select(t => $"{t.RequestedVersion.ToString("p", VersionRangeFormatter.Instance)} by {string.Join(", ", t.PackageNames)}"))}
|
||||||
""";
|
""";
|
||||||
}
|
}
|
||||||
_installedVersionLabel.Text = installedPackagedInfo?.IsTransitive is true ? $"({installedPackagedInfo?.Version.ToNormalizedString()})" : installedPackagedInfo?.Version.ToNormalizedString();
|
_installedVersionLabel.Text = installedPackagedInfo?.IsTransitive is true ? $"({installedPackagedInfo?.Version.ToNormalizedString()})" : installedPackagedInfo?.Version.ToNormalizedString();
|
||||||
var highestVersionPackageFromSource = PackageResult.PackageFromSources
|
var highestVersionPackageFromSource = PackageResult.PackageFromSources
|
||||||
.MaxBy(p => p.PackageSearchMetadata.Identity.Version);
|
.MaxBy(p => p.PackageSearchMetadata.Identity.Version);
|
||||||
if (installedPackagedInfo?.Version != highestVersionPackageFromSource.PackageSearchMetadata.Identity.Version)
|
if (installedPackagedInfo?.Version != highestVersionPackageFromSource.PackageSearchMetadata.Identity.Version)
|
||||||
{
|
{
|
||||||
_latestVersionLabel.Text = highestVersionPackageFromSource.PackageSearchMetadata.Identity.Version.ToNormalizedString();
|
_latestVersionLabel.Text = highestVersionPackageFromSource.PackageSearchMetadata.Identity.Version.ToNormalizedString();
|
||||||
}
|
}
|
||||||
_sourceNamesContainer.QueueFreeChildren();
|
_sourceNamesContainer.QueueFreeChildren();
|
||||||
|
|
||||||
_ = Task.GodotRun(async () =>
|
_ = Task.GodotRun(async () =>
|
||||||
{
|
{
|
||||||
var (iconBytes, iconFormat) = await _nugetPackageIconCacheService.GetNugetPackageIcon(PackageResult.PackageId, PackageResult.PackageFromSources.First().PackageSearchMetadata.IconUrl);
|
var (iconBytes, iconFormat) = await _nugetPackageIconCacheService.GetNugetPackageIcon(PackageResult.PackageId, PackageResult.PackageFromSources.First().PackageSearchMetadata.IconUrl);
|
||||||
var imageTexture = ImageTextureHelper.GetImageTextureFromBytes(iconBytes, iconFormat);
|
var imageTexture = ImageTextureHelper.GetImageTextureFromBytes(iconBytes, iconFormat);
|
||||||
if (imageTexture is not null)
|
if (imageTexture is not null)
|
||||||
{
|
{
|
||||||
await this.InvokeAsync(() => _packageIconTextureRect.Texture = imageTexture);
|
await this.InvokeAsync(() => _packageIconTextureRect.Texture = imageTexture);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
foreach (var (index, packageFromSource) in PackageResult.PackageFromSources.Index())
|
foreach (var (index, packageFromSource) in PackageResult.PackageFromSources.Index())
|
||||||
{
|
{
|
||||||
var label = new Label { Text = packageFromSource.Source.Name };
|
var label = new Label { Text = packageFromSource.Source.Name };
|
||||||
var labelColour = SourceColors[index % SourceColors.Length];
|
var labelColour = SourceColors[index % SourceColors.Length];
|
||||||
label.AddThemeColorOverride(ThemeStringNames.FontColor, labelColour);
|
label.AddThemeColorOverride(ThemeStringNames.FontColor, labelColour);
|
||||||
_sourceNamesContainer.AddChild(label);
|
_sourceNamesContainer.AddChild(label);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user