No Description
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.

WelcomeView.cs 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. using Codice.Client.BaseCommands;
  2. using Codice.Client.Common;
  3. using PlasticGui;
  4. using PlasticGui.WebApi;
  5. using Unity.PlasticSCM.Editor.AssetUtils;
  6. using Unity.PlasticSCM.Editor.Configuration.CloudEdition.Welcome;
  7. using Unity.PlasticSCM.Editor.Configuration.TeamEdition;
  8. using Unity.PlasticSCM.Editor.UI;
  9. using Unity.PlasticSCM.Editor.UI.Progress;
  10. using Unity.PlasticSCM.Editor.Views.CreateWorkspace;
  11. using UnityEditor;
  12. using UnityEngine;
  13. namespace Unity.PlasticSCM.Editor.Views.Welcome
  14. {
  15. internal class WelcomeView
  16. {
  17. internal WelcomeView(
  18. PlasticWindow parentWindow,
  19. CreateWorkspaceView.ICreateWorkspaceListener createWorkspaceListener,
  20. IPlasticAPI plasticApi,
  21. IPlasticWebRestApi plasticWebRestApi,
  22. CmConnection cmConnection)
  23. {
  24. mParentWindow = parentWindow;
  25. mCreateWorkspaceListener = createWorkspaceListener;
  26. mPlasticApi = plasticApi;
  27. mPlasticWebRestApi = plasticWebRestApi;
  28. mCmConnection = cmConnection;
  29. mConfigureProgress = new ProgressControlsForViews();
  30. autoLoginState = AutoLogin.State.Off;
  31. }
  32. internal void Update()
  33. {
  34. if (mCreateWorkspaceView != null)
  35. mCreateWorkspaceView.Update();
  36. mConfigureProgress.UpdateDeterminateProgress(mParentWindow);
  37. }
  38. internal void OnGUI(bool clientNeedsConfiguration)
  39. {
  40. GUILayout.BeginHorizontal();
  41. GUILayout.Space(LEFT_MARGIN);
  42. DoContentViewArea(
  43. clientNeedsConfiguration,
  44. mIsCreateWorkspaceButtonClicked);
  45. GUILayout.EndHorizontal();
  46. }
  47. internal void OnUserClosedConfigurationWindow()
  48. {
  49. ((IProgressControls)mConfigureProgress).HideProgress();
  50. ClientConfig.Reset();
  51. CmConnection.Reset();
  52. ClientHandlers.Register();
  53. }
  54. void DoContentViewArea(
  55. bool clientNeedsConfiguration,
  56. bool isCreateWorkspaceButtonClicked)
  57. {
  58. GUILayout.BeginVertical();
  59. GUILayout.Space(TOP_MARGIN);
  60. if (isCreateWorkspaceButtonClicked)
  61. GetCreateWorkspaceView().OnGUI();
  62. else
  63. DoSetupViewArea(
  64. clientNeedsConfiguration,
  65. mConfigureProgress);
  66. GUILayout.EndVertical();
  67. }
  68. void DoSetupViewArea(
  69. bool clientNeedsConfiguration,
  70. ProgressControlsForViews configureProgress)
  71. {
  72. DoTitleLabel();
  73. GUILayout.Space(STEPS_TOP_MARGIN);
  74. bool isStep1Completed =
  75. !clientNeedsConfiguration &&
  76. !configureProgress.ProgressData.IsOperationRunning;
  77. DoStepsArea(isStep1Completed, configureProgress.ProgressData);
  78. GUILayout.Space(BUTTON_MARGIN);
  79. DoActionButtonsArea(
  80. isStep1Completed,
  81. configureProgress);
  82. DoNotificationArea(configureProgress.ProgressData);
  83. }
  84. void DoActionButtonsArea(
  85. bool isStep1Completed,
  86. ProgressControlsForViews configureProgress)
  87. {
  88. DoActionButton(
  89. isStep1Completed,
  90. configureProgress);
  91. }
  92. void DoActionButton(
  93. bool isStep1Completed,
  94. ProgressControlsForViews configureProgress)
  95. {
  96. if (!isStep1Completed)
  97. {
  98. DoConfigureButton(configureProgress);
  99. return;
  100. }
  101. if (GUILayout.Button(
  102. PlasticLocalization.GetString(PlasticLocalization.Name.CreateWorkspace),
  103. GUILayout.Width(BUTTON_WIDTH)))
  104. mIsCreateWorkspaceButtonClicked = true;
  105. }
  106. void DoConfigureButton(ProgressControlsForViews configureProgress)
  107. {
  108. bool isAutoLoginRunning = autoLoginState > AutoLogin.State.Running && autoLoginState <= AutoLogin.State.InitializingPlastic;
  109. GUI.enabled = !(configureProgress.ProgressData.IsOperationRunning || isAutoLoginRunning);
  110. if (GUILayout.Button(PlasticLocalization.GetString(
  111. PlasticLocalization.Name.LoginOrSignUp),
  112. GUILayout.Width(BUTTON_WIDTH)))
  113. {
  114. if (autoLoginState > AutoLogin.State.Off && autoLoginState <= AutoLogin.State.InitializingPlastic)
  115. {
  116. autoLoginState = AutoLogin.State.Running;
  117. AutoLogin autoLogin = new AutoLogin();
  118. autoLogin.Run();
  119. }
  120. if (autoLoginState != AutoLogin.State.ErrorNoToken)
  121. {
  122. return;
  123. }
  124. ((IProgressControls)configureProgress).ShowProgress(string.Empty);
  125. // Login button defaults to Cloud sign up
  126. CloudEditionWelcomeWindow.ShowWindow(
  127. mPlasticWebRestApi,
  128. mCmConnection,
  129. this);
  130. GUIUtility.ExitGUI();
  131. }
  132. // If client configuration cannot be determined, keep login button default as Cloud
  133. // sign in window, but show Enterprise option as well
  134. GUILayout.FlexibleSpace();
  135. var anchorStyle = new GUIStyle(GUI.skin.label);
  136. anchorStyle.normal.textColor = new Color(0.129f, 0.588f, 0.953f);
  137. anchorStyle.hover.textColor = new Color(0.239f, 0.627f, 0.949f);
  138. anchorStyle.active.textColor = new Color(0.239f, 0.627f, 0.949f);
  139. if (GUILayout.Button(
  140. PlasticLocalization.GetString(
  141. PlasticLocalization.Name.NeedEnterprise),
  142. anchorStyle,
  143. GUILayout.Width(BUTTON_WIDTH),
  144. GUILayout.Height(20)))
  145. TeamEditionConfigurationWindow.ShowWindow(mPlasticWebRestApi, this);
  146. GUILayout.Space(BUTTON_MARGIN);
  147. GUI.enabled = true;
  148. }
  149. static void DoStepsArea(
  150. bool isStep1Completed,
  151. ProgressControlsForViews.Data configureProgressData)
  152. {
  153. DoLoginOrSignUpStep(isStep1Completed, configureProgressData);
  154. DoCreatePlasticWorkspaceStep();
  155. }
  156. static void DoLoginOrSignUpStep(
  157. bool isStep1Completed,
  158. ProgressControlsForViews.Data progressData)
  159. {
  160. Texture2D stepImage = (isStep1Completed) ? Images.GetStepOkIcon() : Images.GetStep1Icon();
  161. string stepText = GetConfigurationStepText(progressData, isStep1Completed);
  162. GUIStyle style = new GUIStyle(EditorStyles.label);
  163. style.richText = true;
  164. GUILayout.BeginHorizontal();
  165. DoStepLabel(stepText, stepImage, style);
  166. GUILayout.EndHorizontal();
  167. }
  168. static void DoCreatePlasticWorkspaceStep()
  169. {
  170. GUILayout.BeginHorizontal();
  171. DoStepLabel(
  172. PlasticLocalization.GetString(PlasticLocalization.Name.CreateAUnityVersionControlWorkspace),
  173. Images.GetStep2Icon(),
  174. EditorStyles.label);
  175. GUILayout.EndHorizontal();
  176. }
  177. static void DoStepLabel(
  178. string text,
  179. Texture2D image,
  180. GUIStyle style)
  181. {
  182. GUILayout.Space(STEPS_LEFT_MARGIN);
  183. GUIContent stepLabelContent = new GUIContent(
  184. string.Format(" {0}", text),
  185. image);
  186. GUILayout.Label(
  187. stepLabelContent,
  188. style,
  189. GUILayout.Height(STEP_LABEL_HEIGHT));
  190. }
  191. static void DoTitleLabel()
  192. {
  193. GUIContent labelContent = new GUIContent(
  194. PlasticLocalization.GetString(PlasticLocalization.Name.NextStepsToSetup),
  195. Images.GetInfoIcon());
  196. GUILayout.Label(labelContent, EditorStyles.boldLabel);
  197. }
  198. static void DoNotificationArea(ProgressControlsForViews.Data configureProgressData)
  199. {
  200. if (!string.IsNullOrEmpty(configureProgressData.NotificationMessage))
  201. DrawProgressForViews.ForNotificationArea(configureProgressData);
  202. }
  203. static string GetConfigurationStepText(
  204. ProgressControlsForViews.Data progressData,
  205. bool isStep1Completed)
  206. {
  207. string result = PlasticLocalization.GetString(
  208. PlasticLocalization.Name.LoginOrSignUpUnityVersionControl);
  209. if (isStep1Completed)
  210. return result;
  211. if (!progressData.IsOperationRunning)
  212. return result;
  213. return string.Format("<b>{0}</b>", result);
  214. }
  215. CreateWorkspaceView GetCreateWorkspaceView()
  216. {
  217. if (mCreateWorkspaceView != null)
  218. return mCreateWorkspaceView;
  219. string workspacePath = ProjectPath.FromApplicationDataPath(
  220. ApplicationDataPath.Get());
  221. mCreateWorkspaceView = new CreateWorkspaceView(
  222. mParentWindow,
  223. mCreateWorkspaceListener,
  224. mPlasticApi,
  225. mPlasticWebRestApi,
  226. workspacePath);
  227. return mCreateWorkspaceView;
  228. }
  229. internal AutoLogin.State autoLoginState = AutoLogin.State.Off;
  230. bool mIsCreateWorkspaceButtonClicked = false;
  231. CreateWorkspaceView mCreateWorkspaceView;
  232. readonly ProgressControlsForViews mConfigureProgress;
  233. readonly CmConnection mCmConnection;
  234. readonly IPlasticAPI mPlasticApi;
  235. readonly IPlasticWebRestApi mPlasticWebRestApi;
  236. readonly CreateWorkspaceView.ICreateWorkspaceListener mCreateWorkspaceListener;
  237. readonly PlasticWindow mParentWindow;
  238. const int LEFT_MARGIN = 30;
  239. const int TOP_MARGIN = 20;
  240. const int STEPS_TOP_MARGIN = 5;
  241. const int STEPS_LEFT_MARGIN = 12;
  242. const int BUTTON_MARGIN = 10;
  243. const int STEP_LABEL_HEIGHT = 20;
  244. const int BUTTON_WIDTH = 170;
  245. }
  246. }