public DocumentActions(VisualElement detailActions) { originDetailActions = detailActions; originDetailActions.parent.Add(this); VisualTreeAsset asset = EditorGUIUtility.Load(TemplatePath) as VisualTreeAsset; #if UNITY_2019_1_OR_NEWER root = asset.CloneTree(); styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet> (StylePath)); #else root = asset.CloneTree(null); AddStyleSheetPath(StylePath); #endif Add(root); // Find ui elements. hostButton = root.Q <Button> ("hostButton"); viewDocumentationButton = root.Q <Button> ("viewDocumentationButton"); viewChangelogButton = root.Q <Button> ("viewChangelogButton"); viewLicenseButton = root.Q <Button> ("viewLicenseButton"); // Adjust host icon. hostButton.RemoveFromClassList("unity-button"); hostButton.RemoveFromClassList("button"); // Add callbacks hostButton.clickable.clicked += () => Application.OpenURL(PackageUtils.GetRepoHttpUrl(packageInfo)); viewDocumentationButton.clickable.clicked += () => MarkdownUtils.OpenInBrowser(PackageUtils.GetFilePath(packageInfo, "README.*")); viewChangelogButton.clickable.clicked += () => MarkdownUtils.OpenInBrowser(PackageUtils.GetFilePath(packageInfo, "CHANGELOG.*")); viewLicenseButton.clickable.clicked += () => MarkdownUtils.OpenInBrowser(PackageUtils.GetFilePath(packageInfo, "LICENSE.*")); }
void onClick_InstallPackage() { PackageUtils.InstallPackage(packageNameLabel.text, GetRepoUrl(repoUrlText.value), refName); onClick_Close(); }
/// <summary> /// Initializes UI. /// </summary> void InitializeUI() { if (_initialized) { return; } var asset = AssetDatabase.LoadAssetAtPath <VisualTreeAsset> (TemplatePath); if (!asset) { return; } #if UNITY_2019_1_OR_NEWER _gitDetailActoins = asset.CloneTree().Q("detailActions"); _gitDetailActoins.styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet> (StylePath)); #else _gitDetailActoins = asset.CloneTree(null).Q("detailActions"); _gitDetailActoins.AddStyleSheetPath(StylePath); #endif // Add callbacks _hostingIcon.clickable.clicked += () => Application.OpenURL(PackageUtils.GetRepoHttpUrl(_packageInfo)); _viewDocumentation.clickable.clicked += () => MarkdownUtils.OpenInBrowser(PackageUtils.GetFilePath(_packageInfo, "README.*")); _viewChangelog.clickable.clicked += () => MarkdownUtils.OpenInBrowser(PackageUtils.GetFilePath(_packageInfo, "CHANGELOG.*")); _viewLicense.clickable.clicked += () => MarkdownUtils.OpenInBrowser(PackageUtils.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(_gitDetailActoins); _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 = UIUtils.GetRoot(_gitDetailActoins); _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; }
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); }); }