RevitMenuComponment.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:RevitMenuComponment
  3. * 作者:xulisong
  4. * 创建时间: 2019/3/7 15:38:41
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Collections.ObjectModel;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace FWindSoft.Revit.Menu
  14. {
  15. public class RevitMenuComponment
  16. {
  17. public MenuConfig Config { get; internal set; }
  18. /// <summary>
  19. /// 名称
  20. /// </summary>
  21. public string Name { get; set; }
  22. /// <summary>
  23. /// 显示
  24. /// </summary>
  25. public string Text { get; set; }
  26. }
  27. /// <summary>
  28. /// 节点集合
  29. /// </summary>
  30. public class RevitComponmentCollection<T> : Collection<T> where T: RevitMenuComponment
  31. {
  32. private MenuConfig m_Config;
  33. internal RevitComponmentCollection(MenuConfig config)
  34. {
  35. m_Config = config;
  36. }
  37. protected override void ClearItems()
  38. {
  39. foreach (var item in this)
  40. {
  41. if (item != null)
  42. {
  43. item.Config = null;
  44. }
  45. }
  46. base.ClearItems();
  47. }
  48. protected override void InsertItem(int index, T item)
  49. {
  50. base.InsertItem(index, item);
  51. item.Config = m_Config ;
  52. }
  53. protected override void RemoveItem(int index)
  54. {
  55. if (this[index] != null)
  56. {
  57. this[index].Config = null;
  58. }
  59. base.RemoveItem(index);
  60. }
  61. protected override void SetItem(int index, T item)
  62. {
  63. base.SetItem(index, item);
  64. item.Config = m_Config;
  65. }
  66. public void AddRange(IEnumerable<T> items)
  67. {
  68. foreach (var item in items)
  69. {
  70. this.Add(item);
  71. }
  72. }
  73. }
  74. }