public void OnEnable()
        {
            m_PageManager.onRefreshOperationStart  += OnRefreshOperationStartOrFinish;
            m_PageManager.onRefreshOperationFinish += OnRefreshOperationStartOrFinish;

            m_PageManager.onVisualStateChange += OnVisualStateChange;
            m_PageManager.onListRebuild       += OnListRebuild;
            m_PageManager.onListUpdate        += OnListUpdate;

            m_PageManager.onSelectionChanged += OnSelectionChanged;

            m_AssetStoreCallQueue.onCheckUpdateProgress += OnCheckUpdateProgress;

            m_UnityConnect.onUserLoginStateChange += OnUserLoginStateChange;

            m_SettingsProxy.onSeeAllVersionsChanged += OnSeeAllPackageVersionsChanged;

            m_PackageFiltering.onFilterTabChanged += OnFilterTabChanged;

            listView.OnEnable();
            packageLoadBar.OnEnable();

            if (!Unsupported.IsDeveloperBuild() && m_SettingsProxy.seeAllPackageVersions)
            {
                m_SettingsProxy.seeAllPackageVersions = false;
                m_SettingsProxy.Save();
            }

            // manually build the items on initialization to refresh the UI
            OnListRebuild(m_PageManager.GetCurrentPage());
        }
        private void OnUserLoginStateChange(bool isUserInfoReady, bool isUserLoggedIn)
        {
            if (!isUserLoggedIn)
            {
                return;
            }

            var page = m_PageManager.GetCurrentPage();

            if (page.filters.updateAvailableOnly)
            {
                m_AssetStoreClient.RefreshLocal();
                CheckUpdateForUncheckedLocalInfos();
            }
        }
Exemple #3
0
        public bool Refresh(PageSelection selections)
        {
            if (selections.Count <= 1)
            {
                return(false);
            }

            title.text = string.Format(L10n.Tr("{0} {1} selected"), selections.Count, selections.Count > 1 ? L10n.Tr("items") : L10n.Tr("item"));

            // We get the versions from the visual states instead of directly from the selection to keep the ordering of packages
            var versions = m_PageManager.GetCurrentPage().visualStates.Select(visualState =>
            {
                if (selections.TryGetValue(visualState.packageUniqueId, out var pair))
                {
                    m_PackageDatabase.GetPackageAndVersion(pair, out var package, out var version);
                    return(version ?? package?.versions.primary);
                }
                return(null);
            }).Where(version => version != null);

            foreach (var foldoutElement in allFoldoutElements)
            {
                foldoutElement.ClearVersions();
            }

            // We want to populate only a subset of all foldouts based on the current tab.
            var foldoutGroups = m_PackageFiltering.currentFilterTab == PackageFilterTab.AssetStore ? m_AssetStoreFoldoutGroups : m_UpmFoldoutGroups;

            foreach (var version in versions)
            {
                if (m_UnlockFoldout.AddPackageVersion(version))
                {
                    continue;
                }

                if (m_CheckUpdateFoldout.AddPackageVersion(version))
                {
                    continue;
                }

                var isActionable = false;
                foreach (var foldoutGroup in foldoutGroups)
                {
                    isActionable |= foldoutGroup.AddPackageVersion(version);
                }

                if (!isActionable)
                {
                    m_NoActionFoldout.AddPackageVersion(version);
                }
            }

            foreach (var foldoutElement in allFoldoutElements)
            {
                foldoutElement.Refresh();
            }

            UIUtils.SetElementDisplay(infoBoxContainer, m_UnlockFoldout.versions.Any());
            return(true);
        }
