using System.Collections.Generic; using System.Linq; using Semver; using UnityEngine; using UnityEngine.Experimental.UIElements; namespace UnityEditor.PackageManager.UI { #if !UNITY_2018_3_OR_NEWER internal class PackageDetailsFactory : UxmlFactory { protected override PackageDetails DoCreate(IUxmlAttributes bag, CreationContext cc) { return new PackageDetails(); } } #endif internal class PackageDetails : VisualElement { #if UNITY_2018_3_OR_NEWER internal new class UxmlFactory : UxmlFactory { } #endif private readonly VisualElement root; private Package package; private const string emptyDescriptionClass = "empty"; private List VersionItems; internal PopupField VersionPopup; private PackageInfo DisplayPackage; private PackageInfo SelectedPackage { get { return VersionPopup.value.Version != null ? VersionPopup.value.Version : null; } } internal enum PackageAction { Add, Remove, Update, Downgrade, Enable, Disable, UpToDate, Current, Local, Git, Embedded } private static readonly VersionItem EmptyVersion = new VersionItem {Version = null}; internal static readonly string[] PackageActionVerbs = { "Install", "Remove", "Update to", "Update to", "Enable", "Disable", "Up to date", "Current", "Local", "Git", "Embedded" }; internal static readonly string[] PackageActionInProgressVerbs = { "Installing", "Removing", "Updating to", "Updating to", "Enabling", "Disabling", "Up to date", "Current", "Local", "Git", "Embedded" }; public PackageDetails() { UIUtils.SetElementDisplay(this, false); root = Resources.GetTemplate("PackageDetails.uxml"); Add(root); foreach (var extension in PackageManagerExtensions.Extensions) CustomContainer.Add(extension.CreateExtensionUI()); root.StretchToParentSize(); SetUpdateVisibility(false); RemoveButton.visible = false; UpdateBuiltIn.visible = false; UpdateButton.clickable.clicked += UpdateClick; UpdateBuiltIn.clickable.clicked += UpdateClick; RemoveButton.clickable.clicked += RemoveClick; ViewDocButton.clickable.clicked += ViewDocClick; ViewChangelogButton.clickable.clicked += ViewChangelogClick; ViewLicenses.clickable.clicked += ViewLicensesClick; VersionItems = new List {EmptyVersion}; VersionPopup = new PopupField(VersionItems, 0); VersionPopup.SetLabelCallback(VersionSelectionSetLabel); VersionPopup.AddToClassList("popup"); VersionPopup.OnValueChanged(VersionSelectionChanged); if (VersionItems.Count == 1) VersionPopup.SetEnabled(false); UpdateDropdownContainer.Add(VersionPopup); VersionPopup.StretchToParentSize(); // Fix button on dark skin but overlapping edge pixel perfectly if (EditorGUIUtility.isProSkin) { VersionPopup.style.positionLeft = -1; UpdateDropdownContainer.style.sliceLeft = 4; } } private string VersionSelectionSetLabel(VersionItem item) { return item.Label; } private void VersionSelectionChanged(ChangeEvent e) { RefreshAddButton(); } private void SetUpdateVisibility(bool value) { if (UpdateContainer != null) UIUtils.SetElementDisplay(UpdateContainer, value); } internal void SetDisplayPackage(PackageInfo packageInfo) { DisplayPackage = packageInfo; var detailVisible = true; Error error = null; if (package == null || DisplayPackage == null) { detailVisible = false; UIUtils.SetElementDisplay(DocumentationContainer, false); UIUtils.SetElementDisplay(CustomContainer, false); UIUtils.SetElementDisplay(UpdateBuiltIn, false); foreach (var extension in PackageManagerExtensions.Extensions) extension.OnPackageSelectionChange(null); } else { SetUpdateVisibility(true); UIUtils.SetElementDisplay(ViewDocButton, true); RemoveButton.visible = true; if (string.IsNullOrEmpty(DisplayPackage.Description)) { DetailDesc.text = "There is no description for this package."; DetailDesc.AddToClassList(emptyDescriptionClass); } else { DetailDesc.text = DisplayPackage.Description; DetailDesc.RemoveFromClassList(emptyDescriptionClass); } root.Q