暫無描述
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

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