Exemple #4
0
        // In PageManager we track selection by keeping track of the package unique ids (hence it's not affected by reordering)
        // In ListView, the selection is tracked by indices. As a result, when we update the itemsSource, we want to sync selection index if needed
        // Because there might be some sort of reordering
        private void SyncPageManagerSelectionToListView(PageSelection selection = null)
        {
            var visualStates = itemsSource as List <VisualState>;

            if (visualStates == null)
            {
                return;
            }

            var page = m_PageManager.GetCurrentPage();

            if (page.tab != PackageFilterTab.AssetStore)
            {
                return;
            }

            selection ??= page.GetSelection();
            var oldSelectedVisualStates = selectedItems.Select(item => item as VisualState).ToArray();

            if (oldSelectedVisualStates.Length == selection.Count && oldSelectedVisualStates.All(v => selection.Contains(v.packageUniqueId)))
            {
                return;
            }

            var newSelectionIndices = new List <int>();

            for (var i = 0; i < visualStates.Count; i++)
            {
                if (selection.Contains(visualStates[i].packageUniqueId))
                {
                    newSelectionIndices.Add(i);
                }
            }
            SetSelection(newSelectionIndices);
        }
        private void AddOrUpdatePackageItem(VisualState state, IPackage package = null)
        {
            package ??= m_PackageDatabase.GetPackage(state?.packageUniqueId);
            if (package == null)
            {
                return;
            }

            var item = GetPackageItem(state.packageUniqueId);

            if (item != null)
            {
                item.SetPackage(package);

                // Check if group has changed
                var groupName = m_PageManager.GetCurrentPage().GetGroupName(package);
                if (item.packageGroup.name != groupName)
                {
                    var oldGroup = GetOrCreateGroup(item.packageGroup.name);
                    var newGroup = GetOrCreateGroup(groupName);
                    state.groupName = groupName;

                    // Replace PackageItem
                    m_PackageItemsLookup[package.uniqueId] = newGroup.AddPackageItem(package, state);
                    oldGroup.RemovePackageItem(item);
                    if (!oldGroup.packageItems.Any())
                    {
                        m_ItemsList.Remove(oldGroup);
                    }

                    ReorderGroups();
                }

                item.UpdateVisualState(state);
            }
            else
            {
                var group = GetOrCreateGroup(state.groupName);
                item = group.AddPackageItem(package, state);
                m_PackageItemsLookup[package.uniqueId] = item;
            }
        }
Exemple #6
0
        public void Refresh()
        {
            if (!UIUtils.IsElementVisible(this))
            {
                return;
            }
            var page = m_PageManager.GetCurrentPage();

            Set(page?.numTotalItems ?? 0, page?.numCurrentItems ?? 0);
            UpdateMenu();
            OnInternetReachabilityChange(m_Application.isInternetReachable);
        }
Exemple #7
0
        private void ViewPackagesOnTab(PackageFilterTab tab, PackageProgress progress, PackageType type = PackageType.None)
        {
            var packagesInProgress = m_PackageDatabase.allPackages.Where(p => p.progress == progress && (type == PackageType.None || p.Is(type))).ToArray();

            if (packagesInProgress.Any())
            {
                m_PackageFiltering.currentFilterTab = tab;
                m_PageManager.GetCurrentPage().LoadExtraItems(packagesInProgress);
                m_PageManager.SetSelected(packagesInProgress.Select(p => new PackageAndVersionIdPair(p.uniqueId)));
            }
            Close();
        }
Exemple #8
0
        public static string GetFilterNameWithSubPage(PackageFiltering packageFiltering, PageManager pageManager)
        {
            var filterName = packageFiltering.currentFilterTab.ToString();
            var page       = pageManager.GetCurrentPage();
            var subPage    = page.subPages.Skip(1).Any() ? page.currentSubPage : null;

            // Add the name of the sub page into the filter name for now
            if (!string.IsNullOrEmpty(subPage?.name))
            {
                filterName += "/" + subPage.name;
            }
            return(filterName);
        }
        private void UpdateStatusMessage()
        {
            var tab = m_PackageFiltering.currentFilterTab;

            var contentType = m_PageManager.GetCurrentPage().contentType ?? L10n.Tr("packages");

            if (m_PageManager.IsRefreshInProgress(tab))
            {
                SetStatusMessage(StatusType.Loading, string.Format(L10n.Tr("Refreshing {0}..."), contentType));
                return;
            }

            if (tab == PackageFilterTab.AssetStore && m_AssetStoreCallQueue.isCheckUpdateInProgress)
            {
                SetStatusMessage(StatusType.Loading, L10n.Tr("Checking for updates..."));
                return;
            }

            var errorMessage = string.Empty;
            var refreshError = m_PageManager.GetRefreshError(tab);

            if (!m_Application.isInternetReachable)
            {
                errorMessage = k_OfflineErrorMessage;
            }
            else if (refreshError != null)
            {
                var seeDetailInConsole = (UIError.Attribute.IsDetailInConsole & refreshError.attribute) != 0;
                errorMessage = seeDetailInConsole ?
                               string.Format(L10n.Tr("Error refreshing {0}, see console"), contentType) :
                               string.Format(L10n.Tr("Error refreshing {0}"), contentType);
            }

            if (!string.IsNullOrEmpty(errorMessage))
            {
                SetStatusMessage(StatusType.Error, errorMessage);
                return;
            }

            SetLastUpdateStatusMessage();
        }
        private void Refresh(IPage page = null)
        {
            if (page == null)
            {
                page = m_PageManager.GetCurrentPage();
            }
            var showOnFilterTab = page.subPages.Skip(1).Any();

            UIUtils.SetElementDisplay(this, showOnFilterTab);

            if (!showOnFilterTab)
            {
                return;
            }

            Clear();
            var currentSubPage = page.currentSubPage;

            foreach (var subPage in page.subPages)
            {
                var button = new Button();
                button.text = subPage.displayName;
                button.clickable.clicked += () =>
                {
                    if (page.currentSubPage == subPage)
                    {
                        return;
                    }
                    page.currentSubPage = subPage;
                    PackageManagerWindowAnalytics.SendEvent("changeSubPage");
                };
                Add(button);
                if (subPage == currentSubPage)
                {
                    button.AddToClassList("active");
                }
            }
        }
