WorkspaceWindow.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEditor;
  5. using Codice.Client.BaseCommands;
  6. using Codice.Client.Commands.CheckIn;
  7. using Codice.Client.Common;
  8. using Codice.Client.Common.Threading;
  9. using Codice.CM.Common;
  10. using Codice.CM.Common.Replication;
  11. using GluonGui.WorkspaceWindow.Views;
  12. using GluonGui;
  13. using GluonGui.WorkspaceWindow.Views.WorkspaceExplorer.Explorer;
  14. using PlasticGui;
  15. using PlasticGui.WorkspaceWindow;
  16. using PlasticGui.WorkspaceWindow.Topbar;
  17. using PlasticGui.WorkspaceWindow.Replication;
  18. using PlasticGui.WorkspaceWindow.Update;
  19. using Unity.PlasticSCM.Editor.AssetUtils;
  20. using Unity.PlasticSCM.Editor.Configuration;
  21. using Unity.PlasticSCM.Editor.Developer.UpdateReport;
  22. using Unity.PlasticSCM.Editor.UI;
  23. using Unity.PlasticSCM.Editor.UI.Progress;
  24. using IGluonUpdateReport = PlasticGui.Gluon.IUpdateReport;
  25. using IGluonWorkspaceStatusChangeListener = PlasticGui.Gluon.IWorkspaceStatusChangeListener;
  26. using GluonUpdateReportDialog = Unity.PlasticSCM.Editor.Gluon.UpdateReport.UpdateReportDialog;
  27. namespace Unity.PlasticSCM.Editor
  28. {
  29. internal class WorkspaceWindow :
  30. IWorkspaceWindow,
  31. IRefreshView,
  32. IUpdateReport,
  33. IGluonUpdateReport,
  34. IGluonWorkspaceStatusChangeListener
  35. {
  36. internal void SetUpdateNotifierForTesting(UpdateNotifier updateNotifier)
  37. {
  38. mUpdateNotifierForTesting = updateNotifier;
  39. }
  40. internal WorkspaceStatusString.Data WorkspaceStatus { get; private set; }
  41. internal OperationProgressData Progress { get { return mOperationProgressData; } }
  42. internal Gluon.ProgressOperationHandler GluonProgressOperationHandler
  43. {
  44. get { return mGluonProgressOperationHandler; }
  45. }
  46. internal WorkspaceWindow(
  47. WorkspaceInfo wkInfo,
  48. ViewHost viewHost,
  49. ViewSwitcher switcher,
  50. IMergeViewLauncher mergeViewLauncher,
  51. NewIncomingChangesUpdater developerNewIncomingChangesUpdater,
  52. EditorWindow parentWindow)
  53. {
  54. mWkInfo = wkInfo;
  55. mViewHost = viewHost;
  56. mSwitcher = switcher;
  57. mMergeViewLauncher = mergeViewLauncher;
  58. mDeveloperNewIncomingChangesUpdater = developerNewIncomingChangesUpdater;
  59. mPlasticWindow = parentWindow;
  60. mGuiMessage = new UnityPlasticGuiMessage();
  61. mDeveloperProgressOperationHandler = new Developer.ProgressOperationHandler(mWkInfo, this);
  62. mGluonProgressOperationHandler = new Gluon.ProgressOperationHandler(this);
  63. mOperationProgressData = new OperationProgressData();
  64. ((IWorkspaceWindow)this).UpdateTitle();
  65. }
  66. internal bool IsOperationInProgress()
  67. {
  68. return mDeveloperProgressOperationHandler.IsOperationInProgress()
  69. || mGluonProgressOperationHandler.IsOperationInProgress();
  70. }
  71. internal void CancelCurrentOperation()
  72. {
  73. if (mDeveloperProgressOperationHandler.IsOperationInProgress())
  74. {
  75. mDeveloperProgressOperationHandler.CancelCheckinProgress();
  76. return;
  77. }
  78. if (mGluonProgressOperationHandler.IsOperationInProgress())
  79. {
  80. mGluonProgressOperationHandler.CancelUpdateProgress();
  81. return;
  82. }
  83. }
  84. internal void OnParentUpdated(double elapsedSeconds)
  85. {
  86. if (IsOperationInProgress() || mRequestedRepaint)
  87. {
  88. if (mDeveloperProgressOperationHandler.IsOperationInProgress())
  89. mDeveloperProgressOperationHandler.Update(elapsedSeconds);
  90. mPlasticWindow.Repaint();
  91. mRequestedRepaint = false;
  92. }
  93. }
  94. internal void RequestRepaint()
  95. {
  96. mRequestedRepaint = true;
  97. }
  98. internal void UpdateWorkspace()
  99. {
  100. UpdateWorkspaceOperation update = new UpdateWorkspaceOperation(
  101. mWkInfo, this, mSwitcher, mMergeViewLauncher, this,
  102. mDeveloperNewIncomingChangesUpdater,
  103. null);
  104. update.Run(
  105. UpdateWorkspaceOperation.UpdateType.UpdateToLatest,
  106. RefreshAsset.UnityAssetDatabase,
  107. null);
  108. }
  109. void IWorkspaceWindow.RefreshView(ViewType viewType)
  110. {
  111. mSwitcher.RefreshView(viewType);
  112. }
  113. void IWorkspaceWindow.RefreshWorkingObjectViews(
  114. ViewType viewType,
  115. WorkingObjectInfo workingObjectInfo)
  116. {
  117. mSwitcher.RefreshWorkingObjectInfoForSelectedView(
  118. viewType,
  119. workingObjectInfo);
  120. }
  121. void IWorkspaceWindow.UpdateTitle()
  122. {
  123. UpdateWorkspaceTitle();
  124. }
  125. bool IWorkspaceWindow.CheckOperationInProgress()
  126. {
  127. return mDeveloperProgressOperationHandler.CheckOperationInProgress();
  128. }
  129. void IWorkspaceWindow.ShowUpdateProgress(string title, UpdateNotifier notifier)
  130. {
  131. mDeveloperProgressOperationHandler.ShowUpdateProgress(title, mUpdateNotifierForTesting ?? notifier);
  132. }
  133. void IWorkspaceWindow.EndUpdateProgress()
  134. {
  135. mDeveloperProgressOperationHandler.EndUpdateProgress();
  136. }
  137. void IWorkspaceWindow.ShowCheckinProgress()
  138. {
  139. mDeveloperProgressOperationHandler.ShowCheckinProgress();
  140. }
  141. void IWorkspaceWindow.EndCheckinProgress()
  142. {
  143. mDeveloperProgressOperationHandler.EndCheckinProgress();
  144. }
  145. void IWorkspaceWindow.RefreshCheckinProgress(
  146. CheckinStatus checkinStatus,
  147. BuildProgressSpeedAndRemainingTime.ProgressData progressData)
  148. {
  149. mDeveloperProgressOperationHandler.
  150. RefreshCheckinProgress(checkinStatus, progressData);
  151. }
  152. bool IWorkspaceWindow.HasCheckinCancelled()
  153. {
  154. return mDeveloperProgressOperationHandler.HasCheckinCancelled();
  155. }
  156. void IWorkspaceWindow.ShowReplicationProgress(IReplicationOperation replicationOperation)
  157. {
  158. throw new NotImplementedException();
  159. }
  160. void IWorkspaceWindow.RefreshReplicationProgress(BranchReplicationData replicationData, ReplicationStatus replicationStatus, int current, int total)
  161. {
  162. throw new NotImplementedException();
  163. }
  164. void IWorkspaceWindow.EndReplicationProgress(ReplicationStatus replicationStatus)
  165. {
  166. throw new NotImplementedException();
  167. }
  168. void IWorkspaceWindow.ShowProgress()
  169. {
  170. mDeveloperProgressOperationHandler.ShowProgress();
  171. }
  172. void IWorkspaceWindow.ShowProgress(IProgressOperation progressOperation)
  173. {
  174. throw new NotImplementedException();
  175. }
  176. void IWorkspaceWindow.RefreshProgress(ProgressData progressData)
  177. {
  178. mDeveloperProgressOperationHandler.RefreshProgress(progressData);
  179. }
  180. void IWorkspaceWindow.EndProgress()
  181. {
  182. mDeveloperProgressOperationHandler.EndProgress();
  183. }
  184. EncryptionConfigurationDialogData IWorkspaceWindow.RequestEncryptionPassword(string server)
  185. {
  186. return EncryptionConfigurationDialog.RequestEncryptionPassword(server, mPlasticWindow);
  187. }
  188. void IRefreshView.ForType(ViewType viewType)
  189. {
  190. mSwitcher.RefreshView(viewType);
  191. }
  192. void IUpdateReport.Show(WorkspaceInfo wkInfo, IList reportLines)
  193. {
  194. UpdateReportDialog.ShowReportDialog(
  195. wkInfo,
  196. reportLines,
  197. mPlasticWindow);
  198. }
  199. void IGluonUpdateReport.AppendReport(string updateReport)
  200. {
  201. throw new NotImplementedException();
  202. }
  203. void IGluonWorkspaceStatusChangeListener.OnWorkspaceStatusChanged()
  204. {
  205. UpdateWorkspaceTitle();
  206. }
  207. void UpdateWorkspaceTitle()
  208. {
  209. WorkspaceStatusString.Data status = null;
  210. IThreadWaiter waiter = ThreadWaiter.GetWaiter();
  211. waiter.Execute(
  212. /*threadOperationDelegate*/ delegate
  213. {
  214. status = GetWorkspaceStatus(mWkInfo);
  215. },
  216. /*afterOperationDelegate*/ delegate
  217. {
  218. if (waiter.Exception != null)
  219. return;
  220. WorkspaceStatus = status;
  221. RequestRepaint();
  222. });
  223. }
  224. static WorkspaceStatusString.Data GetWorkspaceStatus(WorkspaceInfo wkInfo)
  225. {
  226. return WorkspaceStatusString.GetSelectorData(wkInfo);
  227. }
  228. bool mRequestedRepaint;
  229. UpdateNotifier mUpdateNotifierForTesting;
  230. IProgressControls mProgressControls;
  231. readonly OperationProgressData mOperationProgressData;
  232. readonly Developer.ProgressOperationHandler mDeveloperProgressOperationHandler;
  233. readonly Gluon.ProgressOperationHandler mGluonProgressOperationHandler;
  234. readonly GuiMessage.IGuiMessage mGuiMessage;
  235. readonly EditorWindow mPlasticWindow;
  236. readonly NewIncomingChangesUpdater mDeveloperNewIncomingChangesUpdater;
  237. readonly IMergeViewLauncher mMergeViewLauncher;
  238. readonly ViewSwitcher mSwitcher;
  239. readonly ViewHost mViewHost;
  240. readonly WorkspaceInfo mWkInfo;
  241. internal void RegisterPendingChangesProgressControls(
  242. ProgressControlsForViews progressControls)
  243. {
  244. mProgressControls = progressControls;
  245. }
  246. internal void UpdateWorkspaceForMode(
  247. bool isGluonMode,
  248. WorkspaceWindow workspaceWindow)
  249. {
  250. if (isGluonMode)
  251. {
  252. PartialUpdateWorkspace();
  253. return;
  254. }
  255. UpdateWorkspace();
  256. }
  257. UpdateReportResult IGluonUpdateReport.ShowUpdateReport(
  258. WorkspaceInfo wkInfo, List<ErrorMessage> errors)
  259. {
  260. return GluonUpdateReportDialog.ShowUpdateReport(
  261. wkInfo, errors, mPlasticWindow);
  262. }
  263. void PartialUpdateWorkspace()
  264. {
  265. mProgressControls.ShowProgress(PlasticLocalization.GetString(
  266. PlasticLocalization.Name.UpdatingWorkspace));
  267. ((IUpdateProgress)mGluonProgressOperationHandler).ShowCancelableProgress();
  268. OutOfDateUpdater outOfDateUpdater = new OutOfDateUpdater(mWkInfo, null);
  269. BuildProgressSpeedAndRemainingTime.ProgressData progressData =
  270. new BuildProgressSpeedAndRemainingTime.ProgressData(DateTime.Now);
  271. IThreadWaiter waiter = ThreadWaiter.GetWaiter();
  272. waiter.Execute(
  273. /*threadOperationDelegate*/ delegate
  274. {
  275. outOfDateUpdater.Execute();
  276. },
  277. /*afterOperationDelegate*/ delegate
  278. {
  279. mProgressControls.HideProgress();
  280. ((IUpdateProgress)mGluonProgressOperationHandler).EndProgress();
  281. mViewHost.RefreshView(ViewType.CheckinView);
  282. mViewHost.RefreshView(ViewType.IncomingChangesView);
  283. RefreshAsset.UnityAssetDatabase();
  284. if (waiter.Exception != null)
  285. {
  286. ExceptionsHandler.DisplayException(waiter.Exception);
  287. return;
  288. }
  289. ShowUpdateReportDialog(
  290. mWkInfo, mViewHost, outOfDateUpdater.Progress, mProgressControls,
  291. mGuiMessage, mGluonProgressOperationHandler, this);
  292. },
  293. /*timerTickDelegate*/ delegate
  294. {
  295. UpdateProgress progress = outOfDateUpdater.Progress;
  296. if (progress == null)
  297. return;
  298. if (progress.IsCanceled)
  299. {
  300. mProgressControls.ShowNotification(
  301. PlasticLocalization.GetString(PlasticLocalization.Name.Canceling));
  302. }
  303. ((IUpdateProgress)mGluonProgressOperationHandler).RefreshProgress(
  304. progress,
  305. UpdateProgressDataCalculator.CalculateProgressForWorkspaceUpdate(
  306. mWkInfo.ClientPath, progress, progressData));
  307. });
  308. }
  309. static void ShowUpdateReportDialog(
  310. WorkspaceInfo wkInfo,
  311. ViewHost viewHost,
  312. UpdateProgress progress,
  313. IProgressControls progressControls,
  314. GuiMessage.IGuiMessage guiMessage,
  315. IUpdateProgress updateProgress,
  316. IGluonUpdateReport updateReport)
  317. {
  318. if (progress.ErrorMessages.Count == 0)
  319. return;
  320. UpdateReportResult updateReportResult =
  321. updateReport.ShowUpdateReport(wkInfo, progress.ErrorMessages);
  322. if (!updateReportResult.IsUpdateForcedRequested())
  323. return;
  324. UpdateForcedOperation updateForced = new UpdateForcedOperation(
  325. wkInfo, viewHost, progress, progressControls,
  326. guiMessage, updateProgress, updateReport);
  327. updateForced.UpdateForced(
  328. updateReportResult.UpdateForcedPaths,
  329. updateReportResult.UnaffectedErrors);
  330. }
  331. }
  332. }