forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVCWindowCheckoutFailure.cs
More file actions
156 lines (124 loc) · 5.14 KB
/
Copy pathVCWindowCheckoutFailure.cs
File metadata and controls
156 lines (124 loc) · 5.14 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
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using UnityEngine;
using UnityEditorInternal.VersionControl;
namespace UnityEditor.VersionControl
{
// Window allowing you to review files that could not be checked out.
internal class WindowCheckoutFailure : EditorWindow
{
private AssetList assetList = new AssetList();
private ListControl checkoutSuccessList = new ListControl();
private ListControl checkoutFailureList = new ListControl();
public void OnEnable()
{
position = new Rect(100, 100, 700, 230);
minSize = new Vector2(700, 230);
checkoutSuccessList.ReadOnly = true;
checkoutFailureList.ReadOnly = true;
}
public static void OpenIfCheckoutFailed(AssetList assets)
{
Object[] windows = Resources.FindObjectsOfTypeAll(typeof(WindowCheckoutFailure));
WindowCheckoutFailure window = (windows.Length > 0 ? windows[0] as WindowCheckoutFailure : null);
bool alreadyOpen = (window != null);
bool shouldOpen = alreadyOpen;
if (!shouldOpen)
{
foreach (var asset in assets)
{
if (!asset.IsState(Asset.States.CheckedOutLocal))
{
shouldOpen = true;
break;
}
}
}
if (shouldOpen)
GetWindow().DoOpen(assets, alreadyOpen);
}
private static WindowCheckoutFailure GetWindow()
{
return EditorWindow.GetWindow<WindowCheckoutFailure>(true, "Version Control Check Out Failed");
}
private void DoOpen(AssetList assets, bool alreadyOpen)
{
if (alreadyOpen)
{
foreach (var asset in assets)
{
bool found = false;
int count = assetList.Count;
for (int i = 0; i < count; i++)
{
if (assetList[i].path == asset.path)
{
found = true;
assetList[i] = asset;
break;
}
}
if (!found)
assetList.Add(asset);
}
}
else
assetList.AddRange(assets);
RefreshList();
}
private void RefreshList()
{
checkoutSuccessList.Clear();
checkoutFailureList.Clear();
foreach (var asset in assetList)
{
if (asset.IsState(Asset.States.CheckedOutLocal))
checkoutSuccessList.Add(null, asset.prettyPath, asset);
else
checkoutFailureList.Add(null, asset.prettyPath, asset);
}
checkoutSuccessList.Refresh();
checkoutFailureList.Refresh();
Repaint();
}
public void OnGUI()
{
float h = (position.height - 122) / 2;
// TODO: Show the reason: Who has the exclusive lock?
GUILayout.Label("Some files could not be checked out:", EditorStyles.boldLabel);
Rect r1 = new Rect(6, 40, position.width - 12, h);
GUILayout.BeginArea(r1);
GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
GUILayout.EndArea();
checkoutFailureList.OnGUI(new Rect(r1.x + 2, r1.y + 2, r1.width - 4, r1.height - 4), true);
GUILayout.Space(20 + h);
GUILayout.Label("The following files were successfully checked out:", EditorStyles.boldLabel);
Rect r2 = new Rect(6, 40 + h + 40, position.width - 12, h);
GUILayout.BeginArea(r2);
GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
GUILayout.EndArea();
checkoutSuccessList.OnGUI(new Rect(r2.x + 2, r2.y + 2, r2.width - 4, r2.height - 4), true);
GUILayout.FlexibleSpace();
GUILayout.BeginHorizontal();
EditorUserSettings.showFailedCheckout = !GUILayout.Toggle(!EditorUserSettings.showFailedCheckout, "Don't show this window again.");
GUILayout.FlexibleSpace();
bool enabled = GUI.enabled;
GUI.enabled = checkoutFailureList.Size > 0;
if (GUILayout.Button("Retry Check Out"))
Provider.Checkout(assetList, CheckoutMode.Exact);
GUI.enabled = checkoutSuccessList.Size > 0;
if (GUILayout.Button("Revert Unchanged"))
{
Provider.Revert(assetList, RevertMode.Unchanged).SetCompletionAction(CompletionAction.UpdatePendingWindow);
Provider.Status(assetList);
Close();
}
GUI.enabled = enabled;
if (GUILayout.Button("OK"))
Close();
GUILayout.EndHorizontal();
GUILayout.Space(12);
}
}
}