Exemple #11
0
        private void OnPackagesChanged(PackagesChangeArgs args)
        {
            UpdateOrdering(m_PageManager.GetCurrentPage());

            if (m_PackageFiltering.currentFilterTab == PackageFilterTab.MyRegistries)
            {
                // We can skip the whole database scan to save some time if non of the packages changed are related to scoped registry
                // Note that we also check `preUpdate` to catch the cases where packages are move from ScopedRegistry to UnityRegistry
                if (!args.added.Concat(args.removed).Concat(args.updated).Concat(args.preUpdate).Any(p => p.Is(PackageType.ScopedRegistry)))
                {
                    return;
                }

                if (!m_PackageDatabase.allPackages.Any(p => p.Is(PackageType.ScopedRegistry)))
                {
                    SetFilter(PackageFilterTab.UnityRegistry);
                }
            }

            if (args.progressUpdated.Any() || args.added.Any() || args.removed.Any())
            {
                RefreshInProgressSpinner();
            }
        }
Exemple #12
0
        private void SelectPackageAndFilter()
        {
            IPackageVersion version = null;
            IPackage        package = null;

            if (!string.IsNullOrEmpty(m_PackageToSelectOnLoaded))
            {
                m_PackageDatabase.GetPackageAndVersionByIdOrName(m_PackageToSelectOnLoaded, out package, out version);
            }

            if (m_FilterToSelectAfterLoad == PackageFilterTab.AssetStore)
            {
                m_PackageFiltering.currentFilterTab = PackageFilterTab.AssetStore;

                if (!string.IsNullOrEmpty(m_PackageToSelectOnLoaded))
                {
                    if (package == null || package is PlaceholderPackage)
                    {
                        m_PageManager.Fetch(m_PackageToSelectOnLoaded);
                    }
                    else
                    {
                        m_PageManager.GetPage(PackageFilterTab.AssetStore).Load(package, version);
                    }
                }

                m_FilterToSelectAfterLoad  = null;
                m_PackageToSelectOnLoaded  = null;
                m_SubPageToSelectAfterLoad = null;
                return;
            }

            // The !IsInitialFetchingDone check was added to the start of this function in the past for the Entitlement Error checker,
            // But it caused `Open In Unity` to not work sometimes for the `My Assets` tab. Hence we moved the check from the beginning
            // of this function to after the `My Assets` logic is done so that we don't break `My Assets` and the Entitlement Error checker.
            if (!m_PageManager.IsInitialFetchingDone())
            {
                return;
            }

            if (package != null || m_FilterToSelectAfterLoad != null)
            {
                var tab = m_FilterToSelectAfterLoad ?? PackageFiltering.k_DefaultFilterTab;

                if (m_SubPageToSelectAfterLoad != null)
                {
                    void SelectSubPage(IPage page, string subPageName)
                    {
                        var subPage = page.subPages.FirstOrDefault(page => string.Compare(page.name, subPageName, StringComparison.InvariantCultureIgnoreCase) == 0) ?? page.subPages.First();

                        page.currentSubPage = subPage;
                    }

                    void OnFilterTabChangedSelectSubPage(PackageFilterTab filterTab)
                    {
                        m_PackageFiltering.onFilterTabChanged -= OnFilterTabChangedSelectSubPage;
                        SelectSubPage(m_PageManager.GetCurrentPage(), m_SubPageToSelectAfterLoad);
                    }

                    if (m_PackageFiltering.currentFilterTab == tab)
                    {
                        SelectSubPage(m_PageManager.GetCurrentPage(), m_SubPageToSelectAfterLoad);
                    }
                    else
                    {
                        m_PackageFiltering.onFilterTabChanged += OnFilterTabChangedSelectSubPage;
                    }

                    m_PackageToSelectOnLoaded = null;
                }

                m_PackageFiltering.currentFilterTab = tab;
                if (!string.IsNullOrEmpty(m_PackageToSelectOnLoaded))
                {
                    m_PageManager.SetSelected(package, version, true);
                    packageList.OnFocus();
                }

                m_FilterToSelectAfterLoad  = null;
                m_PackageToSelectOnLoaded  = null;
                m_SubPageToSelectAfterLoad = null;
            }
        }