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.

DownloadPlasticExeWindow.cs 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. using UnityEditor;
  2. using UnityEngine;
  3. using UnityEngine.UIElements;
  4. using Codice.Client.Common;
  5. using Codice.Client.Common.EventTracking;
  6. using Codice.CM.Common;
  7. using PlasticGui;
  8. using Unity.PlasticSCM.Editor.UI.UIElements;
  9. using Unity.PlasticSCM.Editor.Views.Welcome;
  10. using Unity.PlasticSCM.Editor.Tool;
  11. namespace Unity.PlasticSCM.Editor.Views
  12. {
  13. internal class DownloadPlasticExeWindow :
  14. EditorWindow,
  15. DownloadAndInstallOperation.INotify
  16. {
  17. internal bool IsPlasticInstalling { get { return mIsPlasticInstalling; } }
  18. internal static void ShowWindow(
  19. RepositorySpec repSpec,
  20. bool isGluonMode,
  21. string installCloudFrom,
  22. string installEnterpriseFrom,
  23. string cancelInstallFrom)
  24. {
  25. DownloadPlasticExeWindow window = GetWindow<DownloadPlasticExeWindow>();
  26. window.mRepSpec = repSpec;
  27. window.mIsGluonMode = isGluonMode;
  28. window.mInstallCloudFrom = installCloudFrom;
  29. window.mInstallEnterpriseFrom = installEnterpriseFrom;
  30. window.mCancelInstallFrom = cancelInstallFrom;
  31. window.titleContent = new GUIContent(
  32. PlasticLocalization.GetString(PlasticLocalization.Name.UnityVersionControl));
  33. if (EditionToken.IsCloudEdition())
  34. window.minSize = window.maxSize = new Vector2(700, 160);
  35. else
  36. window.minSize = window.maxSize = new Vector2(700, 230);
  37. window.Show();
  38. }
  39. void DownloadAndInstallOperation.INotify.InstallationStarted()
  40. {
  41. mIsPlasticInstalling = true;
  42. }
  43. void DownloadAndInstallOperation.INotify.InstallationFinished()
  44. {
  45. mIsPlasticInstalling = false;
  46. }
  47. void OnEnable()
  48. {
  49. BuildComponents();
  50. mInstallerFile = GetInstallerTmpFileName.ForPlatform();
  51. }
  52. void OnDestroy()
  53. {
  54. Dispose();
  55. }
  56. void Dispose()
  57. {
  58. mDownloadCloudEditionButton.clicked -= DownloadCloudEditionButton_Clicked;
  59. if (!EditionToken.IsCloudEdition())
  60. mDownloadEnterpriseButton.clicked -= DownloadEnterpriseEditionButton_Clicked;
  61. mCancelButton.clicked -= CancelButton_Clicked;
  62. EditorApplication.update -= CheckForPlasticExe;
  63. }
  64. void DownloadCloudEditionButton_Clicked()
  65. {
  66. TrackFeatureUseEvent.For(mRepSpec, mInstallCloudFrom);
  67. DownloadAndInstallOperation.Run(
  68. Edition.Cloud,
  69. mInstallerFile,
  70. mProgressControls,
  71. this);
  72. EditorApplication.update += CheckForPlasticExe;
  73. }
  74. void DownloadEnterpriseEditionButton_Clicked()
  75. {
  76. TrackFeatureUseEvent.For(mRepSpec, mInstallEnterpriseFrom);
  77. DownloadAndInstallOperation.Run(
  78. Edition.Enterprise,
  79. mInstallerFile,
  80. mProgressControls,
  81. this);
  82. }
  83. void CancelButton_Clicked()
  84. {
  85. if (!IsExeAvailable.ForMode(mIsGluonMode))
  86. TrackFeatureUseEvent.For(mRepSpec, mCancelInstallFrom);
  87. Close();
  88. }
  89. void CheckForPlasticExe()
  90. {
  91. // executable becomes available halfway through the install
  92. // we do not want to say install is done too early
  93. // when progress control finishes, cancel button will be enabled
  94. // then we can check for exe existing
  95. if (mCancelButton.enabledSelf && IsExeAvailable.ForMode(mIsGluonMode))
  96. {
  97. mMessageLabel.text = "Unity Version Control installed. You can now use the feature.";
  98. mCancelButton.text =
  99. PlasticLocalization.GetString(PlasticLocalization.Name.CloseButton);
  100. mRequireMessageLabel.Collapse();
  101. mDownloadCloudEditionButton.Collapse();
  102. mDownloadEnterpriseButton.Collapse();
  103. }
  104. }
  105. void BuildComponents()
  106. {
  107. VisualElement root = rootVisualElement;
  108. root.Clear();
  109. InitializeLayoutAndStyles();
  110. mRequireMessageLabel = root.Q<Label>("requireMessage");
  111. mMessageLabel = root.Q<Label>("message");
  112. mDownloadCloudEditionButton = root.Q<Button>("downloadCloudEdition");
  113. mDownloadEnterpriseButton = root.Q<Button>("downloadEnterpriseEdition");
  114. mCancelButton = root.Q<Button>("cancel");
  115. mProgressControlsContainer = root.Q<VisualElement>("progressControlsContainer");
  116. root.Q<Label>("title").text =
  117. PlasticLocalization.GetString(PlasticLocalization.Name.InstallUnityVersionControl);
  118. mDownloadCloudEditionButton.text =
  119. PlasticLocalization.GetString(PlasticLocalization.Name.DownloadCloudEdition);
  120. mDownloadCloudEditionButton.clicked += DownloadCloudEditionButton_Clicked;
  121. if (EditionToken.IsCloudEdition())
  122. {
  123. mDownloadEnterpriseButton.Collapse();
  124. DownloadPlasticExeWindow window = GetWindow<DownloadPlasticExeWindow>();
  125. }
  126. else
  127. {
  128. mMessageLabel.text =
  129. PlasticLocalization.GetString(
  130. PlasticLocalization.Name.WhichVersionInstall);
  131. mDownloadEnterpriseButton.text =
  132. PlasticLocalization.GetString(
  133. PlasticLocalization.Name.DownloadEnterpriseEdition);
  134. mDownloadEnterpriseButton.clicked += DownloadEnterpriseEditionButton_Clicked;
  135. }
  136. mCancelButton.text =
  137. PlasticLocalization.GetString(PlasticLocalization.Name.CancelButton);
  138. mCancelButton.clicked += CancelButton_Clicked;
  139. mProgressControls = new ProgressControlsForDialogs(
  140. new VisualElement[] {
  141. mDownloadCloudEditionButton,
  142. mDownloadEnterpriseButton,
  143. mCancelButton
  144. });
  145. mProgressControlsContainer.Add(mProgressControls);
  146. }
  147. void InitializeLayoutAndStyles()
  148. {
  149. rootVisualElement.LoadLayout(typeof(DownloadPlasticExeWindow).Name);
  150. rootVisualElement.LoadStyle(typeof(DownloadPlasticExeWindow).Name);
  151. }
  152. bool mIsGluonMode;
  153. string mInstallCloudFrom;
  154. string mInstallEnterpriseFrom;
  155. string mCancelInstallFrom;
  156. RepositorySpec mRepSpec;
  157. string mInstallerFile;
  158. bool mIsPlasticInstalling = false;
  159. Label mRequireMessageLabel;
  160. Label mMessageLabel;
  161. Button mDownloadCloudEditionButton;
  162. Button mDownloadEnterpriseButton;
  163. Button mCancelButton;
  164. VisualElement mProgressControlsContainer;
  165. ProgressControlsForDialogs mProgressControls;
  166. }
  167. }