Пример #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.
                }
            }
        }
Пример #2
0
        public void BuildMenu(CommandBarControls menu, MenuXml rootNode)
        {
            var root    = addSubMenu(menu, "MoreMenus");
            var visitor = new Visitor(this, root);

            foreach (var item in rootNode.Items)
            {
                item.Accept(visitor);
            }
        }
Пример #3
0
        public static void Create(string path)
        {
            var root = new MenuXml()
            {
                Items = new[] {
                    new MenuTreeDefinition()
                    {
                        Caption  = "Root",
                        Children = new MenuNodeDefinition[] {
                            new MenuTreeDefinition()
                            {
                                Caption  = "Menu1",
                                Children = new [] {
                                    new MenuItemDefinition()
                                    {
                                        Caption   = "Item1",
                                        Action    = "Action1",
                                        Arguments = new [] {
                                            new MenuItemArgument()
                                            {
                                                Name  = "Arg1",
                                                Value = "A1"
                                            },
                                            new MenuItemArgument()
                                            {
                                                Name  = "Arg2",
                                                Value = "A2"
                                            }
                                        }
                                    }
                                }
                            },
                            new MenuItemDefinition()
                            {
                                Caption   = "Item2",
                                Action    = "Action2",
                                Arguments = new [] {
                                    new MenuItemArgument()
                                    {
                                        Name  = "Arg3",
                                        Value = "A3"
                                    }
                                }
                            },
                            new MenuItemDefinition()
                            {
                                Caption   = "Item3",
                                Action    = "Action3",
                                Arguments = new [] {
                                    new MenuItemArgument()
                                    {
                                        Name  = "Arg4",
                                        Value = "A4"
                                    }
                                }
                            }
                        }
                    }
                }
            };

            root.Save(path);
        }