Brak opisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PlasticSCMWindow.cs 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using PlasticGui;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Unity.PlasticSCM.Editor.UI;
  5. using Unity.PlasticSCM.Editor.UI.UIElements;
  6. using UnityEditor;
  7. using UnityEngine;
  8. using UnityEngine.UIElements;
  9. namespace Unity.PlasticSCM.Editor
  10. {
  11. internal class PlasticSCMWindow : EditorWindow
  12. {
  13. internal static void ShowWindow()
  14. {
  15. PlasticSCMWindow window = GetWindow<PlasticSCMWindow>();
  16. window.titleContent = new GUIContent(
  17. UnityConstants.PLASTIC_WINDOW_TITLE,
  18. Images.GetPlasticViewIcon());
  19. window.minSize= new Vector2(750, 260);
  20. window.Show();
  21. }
  22. void OnEnable()
  23. {
  24. BuildComponents();
  25. }
  26. void OnDestroy()
  27. {
  28. Dispose();
  29. }
  30. void Dispose()
  31. {
  32. mRefreshButton.clicked -= RefreshButton_Clicked;
  33. mSettingsButton.clicked -= SettingsButton_Clicked;
  34. }
  35. void BuildComponents()
  36. {
  37. VisualElement root = rootVisualElement;
  38. root.Clear();
  39. root.LoadStyle("PlasticWindow/PlasticWindow");
  40. BuildTabview(root);
  41. BuildStatusBar(root);
  42. }
  43. /*** Tabview ***/
  44. void BuildTabview(VisualElement root)
  45. {
  46. mTabView = new TabView();
  47. mTabView.LoadStyle("PlasticWindow/PlasticWindow");
  48. mTabView.AddTab(
  49. PlasticLocalization.GetString(PlasticLocalization.Name.PendingChangesViewTitle),
  50. new VisualElement()).clicked += () =>
  51. {
  52. // TODO: Add view switch to Pending Changes here
  53. };
  54. mTabView.AddTab(
  55. PlasticLocalization.GetString(PlasticLocalization.Name.ChangesetsViewTitle),
  56. new VisualElement()).clicked += () =>
  57. {
  58. // TODO: Add view switch to Changesets here
  59. };
  60. mTabView.AddTab(
  61. PlasticLocalization.GetString(PlasticLocalization.Name.IncomingChangesViewTitle),
  62. new VisualElement()).clicked += () =>
  63. {
  64. // TODO: Add view switch to Incoming Changes here
  65. };
  66. VisualElement controlsContainer = new VisualElement() { name = "ControlsContainer" };
  67. controlsContainer.AddToClassList("row");
  68. mRefreshButton = new Button() { name = "RefreshButton" };
  69. mRefreshButton.Add(new Image() { image = Images.GetRefreshIcon() });
  70. mRefreshButton.clicked += RefreshButton_Clicked;
  71. controlsContainer.Add(mRefreshButton);
  72. mSettingsButton = new Button() { name = "SettingsButton" };
  73. mSettingsButton.Add(new Image() { image = EditorGUIUtility.IconContent("settings").image });
  74. mSettingsButton.clicked += SettingsButton_Clicked;
  75. controlsContainer.Add(mSettingsButton);
  76. var tabArea = mTabView.Q<VisualElement>("TabArea");
  77. tabArea.Add(controlsContainer);
  78. root.Add(mTabView);
  79. }
  80. void RefreshButton_Clicked()
  81. {
  82. // TODO
  83. }
  84. void SettingsButton_Clicked()
  85. {
  86. GenericMenu menu = new GenericMenu();
  87. menu.AddItem(new GUIContent("Invite Members to Workspace"),
  88. false,
  89. InviteMemberButton_clicked,
  90. null);
  91. menu.ShowAsContext();
  92. }
  93. static void InviteMemberButton_clicked(object obj)
  94. {
  95. Application.OpenURL("https://www.plasticscm.com/dashboard/cloud/unity_cloud/users-and-groups");
  96. }
  97. /*** Update Bar ***/
  98. void BuildStatusBar(VisualElement root)
  99. {
  100. VisualElement StatusBar = new VisualElement() { name = "StatusBar" };
  101. StatusBar.AddToClassList("row");
  102. StatusBar.LoadLayout("PlasticWindow/StatusBar");
  103. mUpdateNotification = StatusBar.Q<VisualElement>("UpdateNotificationContainer");
  104. mUpdateNotificaionImage = StatusBar.Q<Image>("UpdateNotificationImage");
  105. mUpdateNotificationLabel = StatusBar.Q<Label>("UpdateNotificationLabel");
  106. mUpdateButton = StatusBar.Q<Button>("UpdateButton");
  107. mUpdateButton.text = PlasticLocalization.GetString(PlasticLocalization.Name.UpdateButton);
  108. mBranchLabel = StatusBar.Q<Label>("BranchLabel");
  109. mBranchLabel.text = "Branch main @ codice @ codice@cloud";
  110. ShowUpdateNotification(false);
  111. root.Add(StatusBar);
  112. }
  113. // For the icon string, the name of unity icons can be found at
  114. // https://unitylist.com/p/5c3/Unity-editor-icons
  115. internal void ShowUpdateNotification(bool show, string icon = "", string notification = "")
  116. {
  117. if (!string.IsNullOrEmpty(icon))
  118. mUpdateNotificaionImage.image = EditorGUIUtility.IconContent(icon).image;
  119. if (!string.IsNullOrEmpty(notification))
  120. mUpdateNotificationLabel.text = notification;
  121. if (show)
  122. mUpdateNotification.RemoveFromClassList("display-none");
  123. else
  124. mUpdateNotification.AddToClassList("display-none");
  125. }
  126. // Tabview variables
  127. internal TabView mTabView;
  128. Button mRefreshButton;
  129. Button mSettingsButton;
  130. // Update bar variables
  131. VisualElement mUpdateNotification;
  132. Image mUpdateNotificaionImage;
  133. Label mUpdateNotificationLabel;
  134. Button mUpdateButton;
  135. Label mBranchLabel;
  136. }
  137. }