PageRenderTime 28ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/VoteMario/Library/PackageCache/com.unity.collab-proxy@1.13.5/Editor/PlasticSCM/Views/Changesets/ChangesetsListView.cs

https://gitlab.com/Surabhi124/vote-mario
C# | 418 lines | 333 code | 85 blank | 0 comment | 40 complexity | 7d485d089a408c728289452cb1b8dbc9 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor.IMGUI.Controls;
  5. using Codice.CM.Common;
  6. using PlasticGui;
  7. using PlasticGui.WorkspaceWindow.QueryViews;
  8. using Unity.PlasticSCM.Editor.UI;
  9. using Unity.PlasticSCM.Editor.UI.Avatar;
  10. using Unity.PlasticSCM.Editor.UI.Tree;
  11. namespace Unity.PlasticSCM.Editor.Views.Changesets
  12. {
  13. internal class ChangesetsListView : TreeView
  14. {
  15. internal ChangesetsListView(
  16. ChangesetsListHeaderState headerState,
  17. List<string> columnNames,
  18. ChangesetsViewMenu menu,
  19. Action sizeChangedAction,
  20. Action selectionChangedAction,
  21. Action doubleClickAction)
  22. : base(new TreeViewState())
  23. {
  24. mColumnNames = columnNames;
  25. mMenu = menu;
  26. mSizeChangedAction = sizeChangedAction;
  27. mSelectionChangedAction = selectionChangedAction;
  28. mDoubleClickAction = doubleClickAction;
  29. multiColumnHeader = new MultiColumnHeader(headerState);
  30. multiColumnHeader.canSort = true;
  31. multiColumnHeader.sortingChanged += SortingChanged;
  32. rowHeight = UnityConstants.TREEVIEW_ROW_HEIGHT;
  33. showAlternatingRowBackgrounds = false;
  34. mCooldownFilterAction = new CooldownWindowDelayer(
  35. DelayedSearchChanged, UnityConstants.SEARCH_DELAYED_INPUT_ACTION_INTERVAL);
  36. mCooldownSelectionAction = new CooldownWindowDelayer(
  37. DelayedSelectionChanged, UnityConstants.SELECTION_DELAYED_INPUT_ACTION_INTERVAL);
  38. }
  39. protected override void SelectionChanged(IList<int> selectedIds)
  40. {
  41. mCooldownSelectionAction.Ping();
  42. }
  43. public override IList<TreeViewItem> GetRows()
  44. {
  45. return mRows;
  46. }
  47. protected override TreeViewItem BuildRoot()
  48. {
  49. return new TreeViewItem(0, -1, string.Empty);
  50. }
  51. protected override IList<TreeViewItem> BuildRows(
  52. TreeViewItem rootItem)
  53. {
  54. if (mQueryResult == null)
  55. {
  56. ClearRows(rootItem, mRows);
  57. return mRows;
  58. }
  59. RegenerateRows(
  60. mListViewItemIds,
  61. mQueryResult.GetObjects(),
  62. rootItem, mRows);
  63. return mRows;
  64. }
  65. protected override void SearchChanged(string newSearch)
  66. {
  67. mCooldownFilterAction.Ping();
  68. }
  69. protected override void ContextClickedItem(int id)
  70. {
  71. mMenu.Popup();
  72. Repaint();
  73. }
  74. public override void OnGUI(Rect rect)
  75. {
  76. if (Event.current.type == EventType.Layout)
  77. {
  78. if (IsSizeChanged(treeViewRect, mLastRect))
  79. mSizeChangedAction();
  80. }
  81. mLastRect = treeViewRect;
  82. base.OnGUI(rect);
  83. }
  84. protected override void RowGUI(RowGUIArgs args)
  85. {
  86. DrawTreeViewItem.InitializeStyles();
  87. if (args.item is ChangesetListViewItem)
  88. {
  89. ChangesetListViewItem changesetListViewItem = (ChangesetListViewItem)args.item;
  90. ChangesetInfo changesetInfo = (ChangesetInfo)changesetListViewItem.ObjectInfo;
  91. ChangesetsListViewItemGUI(
  92. mQueryResult,
  93. rowHeight,
  94. changesetListViewItem,
  95. args,
  96. changesetInfo.ChangesetId == mLoadedChangesetId,
  97. Repaint);
  98. return;
  99. }
  100. base.RowGUI(args);
  101. }
  102. protected override void DoubleClickedItem(int id)
  103. {
  104. if (!HasSelection())
  105. return;
  106. mDoubleClickAction();
  107. }
  108. internal void BuildModel(
  109. ViewQueryResult queryResult,
  110. long loadedChangesetId)
  111. {
  112. mListViewItemIds.Clear();
  113. mQueryResult = queryResult;
  114. mLoadedChangesetId = loadedChangesetId;
  115. }
  116. internal void Refilter()
  117. {
  118. if (mQueryResult == null)
  119. return;
  120. Filter filter = new Filter(searchString);
  121. mQueryResult.ApplyFilter(filter, mColumnNames);
  122. }
  123. internal void Sort()
  124. {
  125. if (mQueryResult == null)
  126. return;
  127. int sortedColumnIdx = multiColumnHeader.state.sortedColumnIndex;
  128. bool sortAscending = multiColumnHeader.IsSortedAscending(sortedColumnIdx);
  129. mQueryResult.Sort(
  130. mColumnNames[sortedColumnIdx],
  131. sortAscending);
  132. }
  133. internal List<RepositorySpec> GetSelectedRepositories()
  134. {
  135. List<RepositorySpec> result = new List<RepositorySpec>();
  136. IList<int> selectedIds = GetSelection();
  137. if (selectedIds.Count == 0)
  138. return result;
  139. foreach (KeyValuePair<object, int> item
  140. in mListViewItemIds.GetInfoItems())
  141. {
  142. if (!selectedIds.Contains(item.Value))
  143. continue;
  144. RepositorySpec repSpec =
  145. mQueryResult.GetRepositorySpec(item.Key);
  146. result.Add(repSpec);
  147. }
  148. return result;
  149. }
  150. internal List<RepObjectInfo> GetSelectedRepObjectInfos()
  151. {
  152. List<RepObjectInfo> result = new List<RepObjectInfo>();
  153. IList<int> selectedIds = GetSelection();
  154. if (selectedIds.Count == 0)
  155. return result;
  156. foreach (KeyValuePair<object, int> item
  157. in mListViewItemIds.GetInfoItems())
  158. {
  159. if (!selectedIds.Contains(item.Value))
  160. continue;
  161. RepObjectInfo repObjectInfo =
  162. mQueryResult.GetRepObjectInfo(item.Key);
  163. result.Add(repObjectInfo);
  164. }
  165. return result;
  166. }
  167. internal void SelectRepObjectInfos(
  168. List<RepObjectInfo> repObjectsToSelect)
  169. {
  170. List<int> idsToSelect = new List<int>();
  171. foreach (RepObjectInfo repObjectInfo in repObjectsToSelect)
  172. {
  173. int repObjectInfoId = GetTreeIdForItem(repObjectInfo);
  174. if (repObjectInfoId == -1)
  175. continue;
  176. idsToSelect.Add(repObjectInfoId);
  177. }
  178. TableViewOperations.SetSelectionAndScroll(this, idsToSelect);
  179. }
  180. int GetTreeIdForItem(RepObjectInfo repObjectInfo)
  181. {
  182. foreach (KeyValuePair<object, int> item in mListViewItemIds.GetInfoItems())
  183. {
  184. RepObjectInfo currentRepObjectInfo =
  185. mQueryResult.GetRepObjectInfo(item.Key);
  186. if (!currentRepObjectInfo.Equals(repObjectInfo))
  187. continue;
  188. if (!currentRepObjectInfo.GUID.Equals(repObjectInfo.GUID))
  189. continue;
  190. return item.Value;
  191. }
  192. return -1;
  193. }
  194. void DelayedSearchChanged()
  195. {
  196. Refilter();
  197. Sort();
  198. Reload();
  199. TableViewOperations.ScrollToSelection(this);
  200. }
  201. void DelayedSelectionChanged()
  202. {
  203. if (!HasSelection())
  204. return;
  205. mSelectionChangedAction();
  206. }
  207. void SortingChanged(MultiColumnHeader multiColumnHeader)
  208. {
  209. Sort();
  210. Reload();
  211. }
  212. static void RegenerateRows(
  213. ListViewItemIds<object> listViewItemIds,
  214. List<object> objectInfos,
  215. TreeViewItem rootItem,
  216. List<TreeViewItem> rows)
  217. {
  218. ClearRows(rootItem, rows);
  219. if (objectInfos.Count == 0)
  220. return;
  221. foreach (object objectInfo in objectInfos)
  222. {
  223. int objectId;
  224. if (!listViewItemIds.TryGetInfoItemId(objectInfo, out objectId))
  225. objectId = listViewItemIds.AddInfoItem(objectInfo);
  226. ChangesetListViewItem changesetListViewItem =
  227. new ChangesetListViewItem(objectId, objectInfo);
  228. rootItem.AddChild(changesetListViewItem);
  229. rows.Add(changesetListViewItem);
  230. }
  231. }
  232. static void ClearRows(
  233. TreeViewItem rootItem,
  234. List<TreeViewItem> rows)
  235. {
  236. if (rootItem.hasChildren)
  237. rootItem.children.Clear();
  238. rows.Clear();
  239. }
  240. static void ChangesetsListViewItemGUI(
  241. ViewQueryResult queryResult,
  242. float rowHeight,
  243. ChangesetListViewItem item,
  244. RowGUIArgs args,
  245. bool isBoldText,
  246. Action avatarLoadedAction)
  247. {
  248. for (int visibleColumnIdx = 0; visibleColumnIdx < args.GetNumVisibleColumns(); visibleColumnIdx++)
  249. {
  250. Rect cellRect = args.GetCellRect(visibleColumnIdx);
  251. if (visibleColumnIdx == 0)
  252. {
  253. cellRect.x += UnityConstants.FIRST_COLUMN_WITHOUT_ICON_INDENT;
  254. cellRect.width -= UnityConstants.FIRST_COLUMN_WITHOUT_ICON_INDENT;
  255. }
  256. ChangesetsListColumn column =
  257. (ChangesetsListColumn)args.GetColumn(visibleColumnIdx);
  258. ChangesetsListViewItemCellGUI(
  259. cellRect,
  260. rowHeight,
  261. queryResult,
  262. item,
  263. column,
  264. avatarLoadedAction,
  265. args.selected,
  266. args.focused,
  267. isBoldText);
  268. }
  269. }
  270. static void ChangesetsListViewItemCellGUI(
  271. Rect rect,
  272. float rowHeight,
  273. ViewQueryResult queryResult,
  274. ChangesetListViewItem item,
  275. ChangesetsListColumn column,
  276. Action avatarLoadedAction,
  277. bool isSelected,
  278. bool isFocused,
  279. bool isBoldText)
  280. {
  281. string columnText = RepObjectInfoView.GetColumnText(
  282. queryResult.GetRepositorySpec(item.ObjectInfo),
  283. queryResult.GetRepObjectInfo(item.ObjectInfo),
  284. ChangesetsListHeaderState.GetColumnName(column));
  285. if (column == ChangesetsListColumn.CreatedBy)
  286. {
  287. DrawTreeViewItem.ForItemCell(
  288. rect,
  289. rowHeight,
  290. -1,
  291. GetAvatar.ForEmail(columnText, avatarLoadedAction),
  292. null,
  293. columnText,
  294. isSelected,
  295. isFocused,
  296. isBoldText,
  297. false);
  298. return;
  299. }
  300. if (column == ChangesetsListColumn.Branch ||
  301. column == ChangesetsListColumn.Repository ||
  302. column == ChangesetsListColumn.Guid)
  303. {
  304. DrawTreeViewItem.ForSecondaryLabel(
  305. rect, columnText, isSelected, isFocused, isBoldText);
  306. return;
  307. }
  308. DrawTreeViewItem.ForLabel(
  309. rect, columnText, isSelected, isFocused, isBoldText);
  310. }
  311. static bool IsSizeChanged(
  312. Rect currentRect, Rect lastRect)
  313. {
  314. if (currentRect.width != lastRect.width)
  315. return true;
  316. if (currentRect.height != lastRect.height)
  317. return true;
  318. return false;
  319. }
  320. Rect mLastRect;
  321. ListViewItemIds<object> mListViewItemIds = new ListViewItemIds<object>();
  322. List<TreeViewItem> mRows = new List<TreeViewItem>();
  323. ViewQueryResult mQueryResult;
  324. long mLoadedChangesetId;
  325. readonly CooldownWindowDelayer mCooldownFilterAction;
  326. readonly CooldownWindowDelayer mCooldownSelectionAction;
  327. readonly Action mDoubleClickAction;
  328. readonly Action mSelectionChangedAction;
  329. readonly Action mSizeChangedAction;
  330. readonly ChangesetsViewMenu mMenu;
  331. readonly List<string> mColumnNames;
  332. }
  333. }