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