PendingChangesTab_Operations.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. using System.Collections.Generic;
  2. using Codice.Client.BaseCommands;
  3. using Codice.Client.BaseCommands.EventTracking;
  4. using Codice.CM.Common;
  5. using GluonGui.WorkspaceWindow.Views.Checkin.Operations;
  6. using PlasticGui;
  7. using Unity.PlasticSCM.Editor.AssetUtils;
  8. using Unity.PlasticSCM.Editor.UI;
  9. using Unity.PlasticSCM.Editor.Views.PendingChanges.Dialogs;
  10. namespace Unity.PlasticSCM.Editor.Views.PendingChanges
  11. {
  12. internal partial class PendingChangesTab
  13. {
  14. void CheckinForMode(WorkspaceInfo wkInfo, bool isGluonMode, bool keepItemsLocked)
  15. {
  16. TrackFeatureUseEvent.For(
  17. PlasticGui.Plastic.API.GetRepositorySpec(wkInfo),
  18. isGluonMode ?
  19. TrackFeatureUseEvent.Features.PartialCheckin :
  20. TrackFeatureUseEvent.Features.Checkin);
  21. if (isGluonMode)
  22. {
  23. PartialCheckin(keepItemsLocked);
  24. return;
  25. }
  26. Checkin();
  27. }
  28. void UndoForMode(WorkspaceInfo wkInfo, bool isGluonMode)
  29. {
  30. TrackFeatureUseEvent.For(
  31. PlasticGui.Plastic.API.GetRepositorySpec(wkInfo),
  32. isGluonMode ?
  33. TrackFeatureUseEvent.Features.PartialUndo :
  34. TrackFeatureUseEvent.Features.Undo);
  35. if (isGluonMode)
  36. {
  37. PartialUndo();
  38. return;
  39. }
  40. Undo();
  41. }
  42. void UndoChangesForMode(
  43. bool isGluonMode,
  44. List<ChangeInfo> changesToUndo,
  45. List<ChangeInfo> dependenciesCandidates)
  46. {
  47. if (isGluonMode)
  48. {
  49. PartialUndoChanges(changesToUndo, dependenciesCandidates);
  50. return;
  51. }
  52. UndoChanges(changesToUndo, dependenciesCandidates);
  53. }
  54. void PartialCheckin(bool keepItemsLocked)
  55. {
  56. List<ChangeInfo> changesToCheckin;
  57. List<ChangeInfo> dependenciesCandidates;
  58. mPendingChangesTreeView.GetCheckedChanges(
  59. false,
  60. out changesToCheckin,
  61. out dependenciesCandidates);
  62. if (CheckEmptyOperation(changesToCheckin))
  63. {
  64. ((IProgressControls)mProgressControls).ShowWarning(
  65. PlasticLocalization.GetString(PlasticLocalization.Name.NoItemsAreSelected));
  66. return;
  67. }
  68. bool isCancelled;
  69. SaveAssets.ForChangesWithConfirmation(changesToCheckin, out isCancelled);
  70. if (isCancelled)
  71. return;
  72. CheckinUIOperation ciOperation = new CheckinUIOperation(
  73. mWkInfo, mViewHost, mProgressControls, mGuiMessage,
  74. new LaunchCheckinConflictsDialog(mParentWindow),
  75. new LaunchDependenciesDialog(
  76. PlasticLocalization.GetString(PlasticLocalization.Name.CheckinButton),
  77. mParentWindow),
  78. this, mWorkspaceWindow.GluonProgressOperationHandler);
  79. ciOperation.Checkin(
  80. changesToCheckin,
  81. dependenciesCandidates,
  82. CommentText,
  83. keepItemsLocked,
  84. RefreshAsset.UnityAssetDatabase);
  85. }
  86. void Checkin()
  87. {
  88. List<ChangeInfo> changesToCheckin;
  89. List<ChangeInfo> dependenciesCandidates;
  90. mPendingChangesTreeView.GetCheckedChanges(
  91. false, out changesToCheckin, out dependenciesCandidates);
  92. if (CheckEmptyOperation(changesToCheckin, HasPendingMergeLinks()))
  93. {
  94. ((IProgressControls)mProgressControls).ShowWarning(
  95. PlasticLocalization.GetString(PlasticLocalization.Name.NoItemsAreSelected));
  96. return;
  97. }
  98. bool isCancelled;
  99. SaveAssets.ForChangesWithConfirmation(changesToCheckin, out isCancelled);
  100. if (isCancelled)
  101. return;
  102. mPendingChangesOperations.Checkin(
  103. changesToCheckin,
  104. dependenciesCandidates,
  105. CommentText,
  106. null,
  107. EndCheckin);
  108. }
  109. void PartialUndo()
  110. {
  111. List<ChangeInfo> changesToUndo;
  112. List<ChangeInfo> dependenciesCandidates;
  113. mPendingChangesTreeView.GetCheckedChanges(
  114. true, out changesToUndo, out dependenciesCandidates);
  115. PartialUndoChanges(changesToUndo, dependenciesCandidates);
  116. }
  117. void Undo()
  118. {
  119. List<ChangeInfo> changesToUndo;
  120. List<ChangeInfo> dependenciesCandidates;
  121. mPendingChangesTreeView.GetCheckedChanges(
  122. true, out changesToUndo, out dependenciesCandidates);
  123. UndoChanges(changesToUndo, dependenciesCandidates);
  124. }
  125. void PartialUndoChanges(
  126. List<ChangeInfo> changesToUndo,
  127. List<ChangeInfo> dependenciesCandidates)
  128. {
  129. if (CheckEmptyOperation(changesToUndo))
  130. {
  131. ((IProgressControls)mProgressControls).ShowWarning(
  132. PlasticLocalization.GetString(PlasticLocalization.Name.NoItemsToUndo));
  133. return;
  134. }
  135. SaveAssets.ForChangesWithoutConfirmation(changesToUndo);
  136. UndoUIOperation undoOperation = new UndoUIOperation(
  137. mWkInfo, mViewHost,
  138. new LaunchDependenciesDialog(
  139. PlasticLocalization.GetString(PlasticLocalization.Name.UndoButton),
  140. mParentWindow),
  141. mProgressControls, mGuiMessage);
  142. undoOperation.Undo(
  143. changesToUndo,
  144. dependenciesCandidates,
  145. RefreshAsset.UnityAssetDatabase);
  146. }
  147. void UndoChanges(
  148. List<ChangeInfo> changesToUndo,
  149. List<ChangeInfo> dependenciesCandidates)
  150. {
  151. if (CheckEmptyOperation(changesToUndo, HasPendingMergeLinks()))
  152. {
  153. ((IProgressControls)mProgressControls).ShowWarning(
  154. PlasticLocalization.GetString(PlasticLocalization.Name.NoItemsToUndo));
  155. return;
  156. }
  157. SaveAssets.ForChangesWithoutConfirmation(changesToUndo);
  158. mPendingChangesOperations.Undo(
  159. changesToUndo,
  160. dependenciesCandidates,
  161. mPendingMergeLinks.Count,
  162. RefreshAsset.UnityAssetDatabase);
  163. }
  164. void EndCheckin()
  165. {
  166. // TODO: Localization
  167. mNotificationDrawer.Notify("Checkin successfully completed", UnityEditor.MessageType.None, Images.Name.StepOk);
  168. RefreshAsset.UnityAssetDatabase();
  169. }
  170. static bool CheckEmptyOperation(List<ChangeInfo> elements)
  171. {
  172. return elements == null || elements.Count == 0;
  173. }
  174. static bool CheckEmptyOperation(List<ChangeInfo> elements, bool bHasPendingMergeLinks)
  175. {
  176. if (bHasPendingMergeLinks)
  177. return false;
  178. if (elements != null && elements.Count > 0)
  179. return false;
  180. return true;
  181. }
  182. }
  183. }