Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

BranchesTab.cs 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEditor;
  4. using UnityEditor.IMGUI.Controls;
  5. using UnityEngine;
  6. using Codice.CM.Common;
  7. using Codice.Client.Common.Threading;
  8. using PlasticGui;
  9. using PlasticGui.WorkspaceWindow;
  10. using PlasticGui.WorkspaceWindow.QueryViews;
  11. using PlasticGui.WorkspaceWindow.QueryViews.Branches;
  12. using PlasticGui.WorkspaceWindow.Update;
  13. using Unity.PlasticSCM.Editor.AssetUtils;
  14. using Unity.PlasticSCM.Editor.UI;
  15. using Unity.PlasticSCM.Editor.UI.Progress;
  16. using Unity.PlasticSCM.Editor.UI.Tree;
  17. using Unity.PlasticSCM.Editor.Views.Branches.Dialogs;
  18. using Unity.PlasticSCM.Editor.Views.Changesets;
  19. using GluonNewIncomingChangesUpdater = PlasticGui.Gluon.WorkspaceWindow.NewIncomingChangesUpdater;
  20. namespace Unity.PlasticSCM.Editor.Views.Branches
  21. {
  22. internal class BranchesTab :
  23. IRefreshableView,
  24. IBranchMenuOperations,
  25. IQueryRefreshableView
  26. {
  27. internal BranchesListView Table { get { return mBranchesListView; } }
  28. internal IBranchMenuOperations Operations { get { return this; } }
  29. internal BranchesTab(
  30. WorkspaceInfo wkInfo,
  31. IWorkspaceWindow workspaceWindow,
  32. IViewSwitcher viewSwitcher,
  33. IMergeViewLauncher mergeViewLauncher,
  34. IUpdateReport updateReport,
  35. NewIncomingChangesUpdater developerNewIncomingChangesUpdater,
  36. GluonNewIncomingChangesUpdater gluonNewIncomingChangesUpdater,
  37. EditorWindow parentWindow)
  38. {
  39. mWkInfo = wkInfo;
  40. mParentWindow = parentWindow;
  41. mProgressControls = new ProgressControlsForViews();
  42. mDeveloperNewIncomingChangesUpdater = developerNewIncomingChangesUpdater;
  43. mGluonNewIncomingChangesUpdater = gluonNewIncomingChangesUpdater;
  44. BuildComponents(
  45. wkInfo,
  46. workspaceWindow,
  47. viewSwitcher,
  48. mergeViewLauncher,
  49. updateReport,
  50. developerNewIncomingChangesUpdater,
  51. parentWindow);
  52. ((IRefreshableView)this).Refresh();
  53. }
  54. internal void Update()
  55. {
  56. mProgressControls.UpdateProgress(mParentWindow);
  57. }
  58. internal void OnGUI()
  59. {
  60. DoActionsToolbar(mProgressControls);
  61. DoBranchesArea(
  62. mBranchesListView,
  63. mProgressControls.IsOperationRunning());
  64. }
  65. internal void SetWorkingObjectInfo(WorkingObjectInfo homeInfo)
  66. {
  67. lock(mLock)
  68. {
  69. mLoadedBranchId = homeInfo.BranchInfo.BranchId;
  70. }
  71. mBranchesListView.SetLoadedBranchId(mLoadedBranchId);
  72. }
  73. static void DoBranchesArea(
  74. BranchesListView branchesListView,
  75. bool isOperationRunning)
  76. {
  77. EditorGUILayout.BeginVertical();
  78. GUI.enabled = !isOperationRunning;
  79. Rect rect = GUILayoutUtility.GetRect(0, 100000, 0, 100000);
  80. branchesListView.OnGUI(rect);
  81. GUI.enabled = true;
  82. EditorGUILayout.EndVertical();
  83. }
  84. internal void DrawSearchFieldForBranchesTab()
  85. {
  86. DrawSearchField.For(
  87. mSearchField,
  88. mBranchesListView,
  89. UnityConstants.SEARCH_FIELD_WIDTH);
  90. }
  91. internal void OnDisable()
  92. {
  93. mSearchField.downOrUpArrowKeyPressed -=
  94. SearchField_OnDownOrUpArrowKeyPressed;
  95. TreeHeaderSettings.Save(
  96. mBranchesListView.multiColumnHeader.state,
  97. UnityConstants.BRANCHES_TABLE_SETTINGS_NAME);
  98. }
  99. void IRefreshableView.Refresh()
  100. {
  101. // VCS-1005209 - There are scenarios where the list of branches need to check for incoming changes.
  102. // For example, deleting the active branch will automatically switch your workspace to the parent changeset,
  103. // which might have incoming changes.
  104. if (mDeveloperNewIncomingChangesUpdater != null)
  105. mDeveloperNewIncomingChangesUpdater.Update(DateTime.Now);
  106. if (mGluonNewIncomingChangesUpdater != null)
  107. mGluonNewIncomingChangesUpdater.Update(DateTime.Now);
  108. string query = GetBranchesQuery(mDateFilter);
  109. FillBranches(mWkInfo, query, BranchesSelection.GetSelectedRepObjectInfos(mBranchesListView));
  110. }
  111. //IQueryRefreshableView
  112. public void RefreshAndSelect(RepObjectInfo repObj)
  113. {
  114. string query = GetBranchesQuery(mDateFilter);
  115. FillBranches(mWkInfo,
  116. query,
  117. new List<RepObjectInfo> { repObj });
  118. }
  119. void FillBranches(WorkspaceInfo wkInfo, string query, List<RepObjectInfo> branchesToSelect)
  120. {
  121. if (mIsRefreshing)
  122. return;
  123. mIsRefreshing = true;
  124. int defaultRow = TableViewOperations.
  125. GetFirstSelectedRow(mBranchesListView);
  126. ((IProgressControls)mProgressControls).ShowProgress(
  127. PlasticLocalization.GetString(
  128. PlasticLocalization.Name.LoadingBranches));
  129. ViewQueryResult queryResult = null;
  130. IThreadWaiter waiter = ThreadWaiter.GetWaiter();
  131. waiter.Execute(
  132. /*threadOperationDelegate*/ delegate
  133. {
  134. long loadedBranchId = GetLoadedBranchId(wkInfo);
  135. lock(mLock)
  136. {
  137. mLoadedBranchId = loadedBranchId;
  138. }
  139. queryResult = new ViewQueryResult(
  140. PlasticGui.Plastic.API.FindQuery(wkInfo, query));
  141. },
  142. /*afterOperationDelegate*/ delegate
  143. {
  144. try
  145. {
  146. if (waiter.Exception != null)
  147. {
  148. ExceptionsHandler.DisplayException(waiter.Exception);
  149. return;
  150. }
  151. UpdateBranchesList(
  152. mBranchesListView,
  153. queryResult,
  154. mLoadedBranchId);
  155. int branchesCount = GetBranchesCount(queryResult);
  156. if (branchesCount == 0)
  157. {
  158. return;
  159. }
  160. BranchesSelection.SelectBranches(
  161. mBranchesListView, branchesToSelect, defaultRow);
  162. }
  163. finally
  164. {
  165. ((IProgressControls)mProgressControls).HideProgress();
  166. mIsRefreshing = false;
  167. }
  168. });
  169. }
  170. static long GetLoadedBranchId(WorkspaceInfo wkInfo)
  171. {
  172. BranchInfo brInfo = PlasticGui.Plastic.API.GetWorkingBranch(wkInfo);
  173. if (brInfo != null)
  174. return brInfo.BranchId;
  175. return -1;
  176. }
  177. static void UpdateBranchesList(
  178. BranchesListView branchesListView,
  179. ViewQueryResult queryResult,
  180. long loadedBranchId)
  181. {
  182. branchesListView.BuildModel(
  183. queryResult, loadedBranchId);
  184. branchesListView.Refilter();
  185. branchesListView.Sort();
  186. branchesListView.Reload();
  187. }
  188. internal static int GetBranchesCount(
  189. ViewQueryResult queryResult)
  190. {
  191. if (queryResult == null)
  192. return 0;
  193. return queryResult.Count();
  194. }
  195. internal static string GetBranchesQuery(DateFilter dateFilter)
  196. {
  197. if (dateFilter.FilterType == DateFilter.Type.AllTime)
  198. return QueryConstants.BranchesBeginningQuery;
  199. string whereClause = QueryConstants.GetDateWhereClause(
  200. dateFilter.GetTimeAgo());
  201. return string.Format("{0} {1}",
  202. QueryConstants.BranchesBeginningQuery,
  203. whereClause);
  204. }
  205. internal void DrawDateFilter()
  206. {
  207. GUI.enabled = !mProgressControls.IsOperationRunning();
  208. EditorGUI.BeginChangeCheck();
  209. mDateFilter.FilterType = (DateFilter.Type)
  210. EditorGUILayout.EnumPopup(
  211. mDateFilter.FilterType,
  212. EditorStyles.toolbarDropDown,
  213. GUILayout.Width(100));
  214. if (EditorGUI.EndChangeCheck())
  215. {
  216. EnumPopupSetting<DateFilter.Type>.Save(
  217. mDateFilter.FilterType,
  218. UnityConstants.BRANCHES_DATE_FILTER_SETTING_NAME);
  219. ((IRefreshableView)this).Refresh();
  220. }
  221. GUI.enabled = true;
  222. }
  223. void SearchField_OnDownOrUpArrowKeyPressed()
  224. {
  225. mBranchesListView.SetFocusAndEnsureSelectedItem();
  226. }
  227. static void DoActionsToolbar(
  228. ProgressControlsForViews progressControls)
  229. {
  230. EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
  231. if (progressControls.IsOperationRunning())
  232. {
  233. DrawProgressForViews.ForIndeterminateProgress(
  234. progressControls.ProgressData);
  235. }
  236. GUILayout.FlexibleSpace();
  237. EditorGUILayout.EndHorizontal();
  238. }
  239. void BuildComponents(
  240. WorkspaceInfo wkInfo,
  241. IWorkspaceWindow workspaceWindow,
  242. IViewSwitcher viewSwitcher,
  243. IMergeViewLauncher mergeViewLauncher,
  244. IUpdateReport updateReport,
  245. NewIncomingChangesUpdater developerNewIncomingChangesUpdater,
  246. EditorWindow parentWindow)
  247. {
  248. mSearchField = new SearchField();
  249. mSearchField.downOrUpArrowKeyPressed += SearchField_OnDownOrUpArrowKeyPressed;
  250. DateFilter.Type dateFilterType =
  251. EnumPopupSetting<DateFilter.Type>.Load(
  252. UnityConstants.BRANCHES_DATE_FILTER_SETTING_NAME,
  253. DateFilter.Type.LastMonth);
  254. mDateFilter = new DateFilter(dateFilterType);
  255. BranchesListHeaderState headerState =
  256. BranchesListHeaderState.GetDefault();
  257. TreeHeaderSettings.Load(headerState,
  258. UnityConstants.BRANCHES_TABLE_SETTINGS_NAME,
  259. (int)BranchesListColumn.CreationDate, false);
  260. mBranchesListView = new BranchesListView(
  261. headerState,
  262. BranchesListHeaderState.GetColumnNames(),
  263. new BranchesViewMenu(this),
  264. sizeChangedAction: OnBranchesListViewSizeChanged);
  265. mBranchesListView.Reload();
  266. mBranchOperations = new BranchOperations(
  267. wkInfo,
  268. workspaceWindow,
  269. viewSwitcher,
  270. mergeViewLauncher,
  271. this,
  272. ViewType.BranchesView,
  273. mProgressControls,
  274. updateReport,
  275. new ContinueWithPendingChangesQuestionerBuilder(viewSwitcher, parentWindow),
  276. developerNewIncomingChangesUpdater);
  277. }
  278. void OnBranchesListViewSizeChanged()
  279. {
  280. if (!mShouldScrollToSelection)
  281. return;
  282. mShouldScrollToSelection = false;
  283. TableViewOperations.ScrollToSelection(mBranchesListView);
  284. }
  285. int IBranchMenuOperations.GetSelectedBranchesCount()
  286. {
  287. return BranchesSelection.GetSelectedBranchesCount(mBranchesListView);
  288. }
  289. void IBranchMenuOperations.CreateBranch()
  290. {
  291. RepositorySpec repSpec = BranchesSelection.GetSelectedRepository(mBranchesListView);
  292. BranchInfo branchInfo = BranchesSelection.GetSelectedBranch(mBranchesListView);
  293. BranchCreationData branchCreationData = CreateBranchDialog.CreateBranchFromLastParentBranchChangeset(
  294. mParentWindow,
  295. repSpec,
  296. branchInfo);
  297. mBranchOperations.CreateBranch(
  298. branchCreationData,
  299. RefreshAsset.BeforeLongAssetOperation,
  300. RefreshAsset.AfterLongAssetOperation);
  301. }
  302. void IBranchMenuOperations.CreateTopLevelBranch() { }
  303. void IBranchMenuOperations.SwitchToBranch()
  304. {
  305. RepositorySpec repSpec = BranchesSelection.GetSelectedRepository(mBranchesListView);
  306. BranchInfo branchInfo = BranchesSelection.GetSelectedBranch(mBranchesListView);
  307. mBranchOperations.SwitchToBranch(
  308. repSpec,
  309. branchInfo,
  310. RefreshAsset.BeforeLongAssetOperation,
  311. RefreshAsset.AfterLongAssetOperation);
  312. }
  313. void IBranchMenuOperations.MergeBranch() { }
  314. void IBranchMenuOperations.CherrypickBranch() { }
  315. void IBranchMenuOperations.MergeToBranch() { }
  316. void IBranchMenuOperations.PullBranch() { }
  317. void IBranchMenuOperations.PullRemoteBranch() { }
  318. void IBranchMenuOperations.SyncWithGit() { }
  319. void IBranchMenuOperations.PushBranch() { }
  320. void IBranchMenuOperations.DiffBranch() { }
  321. void IBranchMenuOperations.DiffWithAnotherBranch() { }
  322. void IBranchMenuOperations.ViewChangesets() { }
  323. void IBranchMenuOperations.RenameBranch()
  324. {
  325. RepositorySpec repSpec = BranchesSelection.GetSelectedRepository(mBranchesListView);
  326. BranchInfo branchInfo = BranchesSelection.GetSelectedBranch(mBranchesListView);
  327. BranchRenameData branchRenameData = RenameBranchDialog.GetBranchRenameData(
  328. repSpec,
  329. branchInfo,
  330. mParentWindow);
  331. mBranchOperations.RenameBranch(branchRenameData);
  332. }
  333. void IBranchMenuOperations.DeleteBranch()
  334. {
  335. RepositorySpec repSpec = BranchesSelection.GetSelectedRepository(mBranchesListView);
  336. List<RepositorySpec> repositories = BranchesSelection.GetSelectedRepositories(mBranchesListView);
  337. List<BranchInfo> branchesToDelete = BranchesSelection.GetSelectedBranches(mBranchesListView);
  338. mBranchOperations.DeleteBranch(repositories, branchesToDelete);
  339. }
  340. void IBranchMenuOperations.CreateCodeReview() { }
  341. void IBranchMenuOperations.ViewPermissions() { }
  342. SearchField mSearchField;
  343. bool mIsRefreshing;
  344. DateFilter mDateFilter;
  345. bool mShouldScrollToSelection;
  346. BranchesListView mBranchesListView;
  347. BranchOperations mBranchOperations;
  348. long mLoadedBranchId = -1;
  349. object mLock = new object();
  350. readonly WorkspaceInfo mWkInfo;
  351. readonly ProgressControlsForViews mProgressControls;
  352. readonly EditorWindow mParentWindow;
  353. readonly NewIncomingChangesUpdater mDeveloperNewIncomingChangesUpdater;
  354. readonly GluonNewIncomingChangesUpdater mGluonNewIncomingChangesUpdater;
  355. }
  356. }