void AddOrUpdatePackage()
        {
            var target = _versionPopup.text != "(default)" ? _versionPopup.text : "";
            var id     = PackageUtils.GetSpecificPackageId(_packageInfo.packageId, target);

            PackageUtils.AddPackage(id);

            _versionPopup.SetEnabled(false);
            _updateButton.SetEnabled(false);
            _updateButton.text = "Updating to";
        }
        void onClick_InstallPackage()
        {
            root.SetEnabled(false);
            var url        = PackageUtils.GetRepoUrl(repoUrlText.value);
            var _packageId = string.Format("{0}@{1}#{2}", packageNameLabel.text, url, versionSelectButton.text);

            PackageUtils.AddPackage(_packageId, req =>
            {
                root.SetEnabled(true);
                if (req.Status == StatusCode.Success)
                {
                    onClick_Close();
                }
                else if (req.Status == StatusCode.Failure)
                {
                    installPackageError.tooltip = req.Error.message;
                    installPackageError.visible = true;
                }
            });
        }
Example #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));
                    }
                }
            }
        }