PathsToRemoveDropDownMenu.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using UnityEngine;
  2. using UnityEditorInternal;
  3. using System.Collections.Generic;
  4. namespace UnityEditor.TestTools.CodeCoverage
  5. {
  6. internal class PathsToRemoveDropDownMenu
  7. {
  8. GenericMenu m_Menu;
  9. ReorderableList m_ReorderableList;
  10. List<string> m_List;
  11. CodeCoverageWindow m_Parent;
  12. PathFilterType m_PathFilterType;
  13. class Styles
  14. {
  15. public static readonly GUIContent RemoveSelectedLabel = EditorGUIUtility.TrTextContent("Remove Selected");
  16. public static readonly GUIContent RemoveAllLabel = EditorGUIUtility.TrTextContent("Remove All");
  17. }
  18. public PathsToRemoveDropDownMenu(CodeCoverageWindow parent, PathFilterType type)
  19. {
  20. m_Parent = parent;
  21. m_PathFilterType = type;
  22. }
  23. private void PopulateMenu()
  24. {
  25. m_Menu = new GenericMenu();
  26. if (m_ReorderableList.index >= 0 && m_ReorderableList.index < m_List.Count && m_ReorderableList.HasKeyboardControl())
  27. m_Menu.AddItem(Styles.RemoveSelectedLabel, false, () => RemoveSelected());
  28. else
  29. m_Menu.AddDisabledItem(Styles.RemoveSelectedLabel);
  30. m_Menu.AddItem(Styles.RemoveAllLabel, false, () => RemoveAll());
  31. }
  32. public void Show(Rect position, ReorderableList reorderableList, List<string> list)
  33. {
  34. m_ReorderableList = reorderableList;
  35. m_List = list;
  36. PopulateMenu();
  37. m_Menu.DropDown(position);
  38. }
  39. private void RemoveSelected()
  40. {
  41. m_List.RemoveAt(m_ReorderableList.index);
  42. UpdatePathToFilter();
  43. }
  44. private void RemoveAll()
  45. {
  46. m_List.Clear();
  47. UpdatePathToFilter();
  48. }
  49. private void UpdatePathToFilter()
  50. {
  51. if (m_PathFilterType == PathFilterType.Include)
  52. {
  53. m_Parent.PathsToInclude = string.Join(",", m_List);
  54. }
  55. else
  56. {
  57. m_Parent.PathsToExclude = string.Join(",", m_List);
  58. }
  59. m_Parent.LoseFocus();
  60. }
  61. }
  62. }