AsposeVisualStudioPluginCells.Connect.AddPermanentUI C# (CSharp) Method

AddPermanentUI() private method

private AddPermanentUI ( ) : void
return void
        private void AddPermanentUI()
        {
            object[] contextGUIDS = new object[] { };
            Commands2 commands = (Commands2)applicationObject.Commands;

            Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar =
              ((Microsoft.VisualStudio.CommandBars.CommandBars)
              applicationObject.CommandBars)["MenuBar"];

            //Find the Tools command bar on the MenuBar command bar:
            CommandBarControl toolsControl = menuBarCommandBar.Controls["File"];
            CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl;
            CommandBar oBar = null;
            CommandBarButton oBtn = null;
            //This try/catch block can be duplicated if you wish to add multiple commands
            //  to be handled by your Add-in, just make sure you also update the
            //  QueryStatus/Exec method to include the new command names.
            try
            {
                //User Code Start
                //searhing if submenu already exists
                for (int iloop = 1; iloop <= toolsPopup.CommandBar.Controls.Count; iloop++)
                {
                    if (toolsPopup.CommandBar.Controls[iloop].Caption == ASPOSE_MENU_CAPTION)
                    {
                        oBar = ((CommandBarPopup)toolsPopup.CommandBar.Controls[iloop]).CommandBar;
                        foreach (CommandBarButton cmdbtn in oBar.Controls)
                        {
                            if (cmdbtn.Caption == Cells_COMMAND_CAPTION)
                            {
                                oBtn = cmdbtn;
                            }
                        }
                        break;
                    }
                }

                //if required submenu doesn't exist create a new one
                if (oBar == null)
                    oBar = (CommandBar)commands.AddCommandBar(ASPOSE_MENU_CAPTION,
                            vsCommandBarType.vsCommandBarTypeMenu, toolsPopup.CommandBar, 1);

                if (oBtn == null)
                {
                    //Add a command to the Commands collection:
                    Command myCommand = commands.AddNamedCommand2(addInInstance, Cells_COMMAND_NAME,
                        Cells_COMMAND_CAPTION, Cells_COMMAND_TOOLTIP, false, Resources.pnglogosmall, ref contextGUIDS,
                        (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                        (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    //Add a control for the command to the tools menu:
                    if ((myCommand != null) && (toolsPopup != null))
                        myCommand.AddControl(oBar, 1);

                }

                //User Code End
            }
            catch (System.ArgumentException)
            {
                // If we are here, then the exception is probably
                // because a command with that name already exists.
                // If so there is no need to recreate the command and we can 
                // safely ignore the exception.
            }
        }