MenuInfo.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. using GeekDesk.Constant;
  2. using GeekDesk.Util;
  3. using System;
  4. using System.Collections.ObjectModel;
  5. using System.ComponentModel;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Windows;
  9. namespace GeekDesk.ViewModel
  10. {
  11. [Serializable]
  12. public class MenuInfo : INotifyPropertyChanged
  13. {
  14. private string menuName;
  15. private string menuId;
  16. private MenuTypeEnum menuType = MenuTypeEnum.NORMAL;
  17. private string relationPath;
  18. private Visibility menuEdit = Visibility.Collapsed;
  19. private Visibility notMenuEdit = Visibility.Visible;
  20. private string menuGeometry; //菜单几何图标
  21. private string geometryColor; //几何图标颜色
  22. private ObservableCollection<IconInfo> iconList = new ObservableCollection<IconInfo>();
  23. private bool isEncrypt; //是否加密
  24. public string RelationPath
  25. {
  26. get => relationPath;
  27. set
  28. {
  29. relationPath = value;
  30. OnPropertyChanged("RelationPath");
  31. }
  32. }
  33. public MenuTypeEnum MenuType
  34. {
  35. get => menuType;
  36. set
  37. {
  38. menuType = value;
  39. OnPropertyChanged("MenuType");
  40. }
  41. }
  42. public bool IsEncrypt
  43. {
  44. get
  45. {
  46. return isEncrypt;
  47. }
  48. set
  49. {
  50. isEncrypt = value;
  51. OnPropertyChanged("IsEncrypt");
  52. }
  53. }
  54. public string MenuGeometry
  55. {
  56. get
  57. {
  58. if (menuGeometry == null)
  59. {
  60. return Constants.DEFAULT_MENU_GEOMETRY;
  61. }
  62. return menuGeometry;
  63. }
  64. set
  65. {
  66. menuGeometry = value;
  67. OnPropertyChanged("MenuGeometry");
  68. }
  69. }
  70. public string GeometryColor
  71. {
  72. get
  73. {
  74. if (geometryColor == null)
  75. {
  76. return Constants.DEFAULT_MENU_GEOMETRY_COLOR;
  77. }
  78. return geometryColor;
  79. }
  80. set
  81. {
  82. geometryColor = value;
  83. OnPropertyChanged("GeometryColor");
  84. }
  85. }
  86. public string MenuName
  87. {
  88. get
  89. {
  90. return menuName;
  91. }
  92. set
  93. {
  94. menuName = value;
  95. OnPropertyChanged("MenuName");
  96. }
  97. }
  98. public string MenuId
  99. {
  100. get
  101. {
  102. return menuId;
  103. }
  104. set
  105. {
  106. menuId = value;
  107. OnPropertyChanged("MenuId");
  108. }
  109. }
  110. public Visibility MenuEdit
  111. {
  112. get
  113. {
  114. return menuEdit;
  115. }
  116. set
  117. {
  118. menuEdit = value;
  119. if (menuEdit == Visibility.Visible)
  120. {
  121. NotMenuEdit = Visibility.Collapsed;
  122. }
  123. else
  124. {
  125. NotMenuEdit = Visibility.Visible;
  126. }
  127. OnPropertyChanged("MenuEdit");
  128. }
  129. }
  130. public Visibility NotMenuEdit
  131. {
  132. get
  133. {
  134. return notMenuEdit;
  135. }
  136. set
  137. {
  138. notMenuEdit = value;
  139. OnPropertyChanged("NotMenuEdit");
  140. }
  141. }
  142. public ObservableCollection<IconInfo> IconList
  143. {
  144. get
  145. {
  146. //如果是关联文件夹类型,实时读取
  147. if (menuType == MenuTypeEnum.RELATION_FOLDER)
  148. {
  149. DirectoryInfo dir = new DirectoryInfo(RelationPath);
  150. if (dir.Exists)
  151. {
  152. ObservableCollection<IconInfo> relationIconInfo = new ObservableCollection<IconInfo>();
  153. var folders = dir.GetDirectories();
  154. foreach (var directoryInfo in folders)
  155. {
  156. relationIconInfo.Add(CommonCode.GetIconInfoByPath(directoryInfo.FullName));
  157. }
  158. var files = dir.EnumerateFiles().Where(f => MainWindow.appData.AppConfig.FilterExt.Contains(f.Extension.Replace(".", "")));
  159. foreach (var fileInfo in files)
  160. {
  161. relationIconInfo.Add(CommonCode.GetIconInfoByPath(fileInfo.FullName));
  162. }
  163. return relationIconInfo;
  164. }
  165. }
  166. return iconList;
  167. }
  168. set
  169. {
  170. iconList = value;
  171. OnPropertyChanged("IconList");
  172. }
  173. }
  174. [field: NonSerializedAttribute()]
  175. public event PropertyChangedEventHandler PropertyChanged;
  176. private void OnPropertyChanged(string propertyName)
  177. {
  178. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  179. CommonCode.SaveAppData(MainWindow.appData, Constants.DATA_FILE_PATH);
  180. }
  181. }
  182. }