Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

AssetOperations.cs 12KB

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