WorkspaceWindow.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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.Replication;
  17. using PlasticGui.WorkspaceWindow.Update;
  18. using Unity.PlasticSCM.Editor.AssetUtils;
  19. using Unity.PlasticSCM.Editor.Configuration;
  20. using Unity.PlasticSCM.Editor.Developer.UpdateReport;
  21. using Unity.PlasticSCM.Editor.UI;
  22. using Unity.PlasticSCM.Editor.UI.Progress;
  23. using IGluonUpdateReport = PlasticGui.Gluon.IUpdateReport;
  24. using GluonUpdateReportDialog = Unity.PlasticSCM.Editor.Gluon.UpdateReport.UpdateReportDialog;
  25. namespace Unity.PlasticSCM.Editor
  26. {
  27. internal class WorkspaceWindow :
  28. IWorkspaceWindow,
  29. IUpdateReport,
  30. IGluonUpdateReport
  31. {
  32. internal void SetUpdateNotifierForTesting(UpdateNotifier updateNotifier)
  33. {
  34. mUpdateNotifierForTesting = updateNotifier;
  35. }
  36. internal string HeaderTitle { get; private set; }
  37. internal OperationProgressData Progress { get { return mOperationProgressData; } }
  38. internal Gluon.ProgressOperationHandler GluonProgressOperationHandler
  39. {
  40. get { return mGluonProgressOperationHandler; }
  41. }
  42. internal WorkspaceWindow(
  43. WorkspaceInfo wkInfo,
  44. ViewHost viewHost,
  45. ViewSwitcher switcher,
  46. IMergeViewLauncher mergeViewLauncher,
  47. NewIncomingChangesUpdater developerNewIncomingChangesUpdater,
  48. EditorWindow parentWindow)
  49. {
  50. mWkInfo = wkInfo;
  51. mViewHost = viewHost;
  52. mSwitcher = switcher;
  53. mMergeViewLauncher = mergeViewLauncher;
  54. mDeveloperNewIncomingChangesUpdater = developerNewIncomingChangesUpdater;
  55. mPlasticWindow = parentWindow;
  56. mGuiMessage = new UnityPlasticGuiMessage(parentWindow);
  57. mDeveloperProgressOperationHandler = new Developer.ProgressOperationHandler(mWkInfo, this);
  58. mGluonProgressOperationHandler = new Gluon.ProgressOperationHandler(this);
  59. mOperationProgressData = new OperationProgressData();
  60. ((IWorkspaceWindow)this).UpdateTitle();
  61. }
  62. internal bool IsOperationInProgress()
  63. {
  64. return mDeveloperProgressOperationHandler.IsOperationInProgress()
  65. || mGluonProgressOperationHandler.IsOperationInProgress();
  66. }
  67. internal void CancelCurrentOperation()
  68. {
  69. if (mDeveloperProgressOperationHandler.IsOperationInProgress())
  70. {
  71. mDeveloperProgressOperationHandler.CancelCheckinProgress();
  72. return;
  73. }
  74. if (mGluonProgressOperationHandler.IsOperationInProgress())
  75. {
  76. mGluonProgressOperationHandler.CancelUpdateProgress();
  77. return;
  78. }
  79. }
  80. internal void OnParentUpdated(double elapsedSeconds)
  81. {
  82. if (IsOperationInProgress() || mRequestedRepaint)
  83. {
  84. if (mDeveloperProgressOperationHandler.IsOperationInProgress())
  85. mDeveloperProgressOperationHandler.Update(elapsedSeconds);
  86. mPlasticWindow.Repaint();
  87. mRequestedRepaint = false;
  88. }
  89. }
  90. internal void RequestRepaint()
  91. {
  92. mRequestedRepaint = true;
  93. }
  94. internal void UpdateWorkspace()
  95. {
  96. UpdateWorkspaceOperation update = new UpdateWorkspaceOperation(
  97. mWkInfo, this, mSwitcher, mMergeViewLauncher, this,
  98. mDeveloperNewIncomingChangesUpdater,
  99. null);
  100. update.Run(
  101. UpdateWorkspaceOperation.UpdateType.UpdateToLatest,
  102. RefreshAsset.UnityAssetDatabase);
  103. }
  104. void IWorkspaceWindow.RefreshView(ViewType viewType)
  105. {
  106. mSwitcher.RefreshView(viewType);
  107. }
  108. void IWorkspaceWindow.UpdateTitle()
  109. {
  110. string title = string.Empty;
  111. IThreadWaiter waiter = ThreadWaiter.GetWaiter();
  112. waiter.Execute(
  113. /*threadOperationDelegate*/ delegate
  114. {
  115. title = GetTitle(mWkInfo);
  116. },
  117. /*afterOperationDelegate*/ delegate
  118. {
  119. if (waiter.Exception != null)
  120. return;
  121. HeaderTitle = title;
  122. RequestRepaint();
  123. });
  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 IUpdateReport.Show(WorkspaceInfo wkInfo, IList reportLines)
  189. {
  190. UpdateReportDialog.ShowReportDialog(
  191. wkInfo,
  192. reportLines,
  193. mPlasticWindow);
  194. }
  195. void IGluonUpdateReport.AppendReport(string updateReport)
  196. {
  197. throw new NotImplementedException();
  198. }
  199. static string GetTitle(WorkspaceInfo wkInfo)
  200. {
  201. WorkspaceStatusString.Data wkStatusData =
  202. WorkspaceStatusString.GetSelectorData(wkInfo);
  203. return string.Format("{0} {1} @ {2} @ {3}",
  204. wkStatusData.ObjectName,
  205. wkStatusData.ObjectSpec,
  206. wkStatusData.RepositoryName,
  207. wkStatusData.Server);
  208. }
  209. bool mRequestedRepaint;
  210. UpdateNotifier mUpdateNotifierForTesting;
  211. IProgressControls mProgressControls;
  212. readonly OperationProgressData mOperationProgressData;
  213. readonly Developer.ProgressOperationHandler mDeveloperProgressOperationHandler;
  214. readonly Gluon.ProgressOperationHandler mGluonProgressOperationHandler;
  215. readonly GuiMessage.IGuiMessage mGuiMessage;
  216. readonly EditorWindow mPlasticWindow;
  217. readonly NewIncomingChangesUpdater mDeveloperNewIncomingChangesUpdater;
  218. readonly IMergeViewLauncher mMergeViewLauncher;
  219. readonly ViewSwitcher mSwitcher;
  220. readonly ViewHost mViewHost;
  221. readonly WorkspaceInfo mWkInfo;
  222. internal void RegisterPendingChangesProgressControls(
  223. ProgressControlsForViews progressControls)
  224. {
  225. mProgressControls = progressControls;
  226. }
  227. internal void UpdateWorkspaceForMode(
  228. bool isGluonMode,
  229. WorkspaceWindow workspaceWindow)
  230. {
  231. if (isGluonMode)
  232. {
  233. PartialUpdateWorkspace();
  234. return;
  235. }
  236. UpdateWorkspace();
  237. }
  238. UpdateReportResult IGluonUpdateReport.ShowUpdateReport(
  239. WorkspaceInfo wkInfo, List<ErrorMessage> errors)
  240. {
  241. return GluonUpdateReportDialog.ShowUpdateReport(
  242. wkInfo, errors, mPlasticWindow);
  243. }
  244. void PartialUpdateWorkspace()
  245. {
  246. mProgressControls.ShowProgress(PlasticLocalization.GetString(
  247. PlasticLocalization.Name.UpdatingWorkspace));
  248. ((IUpdateProgress)mGluonProgressOperationHandler).ShowCancelableProgress();
  249. OutOfDateUpdater outOfDateUpdater = new OutOfDateUpdater(mWkInfo);
  250. BuildProgressSpeedAndRemainingTime.ProgressData progressData =
  251. new BuildProgressSpeedAndRemainingTime.ProgressData(DateTime.Now);
  252. IThreadWaiter waiter = ThreadWaiter.GetWaiter();
  253. waiter.Execute(
  254. /*threadOperationDelegate*/ delegate
  255. {
  256. outOfDateUpdater.Execute();
  257. },
  258. /*afterOperationDelegate*/ delegate
  259. {
  260. mProgressControls.HideProgress();
  261. ((IUpdateProgress)mGluonProgressOperationHandler).EndProgress();
  262. mViewHost.RefreshView(ViewType.CheckinView);
  263. mViewHost.RefreshView(ViewType.IncomingChangesView);
  264. RefreshAsset.UnityAssetDatabase();
  265. if (waiter.Exception != null)
  266. {
  267. ExceptionsHandler.DisplayException(waiter.Exception);
  268. return;
  269. }
  270. ShowUpdateReportDialog(
  271. mWkInfo, mViewHost, outOfDateUpdater.Progress, mProgressControls,
  272. mGuiMessage, mGluonProgressOperationHandler, this);
  273. },
  274. /*timerTickDelegate*/ delegate
  275. {
  276. UpdateProgress progress = outOfDateUpdater.Progress;
  277. if (progress == null)
  278. return;
  279. if (progress.IsCanceled)
  280. {
  281. mProgressControls.ShowNotification(
  282. PlasticLocalization.GetString(PlasticLocalization.Name.Canceling));
  283. }
  284. ((IUpdateProgress)mGluonProgressOperationHandler).RefreshProgress(
  285. progress,
  286. UpdateProgressDataCalculator.CalculateProgressForWorkspaceUpdate(
  287. mWkInfo.ClientPath, progress, progressData));
  288. });
  289. }
  290. static void ShowUpdateReportDialog(
  291. WorkspaceInfo wkInfo,
  292. ViewHost viewHost,
  293. UpdateProgress progress,
  294. IProgressControls progressControls,
  295. GuiMessage.IGuiMessage guiMessage,
  296. IUpdateProgress updateProgress,
  297. IGluonUpdateReport updateReport)
  298. {
  299. if (progress.ErrorMessages.Count == 0)
  300. return;
  301. UpdateReportResult updateReportResult =
  302. updateReport.ShowUpdateReport(wkInfo, progress.ErrorMessages);
  303. if (!updateReportResult.IsUpdateForcedRequested())
  304. return;
  305. UpdateForcedOperation updateForced = new UpdateForcedOperation(
  306. wkInfo, viewHost, progress, progressControls,
  307. guiMessage, updateProgress, updateReport);
  308. updateForced.UpdateForced(
  309. updateReportResult.UpdateForcedPaths,
  310. updateReportResult.UnaffectedErrors);
  311. }
  312. }
  313. }