Exemplo n.º 1
0
        private void AddOrUpdatePackage()
        {
            var target = _versionPopup.text != "(default)" ? _versionPopup.text : "";
            var id     = UnityPackageUtilities.GetSpecificPackageId(_packageInfo.packageId, target);

            UnityPackageUtilities.AddPackage(id);

            _versionPopup.SetEnabled(false);
            _updateButton.SetEnabled(false);
            _updateButton.text = "Updating to";
        }
Exemplo n.º 2
0
        /// <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>
        void IPackageManagerExtension.OnPackageSelectionChange(PackageInfo packageInfo)
        {
            InitializeUI();

            if (!_initialized ||
                packageInfo == null ||
                _packageInfo == packageInfo)
            {
                return;
            }

            _packageInfo = packageInfo;

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

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

            if (isGit)
            {
                _updateButton.text = "Update to";
                _versionPopup.SetEnabled(false);
                _updateButton.SetEnabled(false);

                GitUtilities.GetRefs(UnityPackageUtilities.GetRepoHttpUrl(_packageInfo.packageId), _refs, CheckCurrentRef);

                SetVersion(_currentRefName);

                EditorApplication.delayCall += DisplayDetailControls;

                _currentHostData = PackageManagerSettings.GetHostData(_packageInfo.packageId);

                _hostingIcon.tooltip = $"View on {_currentHostData.Name}";
                _hostingIcon.style.backgroundImage = EditorGUIUtility.isProSkin ? _currentHostData.LogoLight : _currentHostData.LogoDark;
            }
        }
Exemplo n.º 3
0
        private void OnGUI()
        {
            EditorGUIUtility.labelWidth = 100;

            if (_focused &&
                (Event.current.keyCode == KeyCode.Return ||
                 Event.current.keyCode == KeyCode.Tab))
            {
                _ready   = true;
                _focused = false;
                GUI.FocusControl(null);
            }

            using (new EditorGUI.DisabledScope(UnityPackageUtilities.IsBusy))
            {
                using (new EditorGUILayout.HorizontalScope())
                {
                    GUI.SetNextControlName("Repository URL");
                    _url     = EditorGUILayout.TextField("Repository URL", _url);
                    _focused = GUI.GetNameOfFocusedControl().Equals("Repository URL");

                    if (_ready)
                    {
                        _ready     = false;
                        _repoUrl   = UnityPackageUtilities.GetRepoUrl(_url);
                        _version   = "-- Select Version --";
                        _packageId = string.Empty;
                        GitUtilities.GetRefs(_url, _refs, null);
                    }

                    if (!UnityPackageUtilities.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(OnVersionChanged);
                        }
                    }

                    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)))
                        {
                            UnityPackageUtilities.AddPackage(_packageId, CheckStatus);
                        }
                    }

                    if (_packageId == null)
                    {
                        GUILayout.Label(_errorBranch, GUILayout.Width(20));
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void InitializeUI()
        {
            if (_initialized)
            {
                return;
            }

            const string resourcesPath    = "Editor/Resources/";
            const string packagesRootPath = "Packages/com.xrtk.upm-git-extension/";

            var templatePath = $"{packagesRootPath}{resourcesPath}UpmGitExtension.uxml";
            var stylePath    = $"{packagesRootPath}{resourcesPath}UpmGitExtension.uss";

            var asset = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(templatePath);

            if (asset == null)
            {
                Debug.LogError("Failed to load package manager UI extension!");
                return;
            }

            _gitDetailActions = asset.CloneTree().Q("detailActions");
            _gitDetailActions.styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(stylePath));

            // Add callbacks
            _hostingIcon.clickable.clicked       += () => Application.OpenURL(UnityPackageUtilities.GetRepoHttpUrl(_packageInfo));
            _viewDocumentation.clickable.clicked += () => MarkdownUtilities.OpenInBrowser(UnityPackageUtilities.GetFilePath(_packageInfo, "README.*"));
            _viewChangelog.clickable.clicked     += () => MarkdownUtilities.OpenInBrowser(UnityPackageUtilities.GetFilePath(_packageInfo, "CHANGELOG.*"));
            _viewLicense.clickable.clicked       += () => MarkdownUtilities.OpenInBrowser(UnityPackageUtilities.GetFilePath(_packageInfo, "LICENSE.*"));

            // Move element to documentationContainer
            _detailControls         = parent.parent.Q("detailsControls") ?? parent.parent.parent.parent.Q("packageToolBar");
            _documentationContainer = parent.parent.Q("documentationContainer");
            _originalDetailActions  = _documentationContainer.Q("detailActions");
            _documentationContainer.Add(_gitDetailActions);

            _updateButton = new Button(AddOrUpdatePackage)
            {
                name = "update", text = "Up to date"
            };
            _updateButton.AddToClassList("action");
            _versionPopup = new Button(PopupVersions);
            _versionPopup.AddToClassList("popup");
            _versionPopup.AddToClassList("popupField");
            _versionPopup.AddToClassList("versions");

            if (_detailControls.name == "packageToolBar")
            {
                _hostingIcon.style.borderLeftWidth  = 0;
                _hostingIcon.style.borderRightWidth = 0;
                _versionPopup.style.marginLeft      = -10;
                _detailControls.Q("rightItems").Insert(1, _updateButton);
                _detailControls.Q("rightItems").Insert(2, _versionPopup);
            }
            else
            {
                _versionPopup.style.marginLeft   = -4;
                _versionPopup.style.marginRight  = -3;
                _versionPopup.style.marginTop    = -3;
                _versionPopup.style.marginBottom = -3;
                _detailControls.Q("updateCombo").Insert(1, _updateButton);
                _detailControls.Q("updateDropdownContainer").Add(_versionPopup);
            }

            // Add package button
            var root = UIUtilities.GetRoot(_gitDetailActions);

            _originalAddButton = root.Q("toolbarAddButton") ?? root.Q("moreAddOptionsButton");
            _addButton         = new Button(AddPackage)
            {
                name = "moreAddOptionsButton", text = "+"
            };
            _addButton.AddToClassList("toolbarButton");
            _addButton.AddToClassList("space");
            _addButton.AddToClassList("pulldown");
            _originalAddButton.parent.Insert(_originalAddButton.parent.IndexOf(_originalAddButton) + 1, _addButton);
            _initialized = true;
        }