private void SelectAllBetween(string firstPackageUniqueId, string secondPackageUniqueId)
        {
            var newSelections        = new List <PackageAndVersionIdPair>();
            var inBetweenTwoPackages = false;

            if (firstPackageUniqueId == secondPackageUniqueId)
            {
                newSelections.Add(new PackageAndVersionIdPair(firstPackageUniqueId));
            }
            else
            {
                foreach (var item in packageItems)
                {
                    if (!UIUtils.IsElementVisible(item))
                    {
                        continue;
                    }
                    var packageUniqueId = item.package?.uniqueId;
                    if (string.IsNullOrEmpty(packageUniqueId))
                    {
                        continue;
                    }

                    var matchFirstPackage   = packageUniqueId == firstPackageUniqueId;
                    var matchSecondPackakge = packageUniqueId == secondPackageUniqueId;
                    if (matchFirstPackage || matchSecondPackakge || inBetweenTwoPackages)
                    {
                        newSelections.Add(new PackageAndVersionIdPair(packageUniqueId));
                    }

                    if (matchFirstPackage || matchSecondPackakge)
                    {
                        inBetweenTwoPackages = !inBetweenTwoPackages;
                        if (!inBetweenTwoPackages)
                        {
                            // If we match the second package before we matched the first package then we want to reverse the order
                            // to first sure that the first selected is in front. Otherwise Shift selections might have weird behaviours.
                            if (matchFirstPackage)
                            {
                                newSelections.Reverse();
                            }
                            break;
                        }
                    }
                }
            }
            m_PageManager.SetSelected(newSelections, true);
        }
Example #2
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();
        }
Example #3
0
        private void SyncListViewSelectionToPageManager(IEnumerable <object> items)
        {
            var selections = items.Select(item =>
            {
                var visualState = item as VisualState;
                var package     = m_PackageDatabase.GetPackage(visualState?.packageUniqueId);
                if (package != null)
                {
                    return(new PackageAndVersionIdPair(package.uniqueId));
                }
                return(null);
            }).Where(s => s != null).ToArray();

            // SelectionChange happens before BindItems, hence we use m_PageManager.SetSelected instead of packageItem.SelectMainItem
            // as PackageItems are null sometimes when SelectionChange is triggered
            m_PageManager.SetSelected(selections, true);
        }
        private void InstallByNameAndVersion(string packageName, string packageVersion = null)
        {
            var packageId = string.IsNullOrEmpty(packageVersion) ? packageName : $"{packageName}@{packageVersion}";

            m_UpmClient.AddById(packageId);

            PackageManagerWindowAnalytics.SendEvent("addByNameAndVersion", packageId);

            Close();

            var package = m_PackageDatabase.GetPackage(packageName);

            if (package != null)
            {
                m_PackageFiltering.currentFilterTab = m_PageManager.FindTab(package);
                m_PageManager.SetSelected(package, package.versions?.FirstOrDefault(v => v.versionString == packageVersion));
            }
        }
Example #5
0
 public void SelectVersionItem()
 {
     m_PageManager.SetSelected(package, version, true);
 }
Example #6
0
        private void SetupAddMenu()
        {
            var dropdownItem = addMenu.AddBuiltInDropdownItem();

            dropdownItem.text     = L10n.Tr("Add package from disk...");
            dropdownItem.userData = "AddFromDisk";
            dropdownItem.action   = () =>
            {
                var path = m_Application.OpenFilePanelWithFilters(L10n.Tr("Select package on disk"), "", new[] { "package.json file", "json" });
                if (string.IsNullOrEmpty(path))
                {
                    return;
                }

                try
                {
                    if (m_IOProxy.GetFileName(path) != "package.json")
                    {
                        Debug.Log(L10n.Tr("[Package Manager Window] Please select a valid package.json file in a package folder."));
                        return;
                    }


                    if (!m_PackageDatabase.isInstallOrUninstallInProgress)
                    {
                        m_PackageDatabase.InstallFromPath(m_IOProxy.GetParentDirectory(path), out var tempPackageId);
                        PackageManagerWindowAnalytics.SendEvent("addFromDisk");

                        var package = m_PackageDatabase.GetPackage(tempPackageId);
                        if (package != null)
                        {
                            m_PackageFiltering.currentFilterTab = PackageFilterTab.InProject;
                            m_PageManager.SetSelected(package);
                        }
                    }
                }
                catch (System.IO.IOException e)
                {
                    Debug.Log($"[Package Manager Window] Cannot add package from disk {path}: {e.Message}");
                }
            };

            dropdownItem          = addMenu.AddBuiltInDropdownItem();
            dropdownItem.text     = L10n.Tr("Add package from tarball...");
            dropdownItem.userData = "AddFromTarball";
            dropdownItem.action   = () =>
            {
                var path = m_Application.OpenFilePanelWithFilters(L10n.Tr("Select package on disk"), "", new[] { "Package tarball", "tgz, tar.gz" });
                if (!string.IsNullOrEmpty(path) && !m_PackageDatabase.isInstallOrUninstallInProgress)
                {
                    m_PackageDatabase.InstallFromPath(path, out var tempPackageId);
                    PackageManagerWindowAnalytics.SendEvent("addFromTarball");

                    var package = m_PackageDatabase.GetPackage(tempPackageId);
                    if (package != null)
                    {
                        m_PackageFiltering.currentFilterTab = PackageFilterTab.InProject;
                        m_PageManager.SetSelected(package);
                    }
                }
            };

            dropdownItem          = addMenu.AddBuiltInDropdownItem();
            dropdownItem.text     = L10n.Tr("Add package from git URL...");
            dropdownItem.userData = "AddFromGit";
            dropdownItem.action   = () =>
            {
                var args = new InputDropdownArgs
                {
                    title            = L10n.Tr("Add package from git URL"),
                    iconUssClass     = "git",
                    placeholderText  = L10n.Tr("URL"),
                    submitButtonText = L10n.Tr("Add"),
                    onInputSubmitted = url =>
                    {
                        if (!m_PackageDatabase.isInstallOrUninstallInProgress)
                        {
                            m_PackageDatabase.InstallFromUrl(url);
                            PackageManagerWindowAnalytics.SendEvent("addFromGitUrl", url);

                            var package = m_PackageDatabase.GetPackage(url);
                            if (package != null)
                            {
                                m_PackageFiltering.currentFilterTab = PackageFilterTab.InProject;
                                m_PageManager.SetSelected(package);
                            }
                        }
                    },
                    windowSize = new Vector2(resolvedStyle.width, 50)
                };
                addMenu.ShowInputDropdown(args);
            };

            dropdownItem          = addMenu.AddBuiltInDropdownItem();
            dropdownItem.text     = L10n.Tr("Add package by name...");
            dropdownItem.userData = "AddByName";
            dropdownItem.action   = () =>
            {
                // Same as above, the worldBound of the toolbar is used rather than the addMenu
                var rect     = GUIUtility.GUIToScreenRect(worldBound);
                var dropdown = new AddPackageByNameDropdown(m_ResourceLoader, m_PackageFiltering, m_UpmClient, m_PackageDatabase, m_PageManager, PackageManagerWindow.instance)
                {
                    position = rect
                };
                DropdownContainer.ShowDropdown(dropdown);
            };
        }
 public void SelectMainItem()
 {
     m_PageManager.SetSelected(package, null, true);
 }
Example #8
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;
            }
        }