Пример #1
0
        public VSDevExpressMenu(DTE dte, string menuName = DevExpressMenuName, VSDevExpressMenuLocation location = VSDevExpressMenuLocation.MenuBar, bool directItem = false)
        {
            Header = menuName;
            var            commandBars = dte.CommandBars as CommandBars;
            CommandBar     mainMenuBar = commandBars[MenusCache[location]];
            MsoControlType controlType = GetControlType(directItem);

            if (controlType == MsoControlType.msoControlPopup)
            {
                CommandBarPopup devExpressMenu = null;
                foreach (CommandBarControl commandBarControl in mainMenuBar.Controls)
                {
                    if (commandBarControl.Type == MsoControlType.msoControlPopup)
                    {
                        var commandBarPopup = (CommandBarPopup)commandBarControl;
                        if (commandBarPopup.CommandBar.Name == menuName)
                        {
                            devExpressMenu = commandBarPopup;
                            break;
                        }
                    }
                }
                if (devExpressMenu == null)
                {
                    devExpressMenu = mainMenuBar.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, Type.Missing, Type.Missing) as CommandBarPopup;
                }
                VsSource = devExpressMenu;
                CreateChildrenFromSource();
            }
            else if (controlType == MsoControlType.msoControlButton)
            {
                foreach (CommandBarControl commandBarControl in mainMenuBar.Controls)
                {
                    if (commandBarControl.Type == MsoControlType.msoControlButton)
                    {
                        CommandBarButton button = (CommandBarButton)commandBarControl;
                        if (button.Caption == menuName)
                        {
                            throw new ArgumentException("button already registerer");
                        }
                    }
                }
                var msoButton = mainMenuBar.Controls.Add(MsoControlType.msoControlButton, Type.Missing, Type.Missing, Type.Missing, Type.Missing) as CommandBarButton;
                msoButton.Caption = menuName;
                VsSource          = msoButton;
            }
        }
Пример #2
0
 public VSDevExpressMenu(DTE dte, string menuName = DevExpressMenuName, VSDevExpressMenuLocation location = VSDevExpressMenuLocation.MenuBar, bool directItem = false)
 {
     Header = menuName;
     var commandBars = dte.CommandBars as CommandBars;
     CommandBar mainMenuBar = commandBars[MenusCache[location]];
     MsoControlType controlType = GetControlType(directItem);
     if (controlType == MsoControlType.msoControlPopup) {
         CommandBarPopup devExpressMenu = null;
         foreach (CommandBarControl commandBarControl in mainMenuBar.Controls) {
             if (commandBarControl.Type == MsoControlType.msoControlPopup) {
                 var commandBarPopup = (CommandBarPopup)commandBarControl;
                 if (commandBarPopup.CommandBar.Name == menuName) {
                     devExpressMenu = commandBarPopup;
                     break;
                 }
             }
         }
         if (devExpressMenu == null)
             devExpressMenu = mainMenuBar.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, Type.Missing, Type.Missing) as CommandBarPopup;
         VsSource = devExpressMenu;
         CreateChildrenFromSource();
     }
     else if (controlType == MsoControlType.msoControlButton) {
         foreach (CommandBarControl commandBarControl in mainMenuBar.Controls) {
             if (commandBarControl.Type == MsoControlType.msoControlButton) {
                 CommandBarButton button = (CommandBarButton)commandBarControl;
                 if (button.Caption == menuName)
                     throw new ArgumentException("button already registerer");
             }
         }
         var msoButton = mainMenuBar.Controls.Add(MsoControlType.msoControlButton, Type.Missing, Type.Missing, Type.Missing, Type.Missing) as CommandBarButton;
         msoButton.Caption = menuName;
         VsSource = msoButton;
     }
 }