123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- using PaintDotNet.SystemLayer;
- using System;
- using System.Linq;
- using System.Windows.Forms;
- namespace PaintDotNet.Menus
- {
- /// <summary>
- /// 主菜单容器
- /// 包含所有菜单
- /// </summary>
- internal sealed class PdnMainMenu : MenuStripEx
- {
- private FileMenu fileMenu;
- private EditMenu editMenu;
- private HardwareControlMenu hardwareControlMenu;
- public ImageCollectionMenu imageCollectionMenu;
- private ImageMenu imageMenu;
- public LabelActionMenu labelActionMenu;
- public MeasureActionMenu measureActionMenu;
- private ViewSettingMenu viewSettingMenu;
- private BinaryActionMenu binaryActionMenu;
- private GeneralAnalysisMenu generalAnalysisMenu;
- private AutoAnalysisMenu autoAnalysisMenu;
- private DedicatedAnalysisMenu dedicatedAnalysisMenu;
- private ToolsMenu toolsMenu;
- private SettingMenu settingMenu;
- private HelpMenu helpMenu;
- private AppWorkspace appWorkspace;
- private string[] menuIdArr;
- public AppWorkspace AppWorkspace
- {
- get
- {
- return this.appWorkspace;
- }
- set
- {
- this.appWorkspace = value;
- this.fileMenu.AppWorkspace = value;
- this.editMenu.AppWorkspace = value;
- this.hardwareControlMenu.AppWorkspace = value;
- this.imageCollectionMenu.AppWorkspace = value;
- this.imageMenu.AppWorkspace = value;
- this.labelActionMenu.AppWorkspace = value;
- this.measureActionMenu.AppWorkspace = value;
- this.viewSettingMenu.AppWorkspace = value;
- this.binaryActionMenu.AppWorkspace = value;
- this.generalAnalysisMenu.AppWorkspace = value;
- this.autoAnalysisMenu.AppWorkspace = value;
- this.dedicatedAnalysisMenu.AppWorkspace = value;
- this.toolsMenu.AppWorkspace = value;
- this.settingMenu.AppWorkspace = value;
- this.helpMenu.AppWorkspace = value;
- }
- }
- public PdnMainMenu()
- {
- InitializeComponent();
- //模块管理,暂时先注释掉
- InitializeModule();
- }
- private void InitializeComponent()
- {
- this.fileMenu = new FileMenu(100);
- this.editMenu = new EditMenu(200);
- this.hardwareControlMenu = new HardwareControlMenu(300);
- this.imageCollectionMenu = new ImageCollectionMenu(400);
- this.imageMenu = new ImageMenu(500);
- this.labelActionMenu = new LabelActionMenu(600);
- this.measureActionMenu = new MeasureActionMenu(700);
- this.viewSettingMenu = new ViewSettingMenu(800);
- this.binaryActionMenu = new BinaryActionMenu(900);
- this.generalAnalysisMenu = new GeneralAnalysisMenu(1000);
- this.dedicatedAnalysisMenu = new DedicatedAnalysisMenu(1100);
- this.toolsMenu = new ToolsMenu(1200);
- this.settingMenu = new SettingMenu(1300);
- this.helpMenu = new HelpMenu(1400);
- this.autoAnalysisMenu = new AutoAnalysisMenu(1500);
- SuspendLayout();
- //
- // PdnMainMenu
- //
- this.Name = "PdnMainMenu";
- this.LayoutStyle = ToolStripLayoutStyle.HorizontalStackWithOverflow;
- this.Items.AddRange(
- new ToolStripItem[]
- {
- this.fileMenu,
- this.editMenu,
- this.hardwareControlMenu,
- this.imageCollectionMenu,
- this.imageMenu,
- this.labelActionMenu,
- this.measureActionMenu,
- this.viewSettingMenu,
- this.binaryActionMenu,
- this.generalAnalysisMenu,
- this.autoAnalysisMenu,
- this.dedicatedAnalysisMenu,
- this.toolsMenu,
- this.settingMenu,
- this.helpMenu
- });
- ResumeLayout();
- }
- /// <summary>
- /// 模块管理
- /// 需要先从加密锁过滤一遍
- /// 然后再模块管理的配置过滤一遍
- /// </summary>
- private void InitializeModule()
- {
- /*if (Startup.instance.moduleConfigModel != null)
- {
- for (int i = 0; i < this.Items.Count; i++)
- {
- this.Items[i].Visible = false;
- if (Startup.instance.moduleConfigModel.items.Find(a => a.ParentId == ((PdnMenuItem)this.Items[i]).MenuId) != null)
- {
- this.Items[i].Visible = true;
- }
- }
- }*/
- //以下为新的模块管理代码
- string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\ModuleConfig.txt";
- if (System.IO.File.Exists(filePath))
- {
- string str = System.IO.File.ReadAllText(filePath);
- if (str.IndexOf(',') != -1)
- {
- menuIdArr = str.Split(',');
- }
- else
- {
- if (!string.IsNullOrEmpty(str))
- {
- menuIdArr = new string[] { str };
- }
- }
- if (menuIdArr != null && menuIdArr.Count() > 0)
- {
- RecursionMenuId(this.Items, 0);
- }
- else
- {
- ////模块管理永远显示(已取消的业务注释)
- //for (int i = 0; i < this.Items.Count; i++)
- //{
- // this.Items[i].Visible = false;
- // if (this.Items[i].Name == "Menu.Setting")
- // {
- // this.Items[i].Visible = true;
- // if (((PdnMenuItem)this.Items[i]).DropDownItems.Count > 0)
- // {
- // ToolStripItemCollection collection = ((PdnMenuItem)this.Items[i]).DropDownItems;
- // for (int j = 0; j < collection.Count; j++)
- // {
- // collection[j].Visible = false;
- // if (collection[j].Name == "ModuleSetting")
- // {
- // //collection[j].Visible = true;
- // }
- // }
- // }
- // }
- //}
- }
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="toolStripItemCollection"></param>
- /// <param name="parentLevel"></param>
- /// <returns>返回父菜单是否显示</returns>
- private bool RecursionMenuId(ToolStripItemCollection toolStripItemCollection, int parentLevel)
- {
- bool showParentMenu = false;
- if (toolStripItemCollection != null && toolStripItemCollection.Count > 0)
- {
- bool toShowSeparator = false;
- if (parentLevel > 1)
- toShowSeparator = true;
- for (int i = 0; i < toolStripItemCollection.Count; i++)
- {
- if (toolStripItemCollection[i] is PdnMenuItem)
- {
- bool showToolStripItemI = false;
- //toolStripItemCollection[i].Visible = false;
- if (/* (toolStripItemCollection[i].Name.Equals("ModuleSetting") || toolStripItemCollection[i].Name.Equals("Menu.Setting")) || 模块管理永远显示(已取消的业务注释) */
- Array.IndexOf(menuIdArr, ((PdnMenuItem)toolStripItemCollection[i]).MenuId.ToString()) != -1 && Startup.getMenuIdVisible(((PdnMenuItem)toolStripItemCollection[i]).MenuId))
- {
- showToolStripItemI = true;
- ////toolStripItemCollection[i].Visible = true;
- //if (parentLevel == 1)
- // toShowSeparator = true;
- }
- //控制最后一条分割线不显示
- else if (parentLevel == 1 && i == toolStripItemCollection.Count - 1)
- {
- for (int last_i = toolStripItemCollection.Count - 2; last_i > 0; last_i--)
- {
- if (toolStripItemCollection[last_i]is PdnMenuItem)
- {
- if (Array.IndexOf(menuIdArr, ((PdnMenuItem)toolStripItemCollection[last_i]).MenuId.ToString()) != -1)
- break;
- }
- else
- toolStripItemCollection[last_i].Visible = false;
- }
- }
- ////模块管理永远显示(已取消的业务注释)
- //if (toolStripItemCollection[i].Name.Equals("ModuleSetting") || toolStripItemCollection[i].Name.Equals("Menu.Setting"))
- //{
- // //toolStripItemCollection[i].Visible = true;
- // showParentMenu = true;
- //}
- //控制所有子菜单都没有授权的父菜单也不显示
- if (showToolStripItemI && (RecursionMenuId(((PdnMenuItem)toolStripItemCollection[i]).DropDownItems, parentLevel + 1) || toolStripItemCollection[i].Name.Equals("OpenRecent")))
- {
- if (!toolStripItemCollection[i].Name.Equals("NsetExtraction"))
- toolStripItemCollection[i].Visible = true;
- toShowSeparator = true;
- showParentMenu = true;
- }
- else
- toolStripItemCollection[i].Visible = false;
- }
- else if (parentLevel == 1 && toShowSeparator)
- toShowSeparator = false;
- else if (parentLevel == 1 && !toShowSeparator)
- toolStripItemCollection[i].Visible = false;
- }
- }
- else
- showParentMenu = true;
- return showParentMenu;
- }
- }
- }
|