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