TeamEditionConfigurationWindow.cs
11.0 KB
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
using System;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
using PlasticGui;
using Codice.CM.Common;
using Codice.Client.Common;
using Unity.PlasticSCM.Editor.UI.UIElements;
using PlasticGui.Configuration.TeamEdition;
using PlasticGui.Configuration;
using PlasticGui.WebApi;
using Unity.PlasticSCM.Editor.Views.Welcome;
namespace Unity.PlasticSCM.Editor.Configuration.TeamEdition
{
internal class TeamEditionConfigurationWindow : EditorWindow
{
internal static void ShowWindow(IPlasticWebRestApi restApi, WelcomeView welcomeView)
{
TeamEditionConfigurationWindow window = GetWindow<TeamEditionConfigurationWindow>();
window.mRestApi = restApi;
window.mWelcomeView = welcomeView;
window.titleContent = new GUIContent(
PlasticLocalization.GetString(PlasticLocalization.Name.WelcomeToPlasticSCM));
window.minSize = window.maxSize = new Vector2(650, 300);
window.Show();
}
void OnEnable()
{
InitializeLayoutAndStyles();
BuildComponents();
}
void Dispose()
{
mConnectButton.clicked -= ConnectButton_Clicked;
mCheckConnectionButton.clicked -= CheckConnectionButton_Clicked;
mOkButton.clicked -= OkButton_Clicked;
mCancelButton.clicked -= CancelButton_Clicked;
mServerTextField.UnregisterValueChangedCallback(OnServerTextFieldChanged);
mUseSslToggle.UnregisterValueChangedCallback(OnUseSslToggleChanged);
mLoadingSpinner.Dispose();
}
void ConnectButton_Clicked()
{
ConfigurationConnectServerButtonClickEvent.Click(
server: mUserAssistant.GetProposedServer(),
HideValidation: HideValidation,
ShowError: ShowServerValidationError,
ShowProgress: ShowProgress,
HideProgress: HideProgress,
ShowNotification: ShowServerNotificationMessage,
DisableButtons: () => { mConnectButton.SetEnabled(false); },
EnableButtons: () => { mConnectButton.SetEnabled(true); },
UpdatePasswordEntries: (seidWorkingMode) =>
{
UpdatePasswordEntries(ValidateServerAndCreds.
IsPasswordRequired(seidWorkingMode));
},
NotifyWorkingMode: (mode) => { mSEIDWorkingMode = mode; },
NotifyConnectedStatus: (b) => { });
mUserTextField.SetEnabled(true);
}
void OnDestroy()
{
Dispose();
if (mWelcomeView != null)
mWelcomeView.OnUserClosedConfigurationWindow();
}
void CheckConnectionButton_Clicked()
{
ConfigurationCheckCredentialsButtonClickEvent.Click(
mSEIDWorkingMode,
mUserTextField.value,
mPasswordTextField.value,
Edition.Team,
mUserAssistant,
HideCredentialsValidationError,
ShowCheckCredentialsError,
ShowProgress,
HideProgress,
ShowNotification: ShowCredentialsNotificationMessage,
DisableButtons: () => { mCheckConnectionButton.SetEnabled(false); mConnectButton.SetEnabled(false); },
EnableButtons: () => { mCheckConnectionButton.SetEnabled(true); mConnectButton.SetEnabled(true); },
NotifyWorkingMode: (mode) => { mSEIDWorkingMode = mode; },
NotifyConnectedStatus: (status) => { },
restApi: mRestApi,
cmConnection: CmConnection.Get());
}
void CancelButton_Clicked()
{
Close();
}
void OkButton_Clicked()
{
if (!ValidateServerAndCreds.IsValidInput(
mUserAssistant.GetProposedServer(),
mUserTextField.value,
mSEIDWorkingMode,
mPasswordTextField.value,
ShowCheckCredentialsError))
{
return;
}
ConfigurationActions.SaveClientConfig(
mServerTextField.value,
mSEIDWorkingMode,
mUserTextField.value,
mPasswordTextField.value);
Close();
}
void HideCredentialsValidationError()
{
mCredentialsLabel.RemoveFromClassList("error");
mCredentialsLabel.AddToClassList("visibility-hidden");
}
void BuildComponents()
{
VisualElement root = rootVisualElement;
root.Query<Label>("plasticConfigurationTitle").First().text =
PlasticLocalization.GetString(PlasticLocalization.Name.PlasticConfigurationTitle);
root.SetControlText<Label>(
"plasticConfigurationExplanation",
PlasticLocalization.Name.PlasticConfigurationExplanation);
root.SetControlText<Label>("configurationServerInfo",
PlasticLocalization.Name.PlasticSCMServerLabel);
root.SetControlText<Button>(
"connect",
PlasticLocalization.Name.Connect);
root.SetControlText<Label>("useSsl",
PlasticLocalization.Name.UseSsl);
root.SetControlText<Label>("configurationUserNameInfo",
PlasticLocalization.Name.ConfigurationUserNameInfo);
root.SetControlText<Label>("configurationCredentialsInfo",
PlasticLocalization.Name.ConfigurationCredentialsInfo);
root.SetControlText<Button>("check",
PlasticLocalization.Name.Check);
root.SetControlText<Label>("credentialsOk",
PlasticLocalization.Name.CredentialsOK);
root.SetControlText<Button>("okButton",
PlasticLocalization.Name.OkButton);
root.SetControlText<Button>("cancelButton",
PlasticLocalization.Name.CancelButton);
mSpinnerContainer = root.Query<VisualElement>("spinnerContainer").First();
mSpinnerLabel = root.Query<Label>("spinnerLabel").First();
mLoadingSpinner = new LoadingSpinner();
mSpinnerContainer.Add(mLoadingSpinner);
mSpinnerContainer.AddToClassList("visibility-hidden");
mCheckConnectionButton = root.Query<Button>("check").First();
mCheckConnectionButton.clicked += CheckConnectionButton_Clicked;
mConnectButton = root.Query<Button>("connect").First();
mConnectButton.clicked += ConnectButton_Clicked;
mServerTextField = root.Query<TextField>("serverTextField").First();
mServerTextField.RegisterValueChangedCallback(OnServerTextFieldChanged);
mUseSslToggle = root.Query<Toggle>("useSslToogle").First();
mUseSslToggle.RegisterValueChangedCallback(OnUseSslToggleChanged);
mUserTextField = root.Query<TextField>("userTextField").First();
mUserTextField.SetEnabled(false);
mPasswordTextField = root.Query<TextField>("passwordTextField").First();
mPasswordTextField.isPasswordField = true;
mConnectedLabel = root.Query<Label>("connectedLabel").First();
mCredentialsLabel = root.Query<Label>("credentialsOk").First();
mOkButton = root.Query<Button>("okButton").First();
mOkButton.clicked += OkButton_Clicked;
mCancelButton = root.Query<Button>("cancelButton").First();
mCancelButton.clicked += CancelButton_Clicked;
}
void OnUseSslToggleChanged(ChangeEvent<bool> evt)
{
mUserAssistant.OnSslChanged(mServerTextField.value, evt.newValue);
mServerTextField.value = mUserAssistant.GetProposedServer();
}
void InitializeLayoutAndStyles()
{
VisualElement root = rootVisualElement;
root.LoadLayout(typeof(TeamEditionConfigurationWindow).Name);
root.LoadStyle(typeof(TeamEditionConfigurationWindow).Name);
}
void OnServerTextFieldChanged(ChangeEvent<string> evt)
{
mUserAssistant.OnServerChanged(evt.newValue);
mUseSslToggle.value = mUserAssistant.IsSslServer(evt.newValue);
}
void ShowServerNotificationMessage(string message)
{
mConnectedLabel.text = message;
mConnectedLabel.RemoveFromClassList("visibility-hidden");
}
void ShowServerValidationError(string message)
{
mConnectedLabel.text = message;
mConnectedLabel.AddToClassList("error");
mConnectedLabel.RemoveFromClassList("visibility-hidden");
}
void ShowCredentialsNotificationMessage(string message)
{
mCredentialsLabel.text = message;
mCredentialsLabel.RemoveFromClassList("visibility-hidden");
}
void ShowCheckCredentialsError(string message)
{
mCredentialsLabel.text = message;
mCredentialsLabel.AddToClassList("error");
mCredentialsLabel.RemoveFromClassList("visibility-hidden");
}
void HideValidation()
{
mConnectedLabel.RemoveFromClassList("error");
mConnectedLabel.AddToClassList("visibility-hidden");
}
void ShowProgress(string text)
{
mSpinnerLabel.text = text;
mSpinnerContainer.RemoveFromClassList("visibility-hidden");
mSpinnerLabel.RemoveFromClassList("visibility-hidden");
mLoadingSpinner.Start();
}
void HideProgress()
{
mLoadingSpinner.Stop();
mSpinnerContainer.AddToClassList("visibility-hidden");
mSpinnerLabel.AddToClassList("visibility-hidden");
}
void UpdatePasswordEntries(bool bIsPasswordRequired)
{
if (!bIsPasswordRequired)
{
mPasswordTextField.AddToClassList("display-none");
mUserTextField.SetEnabled(false);
mUserTextField.value = Environment.UserName;
return;
}
mUserTextField.SetEnabled(true);
mPasswordTextField.RemoveFromClassList("display-none");
mUserTextField.SelectAll();
mUserTextField.FocusWorkaround();
}
Button mConnectButton;
Label mConnectedLabel;
TextField mServerTextField;
TextField mPasswordTextField;
Toggle mUseSslToggle;
LoadingSpinner mLoadingSpinner;
Label mSpinnerLabel;
VisualElement mSpinnerContainer;
Button mCheckConnectionButton;
Label mCredentialsLabel;
Button mOkButton;
Button mCancelButton;
SEIDWorkingMode mSEIDWorkingMode = SEIDWorkingMode.UPWorkingMode;
ConfigurationDialogUserAssistant mUserAssistant =
new ConfigurationDialogUserAssistant();
IPlasticWebRestApi mRestApi;
WelcomeView mWelcomeView;
TextField mUserTextField;
}
}