No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TreeViewItemIds.cs 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. namespace Unity.PlasticSCM.Editor.UI.Tree
  4. {
  5. internal class TreeViewItemIds<C, I>
  6. {
  7. internal void Clear()
  8. {
  9. mCacheByCategories.Clear();
  10. mCacheByInfo.Clear();
  11. }
  12. internal List<int> GetCategoryIds()
  13. {
  14. return new List<int>(mCacheByCategories.Values);
  15. }
  16. internal List<KeyValuePair<C, int>> GetCategoryItems()
  17. {
  18. return mCacheByCategories.ToList();
  19. }
  20. internal List<KeyValuePair<I, int>> GetInfoItems()
  21. {
  22. return mCacheByInfo.ToList();
  23. }
  24. internal bool TryGetCategoryItemId(C category, out int itemId)
  25. {
  26. return mCacheByCategories.TryGetValue(category, out itemId);
  27. }
  28. internal bool TryGetInfoItemId(I info, out int itemId)
  29. {
  30. return mCacheByInfo.TryGetValue(info, out itemId);
  31. }
  32. internal int AddCategoryItem(C category)
  33. {
  34. int itemId = GetNextItemId();
  35. mCacheByCategories.Add(category, itemId);
  36. return itemId;
  37. }
  38. internal int AddInfoItem(I info)
  39. {
  40. int itemId = GetNextItemId();
  41. mCacheByInfo.Add(info, itemId);
  42. return itemId;
  43. }
  44. int GetNextItemId()
  45. {
  46. return mCacheByCategories.Count
  47. + mCacheByInfo.Count
  48. + 1;
  49. }
  50. Dictionary<C, int> mCacheByCategories = new Dictionary<C, int>();
  51. Dictionary<I, int> mCacheByInfo = new Dictionary<I, int>();
  52. }
  53. }