PdnMainMenu.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. using PaintDotNet.SystemLayer;
  2. using System;
  3. using System.Linq;
  4. using System.Windows.Forms;
  5. namespace PaintDotNet.Menus
  6. {
  7. /// <summary>
  8. /// 主菜单容器
  9. /// 包含所有菜单
  10. /// </summary>
  11. internal sealed class PdnMainMenu : MenuStripEx
  12. {
  13. private FileMenu fileMenu;
  14. private EditMenu editMenu;
  15. private HardwareControlMenu hardwareControlMenu;
  16. public ImageCollectionMenu imageCollectionMenu;
  17. private ImageMenu imageMenu;
  18. public LabelActionMenu labelActionMenu;
  19. public MeasureActionMenu measureActionMenu;
  20. private ViewSettingMenu viewSettingMenu;
  21. private BinaryActionMenu binaryActionMenu;
  22. private GeneralAnalysisMenu generalAnalysisMenu;
  23. private AutoAnalysisMenu autoAnalysisMenu;
  24. private DedicatedAnalysisMenu dedicatedAnalysisMenu;
  25. private ToolsMenu toolsMenu;
  26. private SettingMenu settingMenu;
  27. private HelpMenu helpMenu;
  28. private AppWorkspace appWorkspace;
  29. private string[] menuIdArr;
  30. public AppWorkspace AppWorkspace
  31. {
  32. get
  33. {
  34. return this.appWorkspace;
  35. }
  36. set
  37. {
  38. this.appWorkspace = value;
  39. this.fileMenu.AppWorkspace = value;
  40. this.editMenu.AppWorkspace = value;
  41. this.hardwareControlMenu.AppWorkspace = value;
  42. this.imageCollectionMenu.AppWorkspace = value;
  43. this.imageMenu.AppWorkspace = value;
  44. this.labelActionMenu.AppWorkspace = value;
  45. this.measureActionMenu.AppWorkspace = value;
  46. this.viewSettingMenu.AppWorkspace = value;
  47. this.binaryActionMenu.AppWorkspace = value;
  48. this.generalAnalysisMenu.AppWorkspace = value;
  49. this.autoAnalysisMenu.AppWorkspace = value;
  50. this.dedicatedAnalysisMenu.AppWorkspace = value;
  51. this.toolsMenu.AppWorkspace = value;
  52. this.settingMenu.AppWorkspace = value;
  53. this.helpMenu.AppWorkspace = value;
  54. }
  55. }
  56. public PdnMainMenu()
  57. {
  58. InitializeComponent();
  59. //模块管理,暂时先注释掉
  60. InitializeModule();
  61. }
  62. private void InitializeComponent()
  63. {
  64. this.fileMenu = new FileMenu(100);
  65. this.editMenu = new EditMenu(200);
  66. this.hardwareControlMenu = new HardwareControlMenu(300);
  67. this.imageCollectionMenu = new ImageCollectionMenu(400);
  68. this.imageMenu = new ImageMenu(500);
  69. this.labelActionMenu = new LabelActionMenu(600);
  70. this.measureActionMenu = new MeasureActionMenu(700);
  71. this.viewSettingMenu = new ViewSettingMenu(800);
  72. this.binaryActionMenu = new BinaryActionMenu(900);
  73. this.generalAnalysisMenu = new GeneralAnalysisMenu(1000);
  74. this.dedicatedAnalysisMenu = new DedicatedAnalysisMenu(1100);
  75. this.toolsMenu = new ToolsMenu(1200);
  76. this.settingMenu = new SettingMenu(1300);
  77. this.helpMenu = new HelpMenu(1400);
  78. this.autoAnalysisMenu = new AutoAnalysisMenu(1500);
  79. SuspendLayout();
  80. //
  81. // PdnMainMenu
  82. //
  83. this.Name = "PdnMainMenu";
  84. this.LayoutStyle = ToolStripLayoutStyle.HorizontalStackWithOverflow;
  85. this.Items.AddRange(
  86. new ToolStripItem[]
  87. {
  88. this.fileMenu,
  89. this.editMenu,
  90. this.hardwareControlMenu,
  91. this.imageCollectionMenu,
  92. this.imageMenu,
  93. this.labelActionMenu,
  94. this.measureActionMenu,
  95. this.viewSettingMenu,
  96. this.binaryActionMenu,
  97. this.generalAnalysisMenu,
  98. this.autoAnalysisMenu,
  99. this.dedicatedAnalysisMenu,
  100. this.toolsMenu,
  101. this.settingMenu,
  102. this.helpMenu
  103. });
  104. ResumeLayout();
  105. }
  106. /// <summary>
  107. /// 模块管理
  108. /// 需要先从加密锁过滤一遍
  109. /// 然后再模块管理的配置过滤一遍
  110. /// </summary>
  111. private void InitializeModule()
  112. {
  113. /*if (Startup.instance.moduleConfigModel != null)
  114. {
  115. for (int i = 0; i < this.Items.Count; i++)
  116. {
  117. this.Items[i].Visible = false;
  118. if (Startup.instance.moduleConfigModel.items.Find(a => a.ParentId == ((PdnMenuItem)this.Items[i]).MenuId) != null)
  119. {
  120. this.Items[i].Visible = true;
  121. }
  122. }
  123. }*/
  124. //以下为新的模块管理代码
  125. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\ModuleConfig.txt";
  126. if (System.IO.File.Exists(filePath))
  127. {
  128. string str = System.IO.File.ReadAllText(filePath);
  129. if (str.IndexOf(',') != -1)
  130. {
  131. menuIdArr = str.Split(',');
  132. }
  133. else
  134. {
  135. if (!string.IsNullOrEmpty(str))
  136. {
  137. menuIdArr = new string[] { str };
  138. }
  139. }
  140. if (menuIdArr != null && menuIdArr.Count() > 0)
  141. {
  142. RecursionMenuId(this.Items, 0);
  143. }
  144. else
  145. {
  146. ////模块管理永远显示(已取消的业务注释)
  147. //for (int i = 0; i < this.Items.Count; i++)
  148. //{
  149. // this.Items[i].Visible = false;
  150. // if (this.Items[i].Name == "Menu.Setting")
  151. // {
  152. // this.Items[i].Visible = true;
  153. // if (((PdnMenuItem)this.Items[i]).DropDownItems.Count > 0)
  154. // {
  155. // ToolStripItemCollection collection = ((PdnMenuItem)this.Items[i]).DropDownItems;
  156. // for (int j = 0; j < collection.Count; j++)
  157. // {
  158. // collection[j].Visible = false;
  159. // if (collection[j].Name == "ModuleSetting")
  160. // {
  161. // //collection[j].Visible = true;
  162. // }
  163. // }
  164. // }
  165. // }
  166. //}
  167. }
  168. }
  169. }
  170. /// <summary>
  171. ///
  172. /// </summary>
  173. /// <param name="toolStripItemCollection"></param>
  174. /// <param name="parentLevel"></param>
  175. /// <returns>返回父菜单是否显示</returns>
  176. private bool RecursionMenuId(ToolStripItemCollection toolStripItemCollection, int parentLevel)
  177. {
  178. bool showParentMenu = false;
  179. if (toolStripItemCollection != null && toolStripItemCollection.Count > 0)
  180. {
  181. bool toShowSeparator = false;
  182. if (parentLevel > 1)
  183. toShowSeparator = true;
  184. for (int i = 0; i < toolStripItemCollection.Count; i++)
  185. {
  186. if (toolStripItemCollection[i] is PdnMenuItem)
  187. {
  188. bool showToolStripItemI = false;
  189. //toolStripItemCollection[i].Visible = false;
  190. if (/* (toolStripItemCollection[i].Name.Equals("ModuleSetting") || toolStripItemCollection[i].Name.Equals("Menu.Setting")) || 模块管理永远显示(已取消的业务注释) */
  191. Array.IndexOf(menuIdArr, ((PdnMenuItem)toolStripItemCollection[i]).MenuId.ToString()) != -1 && Startup.getMenuIdVisible(((PdnMenuItem)toolStripItemCollection[i]).MenuId))
  192. {
  193. showToolStripItemI = true;
  194. ////toolStripItemCollection[i].Visible = true;
  195. //if (parentLevel == 1)
  196. // toShowSeparator = true;
  197. }
  198. //控制最后一条分割线不显示
  199. else if (parentLevel == 1 && i == toolStripItemCollection.Count - 1)
  200. {
  201. for (int last_i = toolStripItemCollection.Count - 2; last_i > 0; last_i--)
  202. {
  203. if (toolStripItemCollection[last_i]is PdnMenuItem)
  204. {
  205. if (Array.IndexOf(menuIdArr, ((PdnMenuItem)toolStripItemCollection[last_i]).MenuId.ToString()) != -1)
  206. break;
  207. }
  208. else
  209. toolStripItemCollection[last_i].Visible = false;
  210. }
  211. }
  212. ////模块管理永远显示(已取消的业务注释)
  213. //if (toolStripItemCollection[i].Name.Equals("ModuleSetting") || toolStripItemCollection[i].Name.Equals("Menu.Setting"))
  214. //{
  215. // //toolStripItemCollection[i].Visible = true;
  216. // showParentMenu = true;
  217. //}
  218. //控制所有子菜单都没有授权的父菜单也不显示
  219. if (showToolStripItemI && (RecursionMenuId(((PdnMenuItem)toolStripItemCollection[i]).DropDownItems, parentLevel + 1) || toolStripItemCollection[i].Name.Equals("OpenRecent")))
  220. {
  221. if (!toolStripItemCollection[i].Name.Equals("NsetExtraction"))
  222. toolStripItemCollection[i].Visible = true;
  223. toShowSeparator = true;
  224. showParentMenu = true;
  225. }
  226. else
  227. toolStripItemCollection[i].Visible = false;
  228. }
  229. else if (parentLevel == 1 && toShowSeparator)
  230. toShowSeparator = false;
  231. else if (parentLevel == 1 && !toShowSeparator)
  232. toolStripItemCollection[i].Visible = false;
  233. }
  234. }
  235. else
  236. showParentMenu = true;
  237. return showParentMenu;
  238. }
  239. }
  240. }