예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
0
        private void OnSelectionChanged(PageSelection selection)
        {
            var currentView = this.currentView;

            foreach (var item in selection.previousSelections.Where(s => !selection.Contains(s.packageUniqueId)).Concat(selection))
            {
                currentView.GetPackageItem(item.packageUniqueId)?.RefreshSelection();
            }
        }
예제 #4
0
 private void SelectInInspector(PageSelection selection, bool forceSelectInInspector)
 {
     // There are 3 situations when we want to select a package in the inspector
     // 1) we explicitly/force to select it as a result of a manual action (in this case, forceSelectInInspector should be set to true)
     // 2) currently there's no active selection at all
     // 3) currently another package is selected in inspector, hence we are sure that we are not stealing selection from some other window
     if (forceSelectInInspector || m_Selection.activeObject == null || m_Selection.activeObject is PackageSelectionObject)
     {
         var packageSelectionObjects = selection.Select(s => GetPackageSelectionObject(s, true)).ToArray();
         m_Selection.objects = packageSelectionObjects;
     }
 }
예제 #5
0
        internal void Refresh(PageSelection selections = null)
        {
            selections = selections ?? m_PageManager.GetSelection();
            scrollView.scrollOffset = new Vector2(0, m_PackageManagerPrefs.packageDetailVerticalScrollOffset);

            if (selections.Count == 1)
            {
                var selection = selections.FirstOrDefault();
                m_PackageDatabase.GetPackageAndVersion(selection.packageUniqueId, selection.versionUniqueId, out var package, out var version);
                Refresh(package, version);
            }
            else
            {
                // We call Refresh(null, null) to make sure that all single package details elements are hidden properly
                // We want to hide those elements when 1) there's nothing selected or 2) the multi select details view is visible.
                Refresh(null, null);
                UIUtils.SetElementDisplay(multiSelectDetails, multiSelectDetails.Refresh(selections));
            }
        }
예제 #6
0
 internal void OnSelectionChanged(PageSelection selections)
 {
     m_PackageManagerPrefs.packageDetailVerticalScrollOffset = 0;
     Refresh(selections);
 }
예제 #7
0
 private void OnPageSelectionChanged(PageSelection selection)
 {
     onSelectionChanged?.Invoke(selection);
     SelectInInspector(selection, false);
 }