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.

TeamEditionConfigurationWindow.cs 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. using System;
  2. using UnityEditor;
  3. using UnityEngine;
  4. using UnityEngine.UIElements;
  5. using PlasticGui;
  6. using Codice.CM.Common;
  7. using Codice.Client.Common;
  8. using Unity.PlasticSCM.Editor.UI.UIElements;
  9. using PlasticGui.Configuration.TeamEdition;
  10. using PlasticGui.Configuration;
  11. using PlasticGui.WebApi;
  12. using Unity.PlasticSCM.Editor.Views.Welcome;
  13. namespace Unity.PlasticSCM.Editor.Configuration.TeamEdition
  14. {
  15. internal class TeamEditionConfigurationWindow : EditorWindow
  16. {
  17. internal static void ShowWindow(IPlasticWebRestApi restApi, WelcomeView welcomeView)
  18. {
  19. TeamEditionConfigurationWindow window = GetWindow<TeamEditionConfigurationWindow>();
  20. window.mRestApi = restApi;
  21. window.mWelcomeView = welcomeView;
  22. window.titleContent = new GUIContent(
  23. PlasticLocalization.GetString(PlasticLocalization.Name.WelcomeToUnityVCS));
  24. window.minSize = window.maxSize = new Vector2(650, 300);
  25. window.Show();
  26. }
  27. void OnEnable()
  28. {
  29. InitializeLayoutAndStyles();
  30. BuildComponents();
  31. }
  32. void Dispose()
  33. {
  34. mConnectButton.clicked -= ConnectButton_Clicked;
  35. mCheckConnectionButton.clicked -= CheckConnectionButton_Clicked;
  36. mOkButton.clicked -= OkButton_Clicked;
  37. mCancelButton.clicked -= CancelButton_Clicked;
  38. mServerTextField.UnregisterValueChangedCallback(OnServerTextFieldChanged);
  39. mUseSslToggle.UnregisterValueChangedCallback(OnUseSslToggleChanged);
  40. mLoadingSpinner.Dispose();
  41. }
  42. void ConnectButton_Clicked()
  43. {
  44. ConfigurationConnectServerButtonClickEvent.Click(
  45. server: mUserAssistant.GetProposedServer(),
  46. HideValidation: HideValidation,
  47. ShowError: ShowServerValidationError,
  48. ShowProgress: ShowProgress,
  49. HideProgress: HideProgress,
  50. ShowNotification: ShowServerNotificationMessage,
  51. DisableButtons: () => { mConnectButton.SetEnabled(false); },
  52. EnableButtons: () => { mConnectButton.SetEnabled(true); },
  53. UpdatePasswordEntries: (seidWorkingMode) =>
  54. {
  55. UpdatePasswordEntries(ValidateServerAndCreds.
  56. IsPasswordRequired(seidWorkingMode));
  57. },
  58. NotifyWorkingMode: (mode) => { mSEIDWorkingMode = mode; },
  59. NotifyConnectedStatus: (b) => { });
  60. mUserTextField.SetEnabled(true);
  61. }
  62. void OnDestroy()
  63. {
  64. Dispose();
  65. if (mWelcomeView != null)
  66. mWelcomeView.OnUserClosedConfigurationWindow();
  67. }
  68. void CheckConnectionButton_Clicked()
  69. {
  70. ConfigurationCheckCredentialsButtonClickEvent.Click(
  71. mSEIDWorkingMode,
  72. mUserTextField.value,
  73. mPasswordTextField.value,
  74. Edition.Team,
  75. mUserAssistant,
  76. HideCredentialsValidationError,
  77. ShowCheckCredentialsError,
  78. ShowProgress,
  79. HideProgress,
  80. ShowNotification: ShowCredentialsNotificationMessage,
  81. DisableButtons: () => { mCheckConnectionButton.SetEnabled(false); mConnectButton.SetEnabled(false); },
  82. EnableButtons: () => { mCheckConnectionButton.SetEnabled(true); mConnectButton.SetEnabled(true); },
  83. NotifyWorkingMode: (mode) => { mSEIDWorkingMode = mode; },
  84. NotifyConnectedStatus: (status) => { },
  85. restApi: mRestApi,
  86. cmConnection: CmConnection.Get());
  87. }
  88. void CancelButton_Clicked()
  89. {
  90. Close();
  91. }
  92. void OkButton_Clicked()
  93. {
  94. if (!ValidateServerAndCreds.IsValidInput(
  95. mUserAssistant.GetProposedServer(),
  96. mUserTextField.value,
  97. mSEIDWorkingMode,
  98. mPasswordTextField.value,
  99. ShowCheckCredentialsError))
  100. {
  101. return;
  102. }
  103. ConfigurationActions.SaveClientConfig(
  104. mServerTextField.value,
  105. mSEIDWorkingMode,
  106. mUserTextField.value,
  107. mPasswordTextField.value);
  108. Close();
  109. }
  110. void HideCredentialsValidationError()
  111. {
  112. mCredentialsLabel.RemoveFromClassList("error");
  113. mCredentialsLabel.Hide();
  114. }
  115. void BuildComponents()
  116. {
  117. VisualElement root = rootVisualElement;
  118. root.Query<Label>("plasticConfigurationTitle").First().text =
  119. PlasticLocalization.GetString(PlasticLocalization.Name.PlasticConfigurationTitleUnityVCS);
  120. root.SetControlText<Label>(
  121. "plasticConfigurationExplanation",
  122. PlasticLocalization.Name.PlasticConfigurationExplanation);
  123. root.SetControlText<Label>("configurationServerInfo",
  124. PlasticLocalization.Name.PlasticSCMServerLabel);
  125. root.SetControlText<Button>(
  126. "connect",
  127. PlasticLocalization.Name.Connect);
  128. root.SetControlText<Label>("useSsl",
  129. PlasticLocalization.Name.UseSsl);
  130. root.SetControlText<Label>("configurationUserNameInfo",
  131. PlasticLocalization.Name.ConfigurationUserNameInfo);
  132. root.SetControlText<Label>("configurationCredentialsInfo",
  133. PlasticLocalization.Name.ConfigurationCredentialsInfo);
  134. root.SetControlText<Button>("check",
  135. PlasticLocalization.Name.Check);
  136. root.SetControlText<Label>("credentialsOk",
  137. PlasticLocalization.Name.CredentialsOK);
  138. root.SetControlText<Button>("okButton",
  139. PlasticLocalization.Name.OkButton);
  140. root.SetControlText<Button>("cancelButton",
  141. PlasticLocalization.Name.CancelButton);
  142. mSpinnerContainer = root.Query<VisualElement>("spinnerContainer").First();
  143. mSpinnerLabel = root.Query<Label>("spinnerLabel").First();
  144. mLoadingSpinner = new LoadingSpinner();
  145. mSpinnerContainer.Add(mLoadingSpinner);
  146. mSpinnerContainer.Hide();
  147. mCheckConnectionButton = root.Query<Button>("check").First();
  148. mCheckConnectionButton.clicked += CheckConnectionButton_Clicked;
  149. mConnectButton = root.Query<Button>("connect").First();
  150. mConnectButton.clicked += ConnectButton_Clicked;
  151. mServerTextField = root.Query<TextField>("serverTextField").First();
  152. mServerTextField.RegisterValueChangedCallback(OnServerTextFieldChanged);
  153. mUseSslToggle = root.Query<Toggle>("useSslToogle").First();
  154. mUseSslToggle.RegisterValueChangedCallback(OnUseSslToggleChanged);
  155. mUserTextField = root.Query<TextField>("userTextField").First();
  156. mUserTextField.SetEnabled(false);
  157. mPasswordTextField = root.Query<TextField>("passwordTextField").First();
  158. mPasswordTextField.isPasswordField = true;
  159. mConnectedLabel = root.Query<Label>("connectedLabel").First();
  160. mCredentialsLabel = root.Query<Label>("credentialsOk").First();
  161. mOkButton = root.Query<Button>("okButton").First();
  162. mOkButton.clicked += OkButton_Clicked;
  163. mCancelButton = root.Query<Button>("cancelButton").First();
  164. mCancelButton.clicked += CancelButton_Clicked;
  165. }
  166. void OnUseSslToggleChanged(ChangeEvent<bool> evt)
  167. {
  168. mUserAssistant.OnSslChanged(mServerTextField.value, evt.newValue);
  169. mServerTextField.value = mUserAssistant.GetProposedServer();
  170. }
  171. void InitializeLayoutAndStyles()
  172. {
  173. VisualElement root = rootVisualElement;
  174. root.LoadLayout(typeof(TeamEditionConfigurationWindow).Name);
  175. root.LoadStyle(typeof(TeamEditionConfigurationWindow).Name);
  176. }
  177. void OnServerTextFieldChanged(ChangeEvent<string> evt)
  178. {
  179. mUserAssistant.OnServerChanged(evt.newValue);
  180. mUseSslToggle.value = mUserAssistant.IsSslServer(evt.newValue);
  181. }
  182. void ShowServerNotificationMessage(string message)
  183. {
  184. mConnectedLabel.text = message;
  185. mConnectedLabel.Show();
  186. }
  187. void ShowServerValidationError(string message)
  188. {
  189. mConnectedLabel.text = message;
  190. mConnectedLabel.AddToClassList("error");
  191. mConnectedLabel.Show();
  192. }
  193. void ShowCredentialsNotificationMessage(string message)
  194. {
  195. mCredentialsLabel.text = message;
  196. mCredentialsLabel.Show();
  197. }
  198. void ShowCheckCredentialsError(string message)
  199. {
  200. mCredentialsLabel.text = message;
  201. mCredentialsLabel.AddToClassList("error");
  202. mCredentialsLabel.Show();
  203. }
  204. void HideValidation()
  205. {
  206. mConnectedLabel.RemoveFromClassList("error");
  207. mConnectedLabel.Hide();
  208. }
  209. void ShowProgress(string text)
  210. {
  211. mSpinnerLabel.text = text;
  212. mSpinnerContainer.Show();
  213. mSpinnerLabel.Show();
  214. mLoadingSpinner.Start();
  215. }
  216. void HideProgress()
  217. {
  218. mLoadingSpinner.Stop();
  219. mSpinnerContainer.Hide();
  220. mSpinnerLabel.Hide();
  221. }
  222. void UpdatePasswordEntries(bool bIsPasswordRequired)
  223. {
  224. if (!bIsPasswordRequired)
  225. {
  226. mPasswordTextField.Collapse();
  227. mUserTextField.SetEnabled(false);
  228. mUserTextField.value = Environment.UserName;
  229. return;
  230. }
  231. mUserTextField.SetEnabled(true);
  232. mPasswordTextField.Show();
  233. mUserTextField.SelectAll();
  234. mUserTextField.FocusWorkaround();
  235. }
  236. Button mConnectButton;
  237. Label mConnectedLabel;
  238. TextField mServerTextField;
  239. TextField mPasswordTextField;
  240. Toggle mUseSslToggle;
  241. LoadingSpinner mLoadingSpinner;
  242. Label mSpinnerLabel;
  243. VisualElement mSpinnerContainer;
  244. Button mCheckConnectionButton;
  245. Label mCredentialsLabel;
  246. Button mOkButton;
  247. Button mCancelButton;
  248. SEIDWorkingMode mSEIDWorkingMode = SEIDWorkingMode.UPWorkingMode;
  249. ConfigurationDialogUserAssistant mUserAssistant =
  250. new ConfigurationDialogUserAssistant();
  251. IPlasticWebRestApi mRestApi;
  252. WelcomeView mWelcomeView;
  253. TextField mUserTextField;
  254. }
  255. }