void onClick_FindVersions()
 {
     SetPhase(Phase.FindVersions);
     root.SetEnabled(false);
     GitUtils.GetRefs(repoUrlText.value, refs =>
     {
         root.SetEnabled(true);
         bool hasError             = !refs.Any();
         findVersionsError.visible = hasError;
         if (!hasError)
         {
             versions = refs;
             SetPhase(Phase.SelectVersion);
         }
     });
 }
        /// <summary>
        /// Called by the Package Manager UI when the package selection changed.
        /// </summary>
        /// <param name="packageInfo">The newly selected package information (can be null)</param>
        public void OnPackageSelectionChange(PackageInfo packageInfo)
        {
            InitializeUI();
            if (!_initialized || packageInfo == null || _packageInfo == packageInfo)
            {
                return;
            }

            _packageInfo = packageInfo;

            var isGit = packageInfo.source == PackageSource.Git;

            UIUtils.SetElementDisplay(_gitDetailActoins, isGit);
            UIUtils.SetElementDisplay(_originalDetailActions, !isGit);
            UIUtils.SetElementDisplay(_detailControls.Q("", "popupField"), !isGit);
            UIUtils.SetElementDisplay(_updateButton, isGit);
            UIUtils.SetElementDisplay(_versionPopup, isGit);
            UIUtils.SetElementDisplay(_originalAddButton, false);
            UIUtils.SetElementDisplay(_addButton, true);

            if (isGit)
            {
                _updateButton.text = "Update to";
                _versionPopup.SetEnabled(false);
                _updateButton.SetEnabled(false);
                GitUtils.GetRefs(PackageUtils.GetRepoHttpUrl(_packageInfo.packageId), _refs, () =>
                {
                    _updateButton.SetEnabled(_currentRefName != _selectedRefName);
                    _versionPopup.SetEnabled(true);
                });

                SetVersion(_currentRefName);
                EditorApplication.delayCall += () =>
                {
                    UIUtils.SetElementDisplay(_detailControls.Q("updateCombo"), true);
                    UIUtils.SetElementDisplay(_detailControls.Q("remove"), true);
                    _detailControls.Q("remove").SetEnabled(true);
                }
                ;
                _currentHostData = Settings.GetHostData(_packageInfo.packageId);

                _hostingIcon.tooltip = "View on " + _currentHostData.Name;
                _hostingIcon.style.backgroundImage = EditorGUIUtility.isProSkin ? _currentHostData.LogoLight : _currentHostData.LogoDark;
            }
        }
示例#3
0
        void OnGUI()
        {
            EditorGUIUtility.labelWidth = 100;
            using (var ds = new EditorGUI.DisabledScope(PackageUtils.isBusy))
            {
                using (var ccs = new EditorGUI.ChangeCheckScope())
                    using (new EditorGUILayout.HorizontalScope())
                    {
                        GUI.SetNextControlName("Repogitory URL");
                        _url = EditorGUILayout.TextField("Repogitory URL", _url);

                        if (!_focused)
                        {
                            EditorGUI.FocusTextInControl("Repogitory URL");
                            _focused = true;
                        }

                        if (ccs.changed)
                        {
                            _repoUrl   = PackageUtils.GetRepoUrl(_url);
                            _version   = "-- Select Version --";
                            _packageId = "";
                            GitUtils.GetRefs(_url, _refs, () => { EditorApplication.delayCall += Repaint; });
                        }

                        if (!PackageUtils.isBusy && !string.IsNullOrEmpty(_url) && _refs.Count == 0)
                        {
                            GUILayout.Label(_errorUrl, GUILayout.Width(20));
                        }
                    }

                using (new EditorGUILayout.HorizontalScope())
                {
                    EditorGUILayout.PrefixLabel("Version");
                    using (new EditorGUI.DisabledScope(_refs.Count == 0))
                    {
                        if (GUILayout.Button(_version, EditorStyles.popup))
                        {
                            PopupVersions(ver =>
                            {
                                _version   = _refs.Contains(ver) ? ver : "HEAD";
                                _packageId = "";
                                GitUtils.GetPackageJson(_url, _version, name =>
                                {
                                    _packageId = string.IsNullOrEmpty(name)
                                                                                ? null
                                                                                : name + "@" + _repoUrl + "#" + _version;
                                    EditorApplication.delayCall += Repaint;
                                });
                            });
                        }
                    }
                    using (new EditorGUI.DisabledScope(string.IsNullOrEmpty(_packageId)))
                    {
                        if (GUILayout.Button(new GUIContent("Add", "Add a package '" + _packageId + "' to the project."), EditorStyles.miniButton, GUILayout.Width(60)))
                        {
                            PackageUtils.AddPackage(_packageId, req =>
                            {
                                if (req.Status == StatusCode.Success)
                                {
                                    Close();
                                }
                            });
                        }
                    }
                    if (_packageId == null)
                    {
                        GUILayout.Label(_errorBranch, GUILayout.Width(20));
                    }
                }
            }
        }
示例#4
0
        void UpdateGitPackages(Queue <Expose> packagesToUpdate, Dictionary <string, IEnumerable <string> > results = null)
        {
            Debug.LogFormat("[UpdateGitPackages] {0} package(s) left", packagesToUpdate.Count);
            phase = Phase.UpdatePackages;
            bool isRunning = 0 < packagesToUpdate.Count;

            PlaySpinner(isRunning);

            // Update task is finished.
            if (!isRunning)
            {
                Debug.LogFormat("[UpdateGitPackages] Completed");
                // Nothing to do.
                if (results == null)
                {
                    phase = Phase.Idle;
                    return;
                }

                // Update package infomation's version.
                Expose exPackages = GetExposedPackages();
                foreach (var pair in results)
                {
                    try
                    {
                        Debug.LogFormat("[UpdateGitPackages] Overwrite {0}", pair.Key);
                        if (exPackages.Call("ContainsKey", pair.Key).As <bool>())
                        {
                            UpdatePackageInfoVersions(exPackages[pair.Key], pair.Value);
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.LogException(e);
                    }
                }

                // Reload package collection on next frame
                Debug.LogFormat("[UpdateGitPackages] Reload on next frame");
                phase = Phase.ReloadPackageCollection;
                EditorApplication.delayCall += ReloadPackageCollection;
                return;
            }

            if (results == null)
            {
                results = new Dictionary <string, IEnumerable <string> >();
            }

            //
            var package        = packagesToUpdate.Dequeue();
            var displayPackage = package["VersionToDisplay"];
            var packageId      = displayPackage["_PackageId"].As <string>();
            var packageName    = package["packageName"].As <string>();

            // Already get versions.
            if (packageId == null || results.ContainsKey(packageName))
            {
                Debug.LogFormat("[UpdateGitPackages] Skip: {0}", packageName);
                UpdateGitPackages(packagesToUpdate, results);
                return;
            }

            // Get all branch/tag names in repo.
            var url = PackageUtils.GetRepoUrlForCommand(packageId);

            Debug.LogFormat("[UpdateGitPackages] GetRefs: {0}", packageName);
            GitUtils.GetRefs(url, refNames =>
            {
                results[packageName] = refNames;
                UpdateGitPackages(packagesToUpdate, results);
            });
        }