暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

TableViewOperations.cs 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System.Collections.Generic;
  2. using UnityEditor.IMGUI.Controls;
  3. namespace Unity.PlasticSCM.Editor.UI.Tree
  4. {
  5. internal static class TableViewOperations
  6. {
  7. internal static int GetFirstSelectedRow(
  8. TreeView treeView)
  9. {
  10. IList<int> selectedIds = treeView.GetSelection();
  11. if (selectedIds.Count == 0)
  12. return -1;
  13. return selectedIds[0];
  14. }
  15. internal static void SelectFirstRow(
  16. TreeView treeView)
  17. {
  18. int rowCount = treeView.GetRows().Count;
  19. if (rowCount == 0)
  20. return;
  21. SetSelectionAndScroll(
  22. treeView, new List<int> { 1 });
  23. }
  24. internal static void SelectDefaultRow(
  25. TreeView treeView, int defaultRow)
  26. {
  27. int rowCount = treeView.GetRows().Count;
  28. if (defaultRow == -1 || rowCount == 0)
  29. return;
  30. if (defaultRow >= rowCount)
  31. defaultRow = rowCount - 1;
  32. SetSelectionAndScroll(
  33. treeView, new List<int> { defaultRow });
  34. }
  35. internal static void SetSelectionAndScroll(
  36. TreeView treeView, List<int> idsToSelect)
  37. {
  38. treeView.SetSelection(
  39. idsToSelect,
  40. TreeViewSelectionOptions.FireSelectionChanged |
  41. TreeViewSelectionOptions.RevealAndFrame);
  42. }
  43. internal static void ScrollToSelection(
  44. TreeView treeView)
  45. {
  46. if (!treeView.HasSelection())
  47. return;
  48. int itemId = treeView.GetSelection()[0];
  49. if (!IsVisible(itemId, treeView))
  50. return;
  51. treeView.FrameItem(itemId);
  52. }
  53. static bool IsVisible(int id, TreeView treeView)
  54. {
  55. foreach (TreeViewItem item in treeView.GetRows())
  56. {
  57. if (item.id == id)
  58. return true;
  59. }
  60. return false;
  61. }
  62. }
  63. }