Example #1
0
        /// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary>
        /// <param term='application'>Root object of the host application.</param>
        /// <param term='connectMode'>Describes how the Add-in is being loaded.</param>
        /// <param term='addInInst'>Object representing this Add-in.</param>
        /// <seealso class='IDTExtensibility2' />
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            _applicationObject = (DTE2)application;
            _addInInstance     = (AddIn)addInInst;

            _actionMgr = new ActionManager();
            _handler   = new MenuActionHandler(_applicationObject);

            if (connectMode == ext_ConnectMode.ext_cm_AfterStartup)
            {
                object[]  contextGUIDS = new object[] { };
                Commands2 commands     = (Commands2)_applicationObject.Commands;

                // get popUp command bars where commands will be registered.
                CommandBars cmdBars         = (CommandBars)(_applicationObject.CommandBars);
                CommandBar  vsBarCodeWindow = cmdBars["Code Window"];

                //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
                {
                    CommandBarBuilder builder = new CommandBarBuilder(_actionMgr, _handler);
                    builder.BuildMenu(vsBarCodeWindow.Controls, MenuXml.Load(@"C:\Corey Derochie\test.xml"));
                }
                catch (System.ArgumentException argEx)
                {
                    System.Diagnostics.Debug.Write("Exception in HintPaths:" + argEx.ToString());
                    //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.
                }
            }
        }
Example #2
0
 public Visitor(CommandBarBuilder builder, CommandBarPopup parent)
 {
     _builder = builder;
     Parent   = parent;
 }