A game about forced loneliness, made by TACStudios
1using System;
2using System.IO;
3using System.Collections.Generic;
4
5using UnityEditor;
6using UnityEditor.VersionControl;
7
8using Codice.Client.BaseCommands;
9using Codice.Client.Commands;
10using Codice.Client.Commands.WkTree;
11using Codice.Client.Common;
12using Codice.Client.Common.EventTracking;
13using Codice.Client.Common.Threading;
14using Codice.CM.Common;
15using GluonGui;
16using PlasticGui;
17using PlasticGui.Gluon;
18using PlasticGui.WorkspaceWindow;
19using PlasticGui.WorkspaceWindow.Diff;
20using PlasticGui.WorkspaceWindow.Items;
21using Unity.PlasticSCM.Editor.AssetMenu.Dialogs;
22using Unity.PlasticSCM.Editor.AssetsOverlays.Cache;
23using Unity.PlasticSCM.Editor.AssetUtils;
24using Unity.PlasticSCM.Editor.AssetUtils.Processor;
25using Unity.PlasticSCM.Editor.Tool;
26using Unity.PlasticSCM.Editor.UI;
27using Unity.PlasticSCM.Editor.Views.PendingChanges.Dialogs;
28
29using GluonCheckoutOperation = GluonGui.WorkspaceWindow.Views.WorkspaceExplorer.Explorer.Operations.CheckoutOperation;
30using GluonUndoCheckoutOperation = GluonGui.WorkspaceWindow.Views.WorkspaceExplorer.Explorer.Operations.UndoCheckoutOperation;
31using GluonAddoperation = GluonGui.WorkspaceWindow.Views.WorkspaceExplorer.Explorer.Operations.AddOperation;
32
33namespace Unity.PlasticSCM.Editor.AssetMenu
34{
35 internal class AssetVcsOperations :
36 IAssetMenuVCSOperations,
37 IAssetFilesFilterPatternsMenuOperations
38 {
39 internal interface IAssetSelection
40 {
41 AssetList GetSelectedAssets();
42 }
43
44 internal AssetVcsOperations(
45 WorkspaceInfo wkInfo,
46 IPlasticAPI plasticApi,
47 IWorkspaceWindow workspaceWindow,
48 IViewSwitcher viewSwitcher,
49 IHistoryViewLauncher historyViewLauncher,
50 ViewHost viewHost,
51 WorkspaceOperationsMonitor workspaceOperationsMonitor,
52 ISaveAssets saveAssets,
53 NewIncomingChangesUpdater newIncomingChangesUpdater,
54 ShelvedChangesUpdater shelvedChangesUpdater,
55 IAssetStatusCache assetStatusCache,
56 IMergeViewLauncher mergeViewLauncher,
57 IGluonViewSwitcher gluonViewSwitcher,
58 IAssetSelection assetSelection,
59 LaunchTool.IShowDownloadPlasticExeWindow showDownloadPlasticExeWindow,
60 bool isGluonMode)
61 {
62 mWkInfo = wkInfo;
63 mPlasticAPI = plasticApi;
64 mWorkspaceWindow = workspaceWindow;
65 mViewSwitcher = viewSwitcher;
66 mHistoryViewLauncher = historyViewLauncher;
67 mViewHost = viewHost;
68 mWorkspaceOperationsMonitor = workspaceOperationsMonitor;
69 mSaveAssets = saveAssets;
70 mNewIncomingChangesUpdater = newIncomingChangesUpdater;
71 mShelvedChangesUpdater = shelvedChangesUpdater;
72 mAssetStatusCache = assetStatusCache;
73 mMergeViewLauncher = mergeViewLauncher;
74 mGluonViewSwitcher = gluonViewSwitcher;
75 mAssetSelection = assetSelection;
76 mShowDownloadPlasticExeWindow = showDownloadPlasticExeWindow;
77 mIsGluonMode = isGluonMode;
78
79 mGuiMessage = new UnityPlasticGuiMessage();
80 mProgressControls = new EditorProgressControls(mGuiMessage);
81 }
82
83 void IAssetMenuVCSOperations.ShowPendingChanges()
84 {
85 mViewSwitcher.ShowPendingChanges();
86 }
87
88 void IAssetMenuVCSOperations.Add()
89 {
90 List<string> selectedPaths = GetSelectedPaths.ForOperation(
91 mWkInfo,
92 mAssetSelection.GetSelectedAssets(),
93 mPlasticAPI,
94 mAssetStatusCache,
95 AssetMenuOperations.Add);
96
97 if (mIsGluonMode)
98 {
99 GluonAddoperation.Add(
100 mViewHost,
101 mProgressControls,
102 mGuiMessage,
103 selectedPaths.ToArray(),
104 false,
105 RefreshAsset.VersionControlCache);
106 return;
107 }
108
109 AddOperation.Run(
110 mWorkspaceWindow,
111 mProgressControls,
112 null,
113 null,
114 selectedPaths,
115 false,
116 mNewIncomingChangesUpdater,
117 mShelvedChangesUpdater,
118 RefreshAsset.VersionControlCache);
119 }
120
121 void IAssetMenuVCSOperations.Checkout()
122 {
123 List<string> selectedPaths = GetSelectedPaths.ForOperation(
124 mWkInfo,
125 mAssetSelection.GetSelectedAssets(),
126 mPlasticAPI,
127 mAssetStatusCache,
128 AssetMenuOperations.Checkout);
129
130 if (mIsGluonMode)
131 {
132 GluonCheckoutOperation.Checkout(
133 mViewHost,
134 mProgressControls,
135 mGuiMessage,
136 selectedPaths.ToArray(),
137 false,
138 RefreshAsset.VersionControlCache,
139 mWkInfo);
140 return;
141 }
142
143 CheckoutOperation.Checkout(
144 mWorkspaceWindow,
145 null,
146 mProgressControls,
147 selectedPaths,
148 mNewIncomingChangesUpdater,
149 mShelvedChangesUpdater,
150 RefreshAsset.VersionControlCache,
151 mWkInfo);
152 }
153
154 void IAssetMenuVCSOperations.Checkin()
155 {
156 List<string> selectedPaths = GetSelectedPaths.ForOperation(
157 mWkInfo,
158 mAssetSelection.GetSelectedAssets(),
159 mPlasticAPI,
160 mAssetStatusCache,
161 AssetMenuOperations.Checkin);
162
163 if (!CheckinDialog.CheckinPaths(
164 mWkInfo,
165 selectedPaths,
166 mAssetStatusCache,
167 mIsGluonMode,
168 mWorkspaceWindow,
169 mViewHost,
170 mWorkspaceOperationsMonitor,
171 mSaveAssets,
172 mGuiMessage,
173 mMergeViewLauncher,
174 mGluonViewSwitcher))
175 return;
176
177 RefreshAsset.UnityAssetDatabase();
178 }
179
180 void IAssetMenuVCSOperations.Undo()
181 {
182 List<string> selectedPaths = GetSelectedPaths.ForOperation(
183 mWkInfo,
184 mAssetSelection.GetSelectedAssets(),
185 mPlasticAPI,
186 mAssetStatusCache,
187 AssetMenuOperations.Undo);
188
189 mSaveAssets.ForPathsWithoutConfirmation(
190 mWkInfo.ClientPath, selectedPaths, mWorkspaceOperationsMonitor);
191
192 if (mIsGluonMode)
193 {
194 GluonUndoCheckoutOperation.UndoCheckout(
195 mWkInfo,
196 mViewHost,
197 mProgressControls,
198 selectedPaths.ToArray(),
199 false,
200 RefreshAsset.UnityAssetDatabase);
201 return;
202 }
203
204 UndoCheckoutOperation.Run(
205 mWorkspaceWindow,
206 null,
207 mProgressControls,
208 selectedPaths,
209 mNewIncomingChangesUpdater,
210 mShelvedChangesUpdater,
211 RefreshAsset.UnityAssetDatabase);
212 }
213
214 void IAssetMenuVCSOperations.ShowDiff()
215 {
216 string selectedPath = AssetsSelection.GetSelectedPath(
217 mWkInfo.ClientPath,
218 mAssetSelection.GetSelectedAssets());
219
220 DiffInfo diffInfo = null;
221
222 IThreadWaiter waiter = ThreadWaiter.GetWaiter(10);
223 waiter.Execute(
224 /*threadOperationDelegate*/ delegate
225 {
226 string symbolicName = GetSymbolicName(selectedPath);
227 string extension = Path.GetExtension(selectedPath);
228
229 diffInfo = PlasticGui.Plastic.API.BuildDiffInfoForDiffWithPrevious(
230 selectedPath, symbolicName, selectedPath, extension, mWkInfo);
231 },
232 /*afterOperationDelegate*/ delegate
233 {
234 if (waiter.Exception != null)
235 {
236 ExceptionsHandler.DisplayException(waiter.Exception);
237 return;
238 }
239
240 DiffOperation.DiffWithPrevious(
241 diffInfo,
242 PlasticExeLauncher.BuildForShowDiff(mWkInfo, mIsGluonMode, mShowDownloadPlasticExeWindow),
243 null);
244 });
245 }
246
247 void IAssetMenuVCSOperations.ShowHistory()
248 {
249 Asset selectedAsset = AssetsSelection.GetSelectedAsset(
250 mWkInfo.ClientPath,
251 mAssetSelection.GetSelectedAssets());
252
253 string selectedPath = Path.GetFullPath(selectedAsset.path);
254
255 WorkspaceTreeNode node = PlasticGui.Plastic.API.
256 GetWorkspaceTreeNode(selectedPath);
257
258 mHistoryViewLauncher.ShowHistoryView(
259 node.RepSpec,
260 node.RevInfo.ItemId,
261 selectedPath,
262 selectedAsset.isFolder);
263 }
264
265 void IAssetFilesFilterPatternsMenuOperations.AddFilesFilterPatterns(
266 FilterTypes type,
267 FilterActions action,
268 FilterOperationType operation)
269 {
270 List<string> selectedPaths = AssetsSelection.GetSelectedPaths(
271 mWkInfo.ClientPath,
272 mAssetSelection.GetSelectedAssets());
273
274 string[] rules = FilterRulesGenerator.GenerateRules(
275 selectedPaths, mWkInfo.ClientPath, action, operation);
276
277 bool isApplicableToAllWorkspaces = !mIsGluonMode;
278 bool isAddOperation = operation == FilterOperationType.Add;
279
280 FilterRulesConfirmationData filterRulesConfirmationData =
281 FilterRulesConfirmationDialog.AskForConfirmation(
282 rules, isAddOperation, isApplicableToAllWorkspaces, EditorWindow.focusedWindow);
283
284 AddFilesFilterPatternsOperation.Run(
285 mWkInfo, mWorkspaceWindow, type, operation, filterRulesConfirmationData);
286 }
287
288 static string GetSymbolicName(string selectedPath)
289 {
290 WorkspaceTreeNode node = PlasticGui.Plastic.API.
291 GetWorkspaceTreeNode(selectedPath);
292
293 string branchName = string.Empty;
294 BranchInfoCache.TryGetBranchName(
295 node.RepSpec, node.RevInfo.BranchId, out branchName);
296
297 string userName = PlasticGui.Plastic.API.GetUserName(
298 node.RepSpec.Server, node.RevInfo.Owner);
299
300 string symbolicName = string.Format(
301 "cs:{0}@{1} {2} {3}",
302 node.RevInfo.Changeset,
303 string.Format("br:{0}", branchName),
304 userName,
305 "Workspace Revision");
306
307 return symbolicName;
308 }
309
310 readonly WorkspaceInfo mWkInfo;
311 readonly IPlasticAPI mPlasticAPI;
312 readonly IViewSwitcher mViewSwitcher;
313 readonly IHistoryViewLauncher mHistoryViewLauncher;
314 readonly IWorkspaceWindow mWorkspaceWindow;
315 readonly ViewHost mViewHost;
316 readonly WorkspaceOperationsMonitor mWorkspaceOperationsMonitor;
317 readonly ISaveAssets mSaveAssets;
318 readonly NewIncomingChangesUpdater mNewIncomingChangesUpdater;
319 readonly ShelvedChangesUpdater mShelvedChangesUpdater;
320 readonly IAssetStatusCache mAssetStatusCache;
321 readonly IMergeViewLauncher mMergeViewLauncher;
322 readonly IGluonViewSwitcher mGluonViewSwitcher;
323 readonly bool mIsGluonMode;
324 readonly GuiMessage.IGuiMessage mGuiMessage;
325 readonly EditorProgressControls mProgressControls;
326 readonly IAssetSelection mAssetSelection;
327 readonly LaunchTool.IShowDownloadPlasticExeWindow mShowDownloadPlasticExeWindow;
328 }
329}