TreeViewItemIds.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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<I, int>> GetInfoItems()
  17. {
  18. return mCacheByInfo.ToList();
  19. }
  20. internal bool TryGetCategoryItemId(C category, out int itemId)
  21. {
  22. return mCacheByCategories.TryGetValue(category, out itemId);
  23. }
  24. internal bool TryGetInfoItemId(I info, out int itemId)
  25. {
  26. return mCacheByInfo.TryGetValue(info, out itemId);
  27. }
  28. internal int AddCategoryItem(C category)
  29. {
  30. int itemId = GetNextItemId();
  31. mCacheByCategories.Add(category, itemId);
  32. return itemId;
  33. }
  34. internal int AddInfoItem(I info)
  35. {
  36. int itemId = GetNextItemId();
  37. mCacheByInfo.Add(info, itemId);
  38. return itemId;
  39. }
  40. int GetNextItemId()
  41. {
  42. return mCacheByCategories.Count
  43. + mCacheByInfo.Count
  44. + 1;
  45. }
  46. Dictionary<C, int> mCacheByCategories = new Dictionary<C, int>();
  47. Dictionary<I, int> mCacheByInfo = new Dictionary<I, int>();
  48. }
  49. }