internal void OnPackagesChanged(IEnumerable <IPackage> added, IEnumerable <IPackage> removed, IEnumerable <IPackage> updated) { var reorderNeeded = false; foreach (var package in added) { if (PackageFiltering.instance.FilterByCurrentTab(package)) { var item = new PackageItem(package); list.Add(item); reorderNeeded = true; UIUtils.SetElementDisplay(item, PackageFiltering.instance.FilterByCurrentSearchText(package)); } } foreach (var package in removed) { var item = FindPackageItem(package); if (item != null) { list.Remove(item); } } foreach (var package in updated) { var item = FindPackageItem(package); if (item != null) { if (PackageFiltering.instance.FilterByCurrentTab(package)) { if (!reorderNeeded && item.displayName != package.displayName) { reorderNeeded = true; } item.SetPackage(package); } else { list.Remove(item); } } else if (PackageFiltering.instance.FilterByCurrentTab(package)) { item = new PackageItem(package); list.Add(item); reorderNeeded = true; } UIUtils.SetElementDisplay(item, PackageFiltering.instance.FilterByCurrentSearchText(package)); } if (!m_PackagesLoaded && added.Any()) { m_PackagesLoaded = true; onPackagesLoaded(); } if (reorderNeeded) { ReorderPackageItems(); } RefreshSelection(); }
public void OnEnable() { this.SetAntiAliasing(4); if (instance == null) { instance = this; } if (instance != this) { return; } instance.titleContent = GetLocalizedTitleContent(); var windowResource = Resources.GetVisualTreeAsset("PackageManagerWindow.uxml"); if (windowResource != null) { var root = windowResource.Instantiate(); root.styleSheets.Add(Resources.GetMainWindowStyleSheet()); cache = new VisualElementCache(root); rootVisualElement.Add(root); LocalizeVisualElementAndAllChildrenText(rootVisualElement); PageManager.instance.Setup(); packageDetails.OnEnable(); packageList.OnEnable(); packageLoadBar.OnEnable(); packageManagerToolbar.OnEnable(); packageStatusbar.OnEnable(); packageManagerToolbar.SetEnabled(!PackageDatabase.instance.isEmpty); packageDetails.packageToolbarContainer.SetEnabled(!PackageDatabase.instance.isEmpty); PageManager.instance.onRefreshOperationFinish += OnRefreshOperationFinish; PageManager.instance.onRefreshOperationStart += OnRefreshOperationStart; PageManager.instance.onRefreshOperationError += OnRefreshOperationError; PackageFiltering.instance.onFilterTabChanged += OnFilterChanged; PackageManagerWindowAnalytics.Setup(); root.StretchToParentSize(); var newTab = PackageManagerPrefs.instance.lastUsedPackageFilter ?? PackageFiltering.instance.defaultFilterTab; PackageFiltering.instance.SetCurrentFilterTabWithoutNotify(newTab); packageManagerToolbar.SetFilter(newTab); if (newTab != PackageFilterTab.AssetStore) { UIUtils.SetElementDisplay(packageLoadBar, false); } if (PageManager.instance.GetRefreshTimestamp(newTab) == 0) { DelayRefresh(newTab); } if (newTab != PackageFilterTab.All && PageManager.instance.GetRefreshTimestamp(PackageFilterTab.All) == 0) { DelayRefresh(PackageFilterTab.All); } mainContainer.leftWidth = m_SplitPaneLeftWidth; mainContainer.onSizeChanged += width => { m_SplitPaneLeftWidth = width; }; EditorApplication.focusChanged += OnFocusChanged; ApplicationUtil.instance.onEditorSelectionChanged += RefreshSelectedInInspectorClass; rootVisualElement.focusable = true; rootVisualElement.RegisterCallback <AttachToPanelEvent>(OnAttachToPanel); rootVisualElement.RegisterCallback <DetachFromPanelEvent>(OnDetachFromPanel); RefreshSelectedInInspectorClass(); } }
private void SetEmptyAreaDisplay(bool value) { // empty area & scroll view should never be shown at the same time UIUtils.SetElementDisplay(emptyArea, value); UIUtils.SetElementDisplay(scrollView, !value); }
private void SetupOrdering() { orderingMenu.menu.MenuItems().Clear(); orderingMenu.ShowTextTooltipOnSizeChange(-16); UIUtils.SetElementDisplay(orderingMenu, false); }
internal void StopSpinner() { spinner.Stop(); UIUtils.SetElementDisplay(stateLabel, true); }
internal void SetPackage(IPackage package) { var displayVersion = package?.primaryVersion; if (displayVersion == null) { return; } var oldDisplayVersion = this.package?.primaryVersion; this.package = package; if (oldDisplayVersion?.uniqueId != displayVersion.uniqueId && SelectionManager.instance.IsSelected(package, oldDisplayVersion)) { SelectionManager.instance.SetSelected(package, displayVersion); } expander.expanded = SelectionManager.instance.IsExpanded(package); displayName = displayVersion.displayName; versionLabel.text = GetStandardizedLabel(displayVersion, true); string stateClass = null; if (package.installedVersion != null) { if (displayVersion.HasTag(PackageTag.InDevelopment)) { stateClass = "development"; } else if (package.state == PackageState.Outdated && package.recommendedVersion != package.installedVersion) { stateClass = GetIconStateId(PackageState.Outdated); } else { stateClass = "installed"; } } // Error state should be last as it should supersede other states if (package.errors.Any()) { stateClass = GetIconStateId(PackageState.Error); } stateClass = stateClass ?? GetIconStateId(package.state); stateLabel.RemoveFromClassList(m_CurrentStateClass); stateLabel.AddToClassList(stateClass); var isBuiltIn = displayVersion.HasTag(PackageTag.BuiltIn); UIUtils.SetElementDisplay(expander, !isBuiltIn); UIUtils.SetElementDisplay(expanderHidden, isBuiltIn); UIUtils.SetElementDisplay(versionList, !isBuiltIn); UIUtils.SetElementDisplay(versionLabel, !isBuiltIn); m_CurrentStateClass = stateClass; if (package.state != PackageState.InProgress && spinner.started) { StopSpinner(); } RefreshVersions(); RefreshSelection(); }
private void RefreshAddButton() { if (package.Current != null && package.Current.IsInDevelopment) { UIUtils.SetElementDisplay(UpdateBuiltIn, false); UIUtils.SetElementDisplay(UpdateButton, false); return; } var targetVersion = TargetVersion; if (targetVersion == null) { return; } var enableButton = !Package.PackageOperationInProgress; var action = PackageAction.Update; var addOperation = package.AddSignal.Operation; var inprogress = addOperation != null && addOperation.PackageInfo.PackageId == DisplayPackage.PackageId; var isBuiltIn = package.IsBuiltIn; if (addOperation != null) { if (isBuiltIn) { action = PackageAction.Enable; inprogress = true; enableButton = false; } else { var addOperationVersion = package.AddSignal.Operation.PackageInfo.Version; if (package.Current == null) { action = PackageAction.Add; inprogress = true; } else { action = addOperationVersion.CompareByPrecedence(package.Current.Version) >= 0 ? PackageAction.Update : PackageAction.Downgrade; inprogress = true; } enableButton = false; } } else { if (package.Current != null) { // Installed if (package.Current.IsVersionLocked) { if (package.Current.Origin == PackageSource.Embedded) { action = PackageAction.Embedded; } else if (package.Current.Origin == PackageSource.Git) { action = PackageAction.Git; } enableButton = false; } else { if (targetVersion.IsInstalled) { if (targetVersion == package.LatestUpdate) { action = PackageAction.UpToDate; } else { action = PackageAction.Current; } enableButton = false; } else { action = targetVersion.Version.CompareByPrecedence(package.Current.Version) >= 0 ? PackageAction.Update : PackageAction.Downgrade; } } } else { // Not Installed if (package.Versions.Any()) { if (isBuiltIn) { action = PackageAction.Enable; } else { action = PackageAction.Add; } } } } if (package.RemoveSignal.Operation != null) { enableButton = false; } if (EditorApplication.isCompiling) { enableButton = false; EditorApplication.update -= CheckCompilationStatus; EditorApplication.update += CheckCompilationStatus; } var version = action == PackageAction.Update || action == PackageAction.Downgrade ? targetVersion.Version : null; var button = isBuiltIn ? UpdateBuiltIn : UpdateButton; button.SetEnabled(enableButton); button.text = GetButtonText(action, inprogress, version); var visibleFlag = !(package.Current != null && package.Current.IsVersionLocked); UIUtils.SetElementDisplay(UpdateBuiltIn, isBuiltIn && visibleFlag); UIUtils.SetElementDisplay(UpdateButton, !isBuiltIn && visibleFlag); }
private void RefreshSupportedUnityVersions() { UIUtils.SetElementDisplay(detailUnityVersionsContainer, displayVersion.supportedVersion != null); detailUnityVersions.text = $"{displayVersion.supportedVersion} or higher"; }
private void SetUpdateVisibility(bool value) { UIUtils.SetElementDisplay(UpdateButton, value); }
private void SetDisplayPackage(PackageInfo packageInfo, Error packageError = null) { DisplayPackage = packageInfo; Error error = null; var detailVisible = package != null && DisplayPackage != null; if (!detailVisible) { RefreshExtensions(null); } else { SetUpdateVisibility(true); var isBuiltIn = DisplayPackage.IsBuiltIn; UIUtils.SetElementDisplay(ViewDocButton, true); UIUtils.SetElementDisplay(ViewLicensesContainer, !isBuiltIn); 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 <Label>("detailTitle").text = DisplayPackage.DisplayName; DetailVersion.text = "Version " + DisplayPackage.VersionWithoutTag; if (DisplayPackage.IsInDevelopment || DisplayPackage.HasVersionTag(PackageTag.preview)) { UIUtils.SetElementDisplay(GetTag(PackageTag.verified), false); } else { var unityVersionParts = Application.unityVersion.Split('.'); var unityVersion = string.Format("{0}.{1}", unityVersionParts[0], unityVersionParts[1]); VerifyLabel.text = unityVersion + " verified"; UIUtils.SetElementDisplay(GetTag(PackageTag.verified), DisplayPackage.IsVerified); } UIUtils.SetElementDisplay(GetTag(PackageTag.inDevelopment), DisplayPackage.IsInDevelopment); UIUtils.SetElementDisplay(GetTag(PackageTag.local), DisplayPackage.IsLocal); UIUtils.SetElementDisplay(GetTag(PackageTag.git), DisplayPackage.IsGit); UIUtils.SetElementDisplay(GetTag(PackageTag.preview), DisplayPackage.IsPreview); UIUtils.SetElementDisplay(EditPackageManifestButton, DisplayPackage.IsInstalled && !package.IsBuiltIn); UIUtils.SetElementDisplay(DocumentationContainer, true); UIUtils.SetElementDisplay(ChangelogContainer, DisplayPackage.HasChangelog); SampleList.SetPackage(DisplayPackage); root.Q <Label>("detailName").text = DisplayPackage.Name; DetailScrollView.scrollOffset = new Vector2(0, 0); DetailModuleReference.text = ""; if (isBuiltIn) { DetailModuleReference.text = DisplayPackage.BuiltInDescription; } DetailAuthor.text = ""; if (!string.IsNullOrEmpty(DisplayPackage.Author)) { DetailAuthor.text = string.Format("Author: {0}", DisplayPackage.Author); } // If the package details is not enabled, don't update the date yet as we are fetching new information if (enabledSelf) { DetailDate.text = ""; // In Development packages are not published, so we do not show any published date if (DisplayPackage.Info != null && !DisplayPackage.IsInDevelopment) { if (DisplayPackage.Info.datePublished != null) { DetailDate.text = $"Published Date: {DisplayPackage.Info.datePublished.Value:MMMM dd, yyyy}"; } else if (DisplayPackage.IsCore || DisplayPackage.IsInstalled) { // For core packages, or installed packages that are bundled with Unity without being published, use Unity's build date var unityBuildDate = new DateTime(1970, 1, 1, 0, 0, 0, 0); unityBuildDate = unityBuildDate.AddSeconds(InternalEditorUtility.GetUnityVersionDate()); DetailDate.text = $"Published Date: {unityBuildDate:MMMM dd, yyyy}"; } } } UIUtils.SetElementDisplay(DetailDesc, !isBuiltIn); UIUtils.SetElementDisplay(DetailVersion, !isBuiltIn); UIUtils.SetElementDisplayNonEmpty(DetailModuleReference); UIUtils.SetElementDisplayNonEmpty(DetailAuthor); UIUtils.SetElementDisplayNonEmpty(DetailDate); if (DisplayPackage.Errors.Count > 0) { error = DisplayPackage.Errors.First(); } RefreshAddButton(); RefreshRemoveButton(); RefreshDevelopButton(); UIUtils.SetElementDisplay(CustomContainer, true); package.AddSignal.OnOperation += OnAddOperation; package.RemoveSignal.OnOperation += OnRemoveOperation; package.EmbedSignal.OnOperation += OnDevelopOperation; RefreshExtensions(DisplayPackage); ShowDependencies(); } OnEditorSelectionChanged(); // Set visibility SetContentVisibility(detailVisible); if (packageError == null && package != null && package.Error != null) { packageError = package.Error; } if (null == error) { error = packageError; } if (error != null) { SetError(error); } else { DetailError.ClearError(); } }
private void SetContentVisibility(bool visible) { UIUtils.SetElementDisplay(DetailContainer, visible); UIUtils.SetElementDisplay(PackageToolbarContainer, visible); }
private void DescLessClick() { detailDesc.style.maxHeight = 48; UIUtils.SetElementDisplay(detailDescMore, true); UIUtils.SetElementDisplay(detailDescLess, false); }
private void DescMoreClick() { detailDesc.style.maxHeight = float.MaxValue; UIUtils.SetElementDisplay(detailDescMore, false); UIUtils.SetElementDisplay(detailDescLess, true); }
private void SetDisplay(bool value) { UIUtils.SetElementDisplay(this, value); }
internal void StartSpinner() { spinner.Start(); UIUtils.SetElementDisplay(stateLabel, false); }
public void OnLessButtonClicked() { UIUtils.SetElementDisplay(releaseNotesContainer, false); UIUtils.SetElementDisplay(moreButton, true); }
private void SetDisplayVersion(IPackageVersion version) { displayVersion = version; detailScrollView.scrollOffset = new Vector2(0, 0); var detailVisible = package != null && displayVersion != null; if (!detailVisible) { UIUtils.SetElementDisplay(customContainer, false); RefreshExtensions(null); } else { var isBuiltIn = displayVersion.HasTag(PackageTag.BuiltIn); var isAssetStorePackage = displayVersion.HasTag(PackageTag.AssetStore); SetUpdateVisibility(true); detailTitle.text = displayVersion.displayName; UIUtils.SetElementDisplay(detailNameContainer, !isAssetStorePackage); detailName.text = displayVersion.name; RefreshLinks(); RefreshDescription(); RefreshCategories(); detailVersion.text = $"Version {displayVersion.version.StripTag()}"; if (isAssetStorePackage && displayVersion.versionString != displayVersion.version.ToString()) { detailVersion.text = $"Version {displayVersion.versionString}"; } foreach (var tag in k_VisibleTags) { UIUtils.SetElementDisplay(GetTagLabel(tag), displayVersion.HasTag(tag)); } UIUtils.SetElementDisplay(editButton, displayVersion.isInstalled && !displayVersion.HasTag(PackageTag.BuiltIn)); sampleList.SetPackageVersion(displayVersion); RefreshAuthor(); RefreshPublishedDate(); UIUtils.SetElementDisplay(detailVersion, !isBuiltIn); UIUtils.SetElementDisplay(customContainer, true); RefreshExtensions(displayVersion); RefreshDependencies(PackageManagerPrefs.instance.showPackageDependencies); RefreshSupportedUnityVersions(); RefreshSizeInfo(); RefreshSupportingImages(); RefreshPackageActionButtons(); RefreshImportAndDownloadButtons(); } OnEditorSelectionChanged(); // Set visibility SetContentVisibility(detailVisible); RefreshErrorDisplay(); }