Exemple #1
0
        /// <summary>
        /// 添加菜单项所要执行的宏
        /// </summary>
        /// <param name="source">CUI文件</param>
        /// <param name="name">宏的显示名称</param>
        /// <param name="command">宏的具体命令</param>
        /// <param name="tag">宏的标识符</param>
        /// <param name="helpString">宏的状态栏提示信息</param>
        /// <param name="imagePath">宏的图标</param>
        /// <returns>返回创建的宏</returns>
        public static MenuMacro AddMacro(this CustomizationSection source, string name, string command, string tag, string helpString, string imagePath)
        {
            MenuGroup menuGroup = source.MenuGroup;//获取CUI文件中的菜单组
            //判断菜单组中是否已经定义与菜单组名相同的宏集合
            MacroGroup mg = menuGroup.FindMacroGroup(menuGroup.Name);

            if (mg == null)//如果宏集合没有定义,则创建一个与菜单组名相同的宏集合
            {
                mg = new MacroGroup(menuGroup.Name, menuGroup);
            }
            //如果已经宏已经被定义,则返回
            foreach (MenuMacro macro in mg.MenuMacros)
            {
                if (macro.ElementID == tag)
                {
                    return(null);
                }
            }
            //在宏集合中创建一个命令宏
            MenuMacro MenuMacro = new MenuMacro(mg, name, command, tag);

            //指定命令宏的说明信息,在状态栏中显示
            MenuMacro.macro.HelpString = helpString;
            //指定命令宏的大小图像的路径
            MenuMacro.macro.LargeImage = MenuMacro.macro.SmallImage = imagePath;
            return(MenuMacro);//返回命令宏
        }