No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WorkspaceWindow.cs 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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. }
  202. void IGluonWorkspaceStatusChangeListener.OnWorkspaceStatusChanged()
  203. {
  204. UpdateWorkspaceTitle();
  205. }
  206. void UpdateWorkspaceTitle()
  207. {
  208. WorkspaceStatusString.Data status = null;
  209. IThreadWaiter waiter = ThreadWaiter.GetWaiter();
  210. waiter.Execute(
  211. /*threadOperationDelegate*/ delegate
  212. {
  213. status = WorkspaceStatusString.GetSelectorData(mWkInfo);
  214. },
  215. /*afterOperationDelegate*/ delegate
  216. {
  217. if (waiter.Exception != null)
  218. return;
  219. WorkspaceStatus = status;
  220. RequestRepaint();
  221. });
  222. }
  223. bool mRequestedRepaint;
  224. UpdateNotifier mUpdateNotifierForTesting;
  225. IProgressControls mProgressControls;
  226. readonly OperationProgressData mOperationProgressData;
  227. readonly Developer.ProgressOperationHandler mDeveloperProgressOperationHandler;
  228. readonly Gluon.ProgressOperationHandler mGluonProgressOperationHandler;
  229. readonly GuiMessage.IGuiMessage mGuiMessage;
  230. readonly EditorWindow mPlasticWindow;
  231. readonly NewIncomingChangesUpdater mDeveloperNewIncomingChangesUpdater;
  232. readonly IMergeViewLauncher mMergeViewLauncher;
  233. readonly ViewSwitcher mSwitcher;
  234. readonly ViewHost mViewHost;
  235. readonly WorkspaceInfo mWkInfo;
  236. internal void RegisterPendingChangesProgressControls(
  237. ProgressControlsForViews progressControls)
  238. {
  239. mProgressControls = progressControls;
  240. }
  241. internal void UpdateWorkspaceForMode(
  242. bool isGluonMode,
  243. WorkspaceWindow workspaceWindow)
  244. {
  245. if (isGluonMode)
  246. {
  247. PartialUpdateWorkspace();
  248. return;
  249. }
  250. UpdateWorkspace();
  251. }
  252. UpdateReportResult IGluonUpdateReport.ShowUpdateReport(
  253. WorkspaceInfo wkInfo, List<ErrorMessage> errors)
  254. {
  255. return GluonUpdateReportDialog.ShowUpdateReport(
  256. wkInfo, errors, mPlasticWindow);
  257. }
  258. void PartialUpdateWorkspace()
  259. {
  260. mProgressControls.ShowProgress(PlasticLocalization.GetString(
  261. PlasticLocalization.Name.UpdatingWorkspace));
  262. ((IUpdateProgress)mGluonProgressOperationHandler).ShowCancelableProgress();
  263. OutOfDateUpdater outOfDateUpdater = new OutOfDateUpdater(mWkInfo, null);
  264. BuildProgressSpeedAndRemainingTime.ProgressData progressData =
  265. new BuildProgressSpeedAndRemainingTime.ProgressData(DateTime.Now);
  266. IThreadWaiter waiter = ThreadWaiter.GetWaiter();
  267. waiter.Execute(
  268. /*threadOperationDelegate*/ delegate
  269. {
  270. outOfDateUpdater.Execute();
  271. },
  272. /*afterOperationDelegate*/ delegate
  273. {
  274. mProgressControls.HideProgress();
  275. ((IUpdateProgress)mGluonProgressOperationHandler).EndProgress();
  276. mViewHost.RefreshView(ViewType.CheckinView);
  277. mViewHost.RefreshView(ViewType.IncomingChangesView);
  278. RefreshAsset.UnityAssetDatabase();
  279. if (waiter.Exception != null)
  280. {
  281. ExceptionsHandler.DisplayException(waiter.Exception);
  282. return;
  283. }
  284. ShowUpdateReportDialog(
  285. mWkInfo, mViewHost, outOfDateUpdater.Progress, mProgressControls,
  286. mGuiMessage, mGluonProgressOperationHandler, this);
  287. },
  288. /*timerTickDelegate*/ delegate
  289. {
  290. UpdateProgress progress = outOfDateUpdater.Progress;
  291. if (progress == null)
  292. return;
  293. if (progress.IsCanceled)
  294. {
  295. mProgressControls.ShowNotification(
  296. PlasticLocalization.GetString(PlasticLocalization.Name.Canceling));
  297. }
  298. ((IUpdateProgress)mGluonProgressOperationHandler).RefreshProgress(
  299. progress,
  300. UpdateProgressDataCalculator.CalculateProgressForWorkspaceUpdate(
  301. mWkInfo.ClientPath, progress, progressData));
  302. });
  303. }
  304. static void ShowUpdateReportDialog(
  305. WorkspaceInfo wkInfo,
  306. ViewHost viewHost,
  307. UpdateProgress progress,
  308. IProgressControls progressControls,
  309. GuiMessage.IGuiMessage guiMessage,
  310. IUpdateProgress updateProgress,
  311. IGluonUpdateReport updateReport)
  312. {
  313. if (progress.ErrorMessages.Count == 0)
  314. return;
  315. UpdateReportResult updateReportResult =
  316. updateReport.ShowUpdateReport(wkInfo, progress.ErrorMessages);
  317. if (!updateReportResult.IsUpdateForcedRequested())
  318. return;
  319. UpdateForcedOperation updateForced = new UpdateForcedOperation(
  320. wkInfo, viewHost, progress, progressControls,
  321. guiMessage, updateProgress, updateReport);
  322. updateForced.UpdateForced(
  323. updateReportResult.UpdateForcedPaths,
  324. updateReportResult.UnaffectedErrors);
  325. }
  326. }
  327. }