Beispiel #1
0
        public void ShowInputDropdown(InputDropdownArgs args)
        {
            var rect     = GUIUtility.GUIToScreenRect(worldBound);
            var dropdown = new GenericInputDropdown(m_ResourceLoader, PackageManagerWindow.instance, args)
            {
                position = rect
            };

            DropdownContainer.ShowDropdown(dropdown);
        }
        private void Init(EditorWindow anchorWindow, InputDropdownArgs args)
        {
            m_AnchorWindow = anchorWindow;

            m_WindowSize = args.windowSize ?? k_DefaultWindowSize;

            inputTextField.value = args.defaultValue ?? string.Empty;
            inputTextField.RegisterCallback <ChangeEvent <string> >(OnTextFieldChange);
            inputTextField.RegisterCallback <KeyDownEvent>(OnKeyDownShortcut);

            m_InputPlaceholder      = new TextFieldPlaceholder(inputTextField);
            m_InputPlaceholder.text = args.placeholderText ?? string.Empty;

            mainTitle.text = args.title ?? string.Empty;
            UIUtils.SetElementDisplay(mainTitle, !string.IsNullOrEmpty(mainTitle.text));

            var showIcon = false;

            if (!string.IsNullOrEmpty(args.iconUssClass))
            {
                showIcon = true;
                icon.AddToClassList(args.iconUssClass);
            }
            else if (args.icon != null)
            {
                showIcon = true;
                icon.style.backgroundImage = new StyleBackground((Background)args.icon);
            }
            UIUtils.SetElementDisplay(icon, showIcon);

            submitButton.clickable.clicked += SubmitClicked;
            submitButton.SetEnabled(!string.IsNullOrWhiteSpace(inputTextField.value));
            submitButton.text = !string.IsNullOrEmpty(args.submitButtonText) ? args.submitButtonText : k_DefaultSubmitButtonText;
            if (args.onInputSubmitted != null)
            {
                submitClicked = args.onInputSubmitted;
            }
        }
        public GenericInputDropdown(ResourceLoader resourceLoader, EditorWindow anchorWindow, InputDropdownArgs args)
        {
            ResolveDependencies(resourceLoader);

            styleSheets.Add(m_ResourceLoader.inputDropdownStyleSheet);

            var root = m_ResourceLoader.GetTemplate("GenericInputDropdown.uxml");

            Add(root);
            cache = new VisualElementCache(root);

            Init(anchorWindow, args);
        }
Beispiel #4
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);
            };
        }