DependenciesDialog.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using System.Collections.Generic;
  2. using UnityEditor;
  3. using UnityEngine;
  4. using Codice.Client.BaseCommands;
  5. using Codice.CM.Common;
  6. using PlasticGui;
  7. using PlasticGui.WorkspaceWindow.PendingChanges;
  8. using Unity.PlasticSCM.Editor.UI;
  9. namespace Unity.PlasticSCM.Editor.Views.PendingChanges.Dialogs
  10. {
  11. internal class DependenciesDialog : PlasticDialog
  12. {
  13. protected override Rect DefaultRect
  14. {
  15. get
  16. {
  17. var baseRect = base.DefaultRect;
  18. return new Rect(baseRect.x, baseRect.y, 650, 430);
  19. }
  20. }
  21. internal static bool IncludeDependencies(
  22. WorkspaceInfo wkInfo,
  23. IList<ChangeDependencies<ChangeInfo>> changesDependencies,
  24. string operation,
  25. EditorWindow parentWindow)
  26. {
  27. DependenciesDialog dialog = Create(wkInfo, changesDependencies, operation);
  28. return dialog.RunModal(parentWindow) == ResponseType.Ok;
  29. }
  30. protected override void OnModalGUI()
  31. {
  32. using (new EditorGUILayout.HorizontalScope())
  33. {
  34. Title(PlasticLocalization.GetString(
  35. PlasticLocalization.Name.DependenciesDialogTitle));
  36. }
  37. Paragraph(PlasticLocalization.GetString(
  38. PlasticLocalization.Name.DependenciesExplanation, mOperation));
  39. Title(PlasticLocalization.GetString(PlasticLocalization.Name.ItemColumn));
  40. Rect scrollWidth = GUILayoutUtility.GetRect(0, position.width, 1, 1);
  41. GUI.DrawTexture(
  42. new Rect(scrollWidth.x, scrollWidth.y, scrollWidth.width, 200),
  43. Texture2D.whiteTexture);
  44. DoDependenciesArea();
  45. GUILayout.Space(20);
  46. DoButtonsArea();
  47. }
  48. protected override string GetTitle()
  49. {
  50. return PlasticLocalization.GetString(
  51. PlasticLocalization.Name.DependenciesDialogTitle);
  52. }
  53. void DoDependenciesArea()
  54. {
  55. // NOTE(rafa): We cannot use a tree view here because it misbehaves with the way we create the modals
  56. mScrollPosition = EditorGUILayout.BeginScrollView(mScrollPosition, GUILayout.Height(200));
  57. for (int i = 0; i < mChangesDependencies.Count; i++)
  58. {
  59. var dependant = mChangesDependencies[i];
  60. bool isExpanded = mExpandedDependencies[i];
  61. isExpanded = EditorGUILayout.Foldout(
  62. isExpanded,
  63. ChangeInfoView.GetPathDescription(
  64. mWkInfo.ClientPath, dependant.Change),
  65. UnityStyles.Dialog.Foldout);
  66. mExpandedDependencies[i] = isExpanded;
  67. if (isExpanded)
  68. {
  69. for (int j = 0; j < dependant.Dependencies.Count; j++)
  70. {
  71. using (new EditorGUILayout.HorizontalScope())
  72. {
  73. GUILayout.Space(20);
  74. GUILayout.Label(
  75. ChangeInfoView.GetPathDescription(
  76. mWkInfo.ClientPath, dependant.Dependencies[j]),
  77. UnityStyles.Paragraph);
  78. }
  79. }
  80. }
  81. }
  82. EditorGUILayout.EndScrollView();
  83. }
  84. void DoButtonsArea()
  85. {
  86. using (new EditorGUILayout.HorizontalScope())
  87. {
  88. GUILayout.FlexibleSpace();
  89. if (Application.platform == RuntimePlatform.WindowsEditor)
  90. {
  91. DoOkButton();
  92. DoCancelButton();
  93. return;
  94. }
  95. DoCancelButton();
  96. DoOkButton();
  97. }
  98. }
  99. void DoOkButton()
  100. {
  101. if (!AcceptButton(mOperation))
  102. return;
  103. OkButtonAction();
  104. }
  105. void DoCancelButton()
  106. {
  107. if (!NormalButton(PlasticLocalization.GetString(
  108. PlasticLocalization.Name.CancelButton)))
  109. return;
  110. CancelButtonAction();
  111. }
  112. static DependenciesDialog Create(
  113. WorkspaceInfo wkInfo,
  114. IList<ChangeDependencies<ChangeInfo>> changesDependencies,
  115. string operation)
  116. {
  117. var instance = CreateInstance<DependenciesDialog>();
  118. instance.mWkInfo = wkInfo;
  119. instance.mChangesDependencies = changesDependencies;
  120. instance.mOperation = operation;
  121. instance.mEnterKeyAction = instance.OkButtonAction;
  122. instance.mEscapeKeyAction = instance.CancelButtonAction;
  123. instance.mExpandedDependencies = new bool[changesDependencies.Count];
  124. for (int i = 0; i < changesDependencies.Count; i++)
  125. instance.mExpandedDependencies[i] = true;
  126. return instance;
  127. }
  128. bool[] mExpandedDependencies;
  129. Vector2 mScrollPosition;
  130. string mOperation;
  131. IList<ChangeDependencies<ChangeInfo>> mChangesDependencies;
  132. WorkspaceInfo mWkInfo;
  133. }
  134. }