CollabHistoryDropDown.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. using UnityEditor.Connect;
  4. #if UNITY_2019_1_OR_NEWER
  5. using UnityEngine.UIElements;
  6. #else
  7. using UnityEngine.Experimental.UIElements;
  8. #endif
  9. namespace UnityEditor.Collaboration
  10. {
  11. internal class CollabHistoryDropDown : VisualElement
  12. {
  13. private readonly VisualElement m_FilesContainer;
  14. private readonly Label m_ToggleLabel;
  15. private int m_ChangesTotal;
  16. private string m_RevisionId;
  17. public CollabHistoryDropDown(ICollection<ChangeData> changes, int changesTotal, bool changesTruncated, string revisionId)
  18. {
  19. m_FilesContainer = new VisualElement();
  20. m_ChangesTotal = changesTotal;
  21. m_RevisionId = revisionId;
  22. m_ToggleLabel = new Label(ToggleText(false));
  23. m_ToggleLabel.AddManipulator(new Clickable(ToggleDropdown));
  24. Add(m_ToggleLabel);
  25. foreach (ChangeData change in changes)
  26. {
  27. m_FilesContainer.Add(new CollabHistoryDropDownItem(change.path, change.action));
  28. }
  29. if (changesTruncated)
  30. {
  31. m_FilesContainer.Add(new Button(ShowAllClick)
  32. {
  33. text = "Show all on dashboard"
  34. });
  35. }
  36. }
  37. private void ToggleDropdown()
  38. {
  39. if (Contains(m_FilesContainer))
  40. {
  41. CollabAnalytics.SendUserAction(CollabAnalytics.historyCategoryString, "CollapseAssets");
  42. Remove(m_FilesContainer);
  43. m_ToggleLabel.text = ToggleText(false);
  44. }
  45. else
  46. {
  47. CollabAnalytics.SendUserAction(CollabAnalytics.historyCategoryString, "ExpandAssets");
  48. Add(m_FilesContainer);
  49. m_ToggleLabel.text = ToggleText(true);
  50. }
  51. }
  52. private string ToggleText(bool open)
  53. {
  54. var icon = open ? "\u25bc" : "\u25b6";
  55. var change = m_ChangesTotal == 1 ? "Change" : "Changes";
  56. return string.Format("{0} {1} Asset {2}", icon, m_ChangesTotal, change);
  57. }
  58. private void ShowAllClick()
  59. {
  60. var host = UnityConnect.instance.GetConfigurationURL(CloudConfigUrl.CloudServicesDashboard);
  61. var org = UnityConnect.instance.GetOrganizationId();
  62. var proj = UnityConnect.instance.GetProjectGUID();
  63. var url = string.Format("{0}/collab/orgs/{1}/projects/{2}/commits?commit={3}", host, org, proj, m_RevisionId);
  64. CollabAnalytics.SendUserAction(CollabAnalytics.historyCategoryString, "ShowAllOnDashboard");
  65. Application.OpenURL(url);
  66. }
  67. }
  68. }