CollabHistoryWindow.cs
10 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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
using System;
using System.Linq;
using System.Collections.Generic;
using UnityEditor.Collaboration;
#if UNITY_2019_1_OR_NEWER
using UnityEditor.UIElements;
using UnityEngine.UIElements;
#else
using UnityEditor.Experimental.UIElements;
using UnityEngine.Experimental.UIElements;
using UnityEngine.Experimental.UIElements.StyleEnums;
#endif
using UnityEngine;
using UnityEditor.Connect;
namespace UnityEditor
{
internal class CollabHistoryWindow : EditorWindow, ICollabHistoryWindow
{
#if UNITY_2019_1_OR_NEWER
private const string ResourcesPath = "Packages/com.unity.collab-proxy/Editor/Resources/Styles/";
#else
private const string ResourcesPath = "StyleSheets/";
#endif
const string kWindowTitle = "Collab History";
const string kServiceUrl = "developer.cloud.unity3d.com";
[MenuItem("Window/Asset Management/Collab History", false, 1)]
public static void ShowHistoryWindow()
{
EditorWindow.GetWindow<CollabHistoryWindow>(kWindowTitle);
}
[MenuItem("Window/Asset Management/Collab History", true)]
public static bool ValidateShowHistoryWindow()
{
return Collab.instance.IsCollabEnabledForCurrentProject();
}
CollabHistoryPresenter m_Presenter;
Dictionary<HistoryState, VisualElement> m_Views;
List<CollabHistoryItem> m_HistoryItems = new List<CollabHistoryItem>();
HistoryState m_State;
VisualElement m_Container;
PagedListView m_Pager;
ScrollView m_HistoryView;
int m_ItemsPerPage = 5;
string m_InProgressRev;
bool m_RevisionActionsEnabled;
public CollabHistoryWindow()
{
minSize = new Vector2(275, 50);
}
public void OnEnable()
{
SetupGUI();
name = "CollabHistory";
if (m_Presenter == null)
{
m_Presenter = new CollabHistoryPresenter(this, new CollabHistoryItemFactory(), new RevisionsService(Collab.instance, UnityConnect.instance));
}
m_Presenter.OnWindowEnabled();
}
public void OnDisable()
{
m_Presenter.OnWindowDisabled();
}
public bool revisionActionsEnabled
{
get { return m_RevisionActionsEnabled; }
set
{
if (m_RevisionActionsEnabled == value)
return;
m_RevisionActionsEnabled = value;
foreach (var historyItem in m_HistoryItems)
{
historyItem.RevisionActionsEnabled = value;
}
}
}
private void AddStyleSheetPath(VisualElement root, string path)
{
#if UNITY_2019_1_OR_NEWER
root.styleSheets.Add(EditorGUIUtility.Load(path) as StyleSheet);
#else
root.AddStyleSheetPath(path);
#endif
}
public void SetupGUI()
{
#if UNITY_2019_1_OR_NEWER
var root = this.rootVisualElement;
#else
var root = this.GetRootVisualContainer();
#endif
AddStyleSheetPath(root, ResourcesPath + "CollabHistoryCommon.uss");
if (EditorGUIUtility.isProSkin)
{
AddStyleSheetPath(root, ResourcesPath + "CollabHistoryDark.uss");
}
else
{
AddStyleSheetPath(root, ResourcesPath + "CollabHistoryLight.uss");
}
m_Container = new VisualElement();
m_Container.StretchToParentSize();
root.Add(m_Container);
m_Pager = new PagedListView()
{
name = "PagedElement",
pageSize = m_ItemsPerPage
};
var errorView = new StatusView()
{
message = "An Error Occurred",
icon = EditorGUIUtility.LoadIconRequired("Collab.Warning") as Texture,
};
var noInternetView = new StatusView()
{
message = "No Internet Connection",
icon = EditorGUIUtility.LoadIconRequired("Collab.NoInternet") as Texture,
};
var maintenanceView = new StatusView()
{
message = "Maintenance",
};
var loginView = new StatusView()
{
message = "Sign in to access Collaborate",
buttonText = "Sign in...",
callback = SignInClick,
};
var noSeatView = new StatusView()
{
message = "Ask your project owner for access to Unity Teams",
buttonText = "Learn More",
callback = NoSeatClick,
};
var waitingView = new StatusView()
{
message = "Updating...",
};
m_HistoryView = new ScrollView() { name = "HistoryContainer", showHorizontal = false};
m_HistoryView.contentContainer.StretchToParentWidth();
m_HistoryView.Add(m_Pager);
m_Views = new Dictionary<HistoryState, VisualElement>()
{
{HistoryState.Error, errorView},
{HistoryState.Offline, noInternetView},
{HistoryState.Maintenance, maintenanceView},
{HistoryState.LoggedOut, loginView},
{HistoryState.NoSeat, noSeatView},
{HistoryState.Waiting, waitingView},
{HistoryState.Ready, m_HistoryView}
};
}
public void UpdateState(HistoryState state, bool force)
{
if (state == m_State && !force)
return;
m_State = state;
switch (state)
{
case HistoryState.Ready:
UpdateHistoryView(m_Pager);
break;
case HistoryState.Disabled:
Close();
return;
}
m_Container.Clear();
m_Container.Add(m_Views[m_State]);
}
public void UpdateRevisions(IEnumerable<RevisionData> datas, string tip, int totalRevisions, int currentPage)
{
var elements = new List<VisualElement>();
var isFullDateObtained = false; // Has everything from this date been obtained?
m_HistoryItems.Clear();
if (datas != null)
{
DateTime currentDate = DateTime.MinValue;
foreach (var data in datas)
{
if (data.timeStamp.Date != currentDate.Date)
{
elements.Add(new CollabHistoryRevisionLine(data.timeStamp, isFullDateObtained));
currentDate = data.timeStamp;
}
var item = new CollabHistoryItem(data);
m_HistoryItems.Add(item);
var container = new VisualElement();
container.style.flexDirection = FlexDirection.Row;
if (data.current)
{
isFullDateObtained = true;
container.AddToClassList("currentRevision");
container.AddToClassList("obtainedRevision");
}
else if (data.obtained)
{
container.AddToClassList("obtainedRevision");
}
else
{
container.AddToClassList("absentRevision");
}
// If we use the index as-is, the latest commit will become #1, but we want it to be last
container.Add(new CollabHistoryRevisionLine(data.index));
container.Add(item);
elements.Add(container);
}
}
m_HistoryView.scrollOffset = new Vector2(0, 0);
m_Pager.totalItems = totalRevisions;
m_Pager.curPage = currentPage;
m_Pager.items = elements;
}
public string inProgressRevision
{
get { return m_InProgressRev; }
set
{
m_InProgressRev = value;
foreach (var historyItem in m_HistoryItems)
{
historyItem.SetInProgressStatus(value);
}
}
}
public int itemsPerPage
{
set
{
if (m_ItemsPerPage == value)
return;
m_Pager.pageSize = m_ItemsPerPage;
}
}
public PageChangeAction OnPageChangeAction
{
set { m_Pager.OnPageChanged = value; }
}
public RevisionAction OnGoBackAction
{
set { CollabHistoryItem.s_OnGoBack = value; }
}
public RevisionAction OnUpdateAction
{
set { CollabHistoryItem.s_OnUpdate = value; }
}
public RevisionAction OnRestoreAction
{
set { CollabHistoryItem.s_OnRestore = value; }
}
public ShowBuildAction OnShowBuildAction
{
set { CollabHistoryItem.s_OnShowBuild = value; }
}
public Action OnShowServicesAction
{
set { CollabHistoryItem.s_OnShowServices = value; }
}
void UpdateHistoryView(VisualElement history)
{
}
void NoSeatClick()
{
var connection = UnityConnect.instance;
var env = connection.GetEnvironment();
// Map environment to url - prod is special
if (env == "production")
env = "";
else
env += "-";
var url = "https://" + env + kServiceUrl
+ "/orgs/" + connection.GetOrganizationId()
+ "/projects/" + connection.GetProjectName()
+ "/unity-teams/";
Application.OpenURL(url);
}
void SignInClick()
{
UnityConnect.instance.ShowLogin();
}
}
}