public void TestIndexComboBox()
        {
            UIThreadInvoker.Invoke((ThreadInvoker) delegate()
            {
                //Get the global service provider and the dte
                IServiceProvider sp = VsIdeTestHostContext.ServiceProvider;
                DTE dte             = (DTE)sp.GetService(typeof(DTE));

                //Show toolbar
                CommandBars commandBars = (CommandBars)dte.CommandBars;
                commandBars["ComboBoxSample"].Visible = true;

                // Create the messageBoxListener Thread.
                string expectedDialogBoxText = String.Format(System.Globalization.CultureInfo.CurrentCulture,
                                                             "{0}\n\n{1}", "My Index Combo", "1");
                DialogBoxPurger purger = new DialogBoxPurger(NativeMethods.IDOK, expectedDialogBoxText);

                try
                {
                    purger.Start();

                    dte.ExecuteCommand("Tools.IndexCombo", "Tigers");
                }
                finally
                {
                    Assert.IsTrue(purger.WaitForDialogThreadToTerminate(), "The Index Combo dialog box has not shown");
                }
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        ///		Applies the toolbars to the given window.
        /// </summary>
        /// <param name="window">The window to apply to.</param>
        internal void Apply(OfficeWindow window)
        {
            CommandBars bars = window.CommandBars;

            foreach (Toolbar toolbar in toolbars.Values)
            {
                CommandBar commandbar = null;
                try
                {
                    commandbar = bars[toolbar.Caption];
                }
                catch
                {
                }
                if (commandbar == null)
                {
                    commandbar = bars.Add(toolbar.Caption, toolbar.Position, false, true);
                }
                else
                {
                }
                toolbar.Apply(window, commandbar);
                manager.RegisterCommandBar(commandbar, window, toolbar);
            }
        }
Ejemplo n.º 3
0
        }     // RemoveCommand

        /// <summary>
        /// Remove a Control from a CommnandBar
        /// </summary>
        /// <param name="applicationObject">The host application.</param>
        /// <param name="commandBarName"></param>
        /// <param name="controlName"></param>
        public static void RemoveCommandControl(DTE2 applicationObject, string commandBarName, string controlName)
        {
            // Remove the controls from the CommandBars
            try
            {
                CommandBars       cmdBars = (CommandBars)(applicationObject.CommandBars);
                CommandBar        bar     = cmdBars[commandBarName];
                CommandBarControl ctrl    = null;
                for (int n = 1; n <= bar.Controls.Count; n++)
                {
                    string cap = bar.Controls[n].Caption;
                    if (bar.Controls[n].Caption == controlName)
                    {
                        ctrl = bar.Controls[n];
                    }
                }     // for
                // CommandBarControl ctrl = bar.Controls[controlName];
                if (ctrl != null)
                {
                    ctrl.Delete(false);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message, "ChirpyPopupAddIn.RemoveCommandControl");
            } // try
        }     // RemoveCommandControl
Ejemplo n.º 4
0
        private void RemoveCommandBar(string name, IVsProfferCommands3 profferCommands3)
        {
            // Remove a command bar and contained controls
            DTE2        dte            = GetGlobalService(typeof(DTE)) as DTE2;
            CommandBars commandBars    = (CommandBars)dte.CommandBars;
            Commands    commands       = dte.Commands;
            CommandBar  existingCmdBar = null;

            try
            {
                existingCmdBar = commandBars[name];
            }
            catch (Exception)
            {
            }

            if (existingCmdBar != null)
            {
                // Remove all buttons

                while (existingCmdBar.Controls.Count > 0)
                {
                    foreach (CommandBarControl ctrl in existingCmdBar.Controls)
                    {
                        profferCommands3.RemoveCommandBarControl(ctrl);
                        break;
                    }
                }
            }
            profferCommands3.RemoveCommandBar(existingCmdBar);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Handles the Startup event of the ThisDocument control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 private void ThisDocument_Startup(object sender, System.EventArgs e)
 {
     app            = ThisApplication;
     commandbars    = Globals.ThisDocument.CommandBars;
     textCommandBar = commandbars["Text"] as CommandBar;
     refreshDocumentCommandBarButton = AddCommandBar(textCommandBar, new _CommandBarButtonEvents_ClickEventHandler(RefreshDocumentCommandBarButton_Click), 1, "refreshDocument", "Refresh Document");
 }
Ejemplo n.º 6
0
        public static bool AddOpenFloderFoVS()
        {
            CommandBars cmdBars          = (CommandBars)(Common.chDTE.DTE.CommandBars);
            CommandBar  vsBarProjectItem = cmdBars["Item"];

            menuItemPI = vsBarProjectItem.Controls.Add(MsoControlType.msoControlButton, 1, "", 2, true);

            menuItemPI.Caption = "在 Windows 资源管理器中打开文件夹(&X)";
            if (chDTE.Version != "10.0")
            {
                menuItemPI.TooltipText = menuItemPI.Caption;
            }
            menuItemHandlerPI        = (CommandBarEvents)Common.chDTE.DTE.Events.get_CommandBarEvents(menuItemPI);
            menuItemHandlerPI.Click += new _dispCommandBarControlEvents_ClickEventHandler(menuItemHandler_Click);

            if (chDTE.Version != "8.0")
            {
                return(true);
            }

            CommandBar vsBarProject = cmdBars["Project"];

            menuItem = vsBarProject.Controls.Add(MsoControlType.msoControlButton, 1, "", 2, true);

            menuItem.Caption = "在 Windows 资源管理器中打开文件夹(&X)";
            if (chDTE.Version != "10.0")
            {
                menuItem.TooltipText = menuItem.Caption;
            }
            menuItemHandler        = (CommandBarEvents)Common.chDTE.DTE.Events.get_CommandBarEvents(menuItem);
            menuItemHandler.Click += new _dispCommandBarControlEvents_ClickEventHandler(menuItemHandler_Click);
            return(true);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 从菜单或工具条中删除指定的命令
        /// </summary>
        /// <param name="CmdName"></param>
        /// <param name="SubItemName"></param>
        /// <param name="Name"></param>
        /// <param name="Caption"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static Exception DeleteCommand(string CmdName, string SubItemName, string Name, string Caption)
        {
            //CmdName 工具条名称, SubItemName 工具条子项目名称,Name 要添加的项目名称,
            //Caption 要添加的项目标题.此方法内用于删除该按钮/项
            Exception   e            = null;
            Commands2   Cmds         = (Commands2)chDTE.Commands;
            CommandBars CmdBars      = (CommandBars)chDTE.CommandBars;
            CommandBar  mnuBarCmdBar = CmdBars[CmdName];
            //菜单
            CommandBarControl CmdCtrl  = mnuBarCmdBar.Controls[SubItemName];
            CommandBarPopup   CmdPopup = (CommandBarPopup)CmdCtrl;

            try
            {
                Cmds.Item("KeelKit.Commands." + Name, 0).Delete();
            }
            catch (Exception ex)
            {
                e = ex;
            }
            try
            {
                CommandBarControl chCmdConfig = CmdPopup.Controls[Caption];
                chCmdConfig.Delete(null);
            }
            catch (Exception ex)
            {
                e = ex;
            }
            return(e);
        }
Ejemplo n.º 8
0
        public static void DelOpenFloderForVS()
        {
            CommandBars cmdBars = (CommandBars)(Common.chDTE.DTE.CommandBars);

            if (menuItemPI != null)
            {
                menuItemPI.Delete(null);
            }
            if (menuItem != null)
            {
                menuItem.Delete(null);
            }
            if (menuItemCTH != null)
            {
                menuItemCTH.Delete(null);
            }
            if (menuItemCTH_C != null)
            {
                menuItemCTH_C.Delete(null);
            }
            if (menuItemCopyPath != null)
            {
                menuItemCopyPath.Delete(null);
            }
            if (menuItem != null)
            {
                menuItem.Delete(null);
            }
            //if (menuItemCTH != null)
            //{
            //    menuItemCTH.Delete(null);
            //}
        }
Ejemplo n.º 9
0
        public void SynchronizeClassView()
        {
            CommandBars cmdBars          = (CommandBars)(Common.chDTE.DTE.CommandBars);
            CommandBar  vsBarProjectItem = cmdBars["Item"];

            menuItemPI = vsBarProjectItem.Controls.Add(MsoControlType.msoControlButton, 1, "", 2, true);
        }
Ejemplo n.º 10
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;

            if (connectMode == ext_ConnectMode.ext_cm_UISetup)
            {
                object[]  contextGUIDS = new object[] { };
                Commands2 commands     = (Commands2)_applicationObject.Commands;
                commandBars = (CommandBars)_applicationObject.CommandBars;
                try
                {
                    commandBar = (CommandBar)commandBars["Code Window"];

                    //Add a command to the Commands collection:
                    command = commands.AddNamedCommand2(_addInInstance, "ReviewCode", "ReviewCode", "Executes the command for ReviewCode", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    //Command command2 = commands.AddNamedCommand2(_addInInstance,"Review Code","MyaddIn2","Execute the process for review code", true,59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported+(int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    //Add a control for the command to the tools menu:
                    if ((command != null) && (commandBar != null))
                    {
                        //command.AddControl(toolsPopup.CommandBar, 1);
                        command.AddControl(commandBar, 1);
                    }
                    Buisness.InteractWindow.OpenPendingChangesWindow((CommandBars)_applicationObject.CommandBars);
                }
                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.
                }
            }
        }
Ejemplo n.º 11
0
        public CommandBar AddCommandBar(string name, MsoBarPosition position)
        {
            CommandBars cmdBars = (Microsoft.VisualStudio.CommandBars.CommandBars)m_application.CommandBars;
            CommandBar  bar     = null;

            try
            {
                try
                {
                    // Create the new CommandBar
                    bar         = cmdBars.Add(name, position, false, false);
                    bar.Visible = true;
                }
                catch (ArgumentException)
                {
                    // Try to find an existing CommandBar
                    bar = cmdBars[name];
                }
            }
            catch
            {
            }

            return(bar);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Solution Platform command is shown in the Standard toolbar by default with Visual C++ settings. Add the
        /// command if not in the Standard toolbar.
        /// </summary>
        private void CheckSolutionPlatformCommand()
        {
            DTE         dte                = (DTE)_applicationObject;
            CommandBars commandBars        = (CommandBars)dte.CommandBars;
            CommandBar  standardCommandBar = commandBars[STANDARD_TOOL_BAR];
            int         pos                = 0;

            foreach (CommandBarControl cmd in standardCommandBar.Controls)
            {
                if (cmd.Caption == SOLUTION_CONFIGURATIONS)
                {
                    pos = cmd.Index;
                }
                if (cmd.Caption == SOLUTION_PLATFORMS)
                {
                    return;
                }
            }

            Command sp = null;

            foreach (Command c in dte.Commands)
            {
                if (c.Guid == GuidList.guidVSStd2KString && c.ID == CommandConstants.cmdidSolutionPlatform)
                {
                    sp = c;
                    break;
                }
            }
            if (sp != null)
            {
                sp.AddControl(standardCommandBar, pos + 1);
            }
        }
Ejemplo n.º 13
0
        /// <summary>This method gets the command bar named in
        /// commandBarName.</summary>
        /// <param name="visioApplication">Current vision application.</param>
        /// <param name="commandBarName">Name of the command bar to be
        /// found</param>
        /// <returns>CommandBar object if found; otherwise null.</returns>
        public static CommandBar GetCommandBar(Application visioApplication, string commandBarName)
        {
            CommandBar currentCommandBar = null;

            try
            {
                CommandBars applicationCommandBars = (CommandBars)visioApplication.CommandBars;
                currentCommandBar = applicationCommandBars[commandBarName];
            }
            catch (COMException e)
            {
                // Some other COM screw-up. :/
                //ESITracer.Current.LogDebug("GetCommandBar:EXC:"+e.StackTrace.ToString());
                //if (e.InnerException != null)
                //    ESITracer.Current.LogDebug("GetCommandBar:EXC:INNER:" + e.InnerException.StackTrace.ToString());
            }
            catch (ArgumentException e)
            {
                // The CommandBar object was not found. Ignore the error.
                //ESITracer.Current.LogDebug("GetCommandBar:EXC:" + e.StackTrace.ToString());
                //if (e.InnerException != null)
                //    ESITracer.Current.LogDebug("GetCommandBar:EXC:INNER:" + e.InnerException.StackTrace.ToString());
            }
            catch (InvalidComObjectException e)
            {
                // The CommandBar object was not found. Ignore the error.

                /*ESITracer.Current.LogDebug("GetCommandBar:EXC:" + e.StackTrace.ToString());
                 * if (e.InnerException != null)
                 *  ESITracer.Current.LogDebug("GetCommandBar:EXC:INNER:" + e.InnerException.StackTrace.ToString());*/
            }

            return(currentCommandBar);
        }
Ejemplo n.º 14
0
        private void BindCommandBars()
        {
            CommandBars cmdBars = (DTEObject.CommandBars as CommandBars);

            #region SortedNames

            List <string> names = new List <string>(cmdBars.Count);
            foreach (CommandBar bar in cmdBars)
            {
                names.Add(bar.Name);
            }

            names.Sort();
            foreach (string name in names)
            {
                TreeNode node = new TreeNode();
                node.Text = name;
                node.Tag  = "bar";
                // Add a dummy node
                node.Nodes.Add("dummyNode");

                tvCommandBars.Nodes.Add(node);
            }

            #endregion
        }
Ejemplo n.º 15
0
        private void AddItemCommand(string name, string text, object bindings, int position, int faceId, bool beginGroup)
        {
            object[]    contextGUIDS = new object[] { };
            Commands2   commands     = (Commands2)_applicationObject.Commands;
            CommandBars commandBars  = ((CommandBars)_applicationObject.CommandBars);

            CommandBar[] targetBars = new CommandBar[] {
                commandBars["Folder"],
                commandBars["Project"]
            };

            try
            {
                Command command = commands.AddNamedCommand2(_addInInstance, name, text, null, true, faceId, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                if (bindings != null)
                {
                    command.Bindings = bindings;
                }
                if (command != null)
                {
                    foreach (CommandBar bar in targetBars)
                    {
                        CommandBarButton button = (CommandBarButton)command.AddControl(bar, position);
                        button.BeginGroup = beginGroup;
                    }
                }
            }
            catch (ArgumentException)
            {
            }
        }
Ejemplo n.º 16
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.
                }
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Get or create a command bar with the given name.
        /// </summary>
        /// <param name="name">The name of the command bar.</param>
        /// <returns>The command bar with the specified name. If the command bar does not exist the method creates a new one.</returns>
        protected override CommandBar GetCommandBar(string name)
        {
            Debug.WriteLine("GetCommandBar(" + name + ")");

            CommandBars commandBars = (CommandBars)Application.CommandBars;

            foreach (Object item in commandBars)
            {
                CommandBar commandBar = item as CommandBar;
                if (commandBar == null)
                {
                    continue;
                }

                if (commandBar.Name.Equals(name))
                {
                    return(commandBar);
                }
            }

            Debug.WriteLine("Command bar not found. Addin new...");

            CommandBar newCommandBar = (CommandBar)commandBars.Add(name, MsoBarPosition.msoBarTop, System.Type.Missing, true);

            newCommandBar.Visible = true;
            return(newCommandBar);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Gets the menu bar with the specified english name.
        /// </summary>
        /// <seealso cref="http://www.mztools.com/articles/2007/mz2007002.aspx">HOWTO: Locate commandbars in international versions of Visual Studio</seealso>
        /// <param name="application">The visual studio application object.</param>
        /// <param name="menuBarName">Then english name of the menu bar, e.g. Tools, Data, Window...</param>
        /// <returns>
        /// The menu bar with the specified english name or <c>null</c>
        /// if the menu bar was not found.
        /// </returns>
        public static bool TryGetMenuBar(this _DTE application, string menuBarName, out CommandBar menuBar)
        {
            CommandBars commandBars = (CommandBars)application.CommandBars;
            CommandBar  mainMenuBar = (CommandBar)commandBars["MenuBar"];

            foreach (CommandBarControl ctrl in mainMenuBar.Controls)
            {
                MsoControlType type = ctrl.Type;
                if (type != MsoControlType.msoControlPopup)
                {
                    continue;
                }

                CommandBarPopup ctrlPopup = (CommandBarPopup)ctrl;
                menuBar = ctrlPopup.CommandBar;
                string subMenuName = menuBar.Name;
                if (subMenuName.Equals(menuBarName, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(true);
                }
            }
            Debug.WriteLine("VsApplicationExtensions.GetMenuBar - Menu bar not found: " + menuBarName);
            menuBar = null;
            return(false);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Init constructor.
        /// </summary>
        public CustomAddInMenuManager(DTE2 appObject, AddIn addInInstance, IMenuCustomizator menuCustomizator)
        {
            this.appObject        = appObject;
            this.addInInstance    = addInInstance;
            this.menuCustomizator = menuCustomizator;
            isSetupUI             = true;

            try
            {
                if (resourceManager == null)
                {
                    resourceManager = new ResourceManager("Pretorianie.Tytan.Core.CustomAddIn.CommandBar", Assembly.GetExecutingAssembly());
                }
                if (cultureInfo == null)
                {
                    cultureInfo = new CultureInfo(this.appObject.LocaleID);
                }

                // get instances of default command and tool bars:
                vsCommandBars = appObject.CommandBars as CommandBars;
                if (vsCommandBars != null)
                {
                    mainMenu        = vsCommandBars["MenuBar"];
                    codeWindowMenu  = vsCommandBars["Code Window"];
                    standardToolbar = vsCommandBars["Standard"];
                }
            }
            catch (Exception e)
            {
                Trace.TraceError(e.ToString());
                throw;
            }
        }
Ejemplo n.º 20
0
        private void AddGenerateCodeBtn()
        {
            Command findCommand = null;

            object[]         contextUIGuids             = new object[] { };
            CommandBarButton findCommandBarButtonButton = null;
            Commands2        commands = (Commands2)_applicationObject.Commands;
            CommandBars      cmdBars  = (CommandBars)_applicationObject.CommandBars;

            if (findCommand == null)
            {
                findCommand = commands.AddNamedCommand2(
                    _addInInstance,
                    "GenerateCode",
                    "GenerateCode",
                    "GenerateCode",
                    true,
                    59,
                    ref contextUIGuids,
                    (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
            }
            if (findCommand != null)
            {
                //解决方案
                CommandBar codeWindowCommandBar3 = cmdBars["Project"];
                if (codeWindowCommandBar3 != null)
                {
                    findCommandBarButtonButton = (CommandBarButton)findCommand.AddControl(
                        codeWindowCommandBar3, codeWindowCommandBar3.Controls.Count + 1);
                    findCommandBarButtonButton.Caption = "rx_orm 强类型开发设置";
                }
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Create a new Command Bar and remove the existing Command Bar with the same name.
        /// </summary>
        /// <param name="applicationObject">The host application.</param>
        /// <param name="szName">The name of the new command bar.</param>
        /// <returns>The created CommandaBar object.</returns>
        public static CommandBar AddCommandBar(DTE2 applicationObject, String szName)
        {
            Commands   commands = applicationObject.Commands;
            CommandBar cmdBar   = null;

            try
            {
                CommandBars oldCmdBars = (CommandBars)applicationObject.CommandBars;
                CommandBar  oldCmdBar  = oldCmdBars[szName];
                commands.RemoveCommandBar(oldCmdBar);
            }
            catch (ArgumentException)
            {
                // Thrown if command doesn't already exist.
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message, "ChirpyPopupAddIn.AddCommandBar");
            }     // try

            try
            {
                cmdBar = (CommandBar)commands.AddCommandBar(szName, vsCommandBarType.vsCommandBarTypeToolbar, null, 0);
            }
            catch (ArgumentException)
            {
                // Thrown if command doesn't already exist.
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message, "ChirpyPopupAddIn.AddCommandBar");
            } // try
            return(cmdBar);
        }     // AddCommandBar
Ejemplo n.º 22
0
        public void AddCommandMenu(string commandName, string menuName, string menuText, string description, string shortCut, string helpTopic)
        {
            try // Basically suppress problems here..?
            {
                CommandBarPopup menu;
                if (!_foundMenus.TryGetValue(menuName, out menu))
                {
                    // We've not seen this menu before

                    // Check if the menu exists
                    CommandBars        commandBars  = ExcelCommandBarUtil.GetCommandBars();
                    CommandBar         worksheetBar = commandBars[1];
                    CommandBarControls controls     = worksheetBar.Controls;
                    int controlCount = controls.Count();

                    for (int i = 1; i <= controlCount; i++)
                    {
                        CommandBarControl control = controls[i];
                        if (control.Caption == menuName && control is CommandBarPopup)
                        {
                            menu = (CommandBarPopup)control;
                            _foundMenus[menuName] = menu;
                            break;
                        }
                    }

                    if (menu == null)
                    {
                        // Make a new menu
                        menu         = controls.AddPopup(menuName);
                        menu.Caption = menuName;
                        _addedMenus.Add(menu);
                        _foundMenus[menuName] = menu;
                    }
                }

                CommandBarControls menuButtons = menu.Controls;
                int buttonCount = menu.Controls.Count();
                for (int i = 1; i <= buttonCount; i++)
                {
                    CommandBarControl button = menuButtons[i];
                    if (button.Caption == menuText && button is CommandBarButton)
                    {
                        button.OnAction = commandName;
                        return;
                    }
                }

                // If we're here, need to add a button.
                CommandBarButton newButton = menuButtons.AddButton();
                newButton.Caption  = menuText;
                newButton.OnAction = commandName;
                _addedButtons.Add(newButton);
            }
            catch (Exception e)
            {
                Logger.Initialization.Error(e, "MenuManager.AddCommandMenu Error");
            }
        }
Ejemplo n.º 23
0
        public static IEnumerable <CommandBar> GetCommandBars(this DTE2 me)
        {
            CommandBars bars = (CommandBars)me.CommandBars;

            for (int i = 1; i <= bars.Count; i++)
            {
                yield return(bars[i]);
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Find the DTE_Menu ( CommandBar ) within the DTE complex.
        /// </summary>
        /// <param name="InMenuName"></param>
        /// <returns></returns>
        public DTE_Menu FindMenu(string InMenuName)
        {
            CommandBars bars = (CommandBars)dte2.CommandBars;

            Microsoft.VisualStudio.CommandBars.CommandBar cmdBar = null;
            cmdBar = DTE_Common.FindCommandBar(dte2, InMenuName);

            return(new DTE_Menu(this, cmdBar));
        }
Ejemplo n.º 25
0
        private void olustur()
        {
            const string vsStandardCommandbarName = "Standard";
            Command      myCommand = null;

            object[] contextUiGuids = new object[] { };

            try
            {
                // Try to retrieve the command, just in case it was already created, ignoring the
                // exception that would happen if the command was not created yet.
                try
                {
                    myCommand = _applicationObject.Commands.Item(_addInInstance.ProgID + "." + MyCommandName, -1);
                }
                catch
                {
                }

                // Add the command if it does not exist
                if (myCommand == null)
                {
                    myCommand = _applicationObject.Commands.AddNamedCommand(_addInInstance,
                                                                            MyCommandName, MyCommandCaption, MyCommandTooltip, true, 59, ref contextUiGuids,
                                                                            (int)(vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled));
                }

                // Retrieve the collection of commandbars
                CommandBars commandBars = (CommandBars)_applicationObject.CommandBars;

                // Retrieve some built-in commandbars
                CommandBar standardCommandBar = commandBars[vsStandardCommandbarName];

                // Add a button on the "Standard" toolbar
                _myStandardCommandBarButton = (CommandBarButton)myCommand.AddControl(standardCommandBar,
                                                                                     standardCommandBar.Controls.Count + 1);

                // Change some button properties
                _myStandardCommandBarButton.Caption    = MyCommandCaption;
                _myStandardCommandBarButton.BeginGroup = true;

                // Get if the toolwindow was visible when the add-in was unloaded last time to show it
                Microsoft.Win32.RegistryKey registryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\SaveTabs");
                if (registryKey != null)
                {
                    if ((int)registryKey.GetValue("SaveTabsVisible") == ToolwindowVisible)
                    {
                        showToolWindow();
                    }
                    registryKey.Close();
                }
            }
            catch (System.Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.ToString());
            }
        }
Ejemplo n.º 26
0
        FindCommandBar(
            DTE2 InDte2,
            string InBarName)
        {
            CommandBars bars = (CommandBars)InDte2.CommandBars;
            CommandBar  bar  = CommandBars_FindBar(bars, InBarName);

            return(bar);
        }
        /// <summary>
        /// Open Pending Changes Window
        /// </summary>
        /// <param name="cmdBar">Take CommanBars of the main Window </param>
        public static void OpenPendingChangesWindow(CommandBars cmdBar)
        {
            CommandBar       cmdMenuBar             = (CommandBar)cmdBar[1];
            CommandBarPopup  cmdBarPopupView        = (CommandBarPopup)cmdMenuBar.Controls[3];
            CommandBar       cmdBarView             = cmdBarPopupView.CommandBar;
            CommandBarPopup  cmdOtherWindowBarPopup = (CommandBarPopup)cmdBarView.Controls["Other Windows"];
            CommandBarButton buttonPendingChanges   = (CommandBarButton)cmdOtherWindowBarPopup.Controls[17];

            buttonPendingChanges.Execute();
        }
Ejemplo n.º 28
0
        // This method closes the toolbar.
        public void CloseToolbar()
        {
            CommandBars cbars = (CommandBars)_applicationObject.CommandBars;

            try
            {
                cbars["opCppToolbar"].Delete();
            }
            catch (Exception) {}
        }
        /// <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;

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

                // Add new toolbar and set enabled and visible
                CommandBars commandBars = _applicationObject.CommandBars as CommandBars;
                CommandBar  toolbar     = commandBars.Add("AlphaToolbar", MsoBarPosition.msoBarTop, System.Type.Missing, true);
                toolbar.Visible = true;
                toolbar.Enabled = true;

                // Make sure the alpha command doesn't already exist
                Command commandAlpha = null, commandOmega = null;

                try
                {
                    commandAlpha = commands.Item("AlphaBlendToolbar.Connect.AlphaButton");
                }
                catch (System.ArgumentException)
                {
                    // Load the alpha button image from a 32-bit alpha-transparent portable network graphic file which is an
                    // embedded resource in this project.  This image could also be loaded directly from disk.
                    System.Drawing.Bitmap alpha = new System.Drawing.Bitmap(typeof(AlphaBlendToolbar.Connect), @"alpha.png");

                    // Create the alpha button command, specifying the command name, button text, tooltip, bitmap image,
                    // status, style, and control type.  Add this command to the AlphaToolbar.
                    commandAlpha = commands.AddNamedCommand2(_addInInstance, "AlphaButton", "Alpha", "Alpha Command", false, alpha, ref contextGUIDS,
                                                             (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                }
                commandAlpha.AddControl(toolbar, 1);

                // Make sure the omega command doesn't already exist
                try
                {
                    commandOmega = commands.Item("AlphaBlendToolbar.Connect.OmegaButton");
                }
                catch (System.ArgumentException)
                {
                    // Load the omega button image from a 32-bit alpha-transparent portable network graphic file which is an
                    // embedded resource in this project.  This image could also be loaded directly from disk.
                    System.Drawing.Bitmap omega = new System.Drawing.Bitmap(typeof(AlphaBlendToolbar.Connect), @"omega.png");

                    // Create the omega button command, specifying the command name, button text, tooltip, bitmap image,
                    // status, style, and control type.  Add this command to the AlphaToolbar.
                    commandOmega = commands.AddNamedCommand2(_addInInstance, "OmegaButton", "Omega", "Omega Command", false, omega, ref contextGUIDS,
                                                             (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                }
                commandOmega.AddControl(toolbar, 2);
            }
        }
Ejemplo n.º 30
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)
        {
            AppLog.LogMessage("Entering OnConnection method.");

            this.applicationObject = (DTE2)application;
            // Initialize VsHelper.
            this.visualStudio = new VisualStudio(this.applicationObject);

            this.addInInstance = (AddIn)addInInst;
            object[] contextGUIDS = new object[] { };
            //CommandBar cmdBar;
            //Command cmdObj;

            if (connectMode == ext_ConnectMode.ext_cm_Startup ||
                connectMode == ext_ConnectMode.ext_cm_AfterStartup ||
                connectMode == ext_ConnectMode.ext_cm_UISetup)
            {
                AppLog.LogMessage("Creating commands.");

                Commands2   commands    = (Commands2)applicationObject.Commands;
                CommandBars commandBars = (CommandBars)applicationObject.CommandBars;

                try
                {
                    menuBuilder = new MenuBuilder(visualStudio);

                    // Add command bar to tools menu
                    contextGUIDS = menuBuilder.AddCommandBarToToolsMenu(addInInstance, applicationObject, commands, contextGUIDS, commandBars);
                    // Create the 'Generate Web Service Code...' context-menu entry
                    contextGUIDS = menuBuilder.GenerateMenuItemForWSCodeGen(addInInstance, applicationObject, commands, contextGUIDS);
                    // Create the 'Edit WSDL Interface Description...' context-menu entry
                    contextGUIDS = menuBuilder.GenerateMenuItemForEditWsdl(addInInstance, applicationObject, commands, contextGUIDS);
                    // Create the 'Create WSDL Interface Description...' context-menu entry
                    contextGUIDS = menuBuilder.GenerateMenuItemForCreateWsdl(addInInstance, applicationObject, commands, contextGUIDS);
                    // Create the 'Choose WSDL to implement...' context-menu entry
                    contextGUIDS = menuBuilder.GenerateMenuItemForChooseWsdlToImplement(addInInstance, applicationObject, commands, contextGUIDS);
                    // Create the 'Generate code...' context-menu entry
                    //GenerateMenuItemForDCCodeGen(commands, contextGUIDS);
                    contextGUIDS = menuBuilder.GenerateMenuItemForDCCodeGen(addInInstance, applicationObject, commands, contextGUIDS);
                    // Create the 'Paste XML as Schema' Edit menu entry.
                    menuBuilder.GenerateMenuItemForPasteXmlAsSchema(addInInstance, applicationObject, commands, commandBars, contextGUIDS);
                }
                catch (ArgumentException e)
                {
                    AppLog.LogMessage(e.Message);
                }
                catch (Exception e)
                {
                    AppLog.LogMessage(e.Message);
                }
            }

            AppLog.LogMessage("Leaving OnConnection method.");
        }
 /// <summary>
 /// Returns an instance of the selected command bar by name
 /// </summary>
 /// <param name="commandBars">A vector of command bars</param>
 /// <param name="commandBarName">Command bar name</param>
 /// <param name="commandBar">Handle of the selected command bar</param>
 private void getCommandBarInstanceByName(CommandBars commandBars, string commandBarName, out CommandBar commandBar)
 {
     try
     {
         commandBar = null;
         commandBar = Globals.ThisAddIn.Application.CommandBars[commandBarName];
     }
     catch (Exception)
     {
         commandBar = null;
     }
 }
    	public object[] AddCommandBarToToolsMenu(AddIn addInInstance, DTE2 applicationObject, Commands2 commands, object[] contextGUIDS, CommandBars commandBars)
        {
            Command command = commands.AddNamedCommand2(
                addInInstance,
                "WsContractFirst",
                "Web Services Contract-First...",
                "Executes the command for WsContractFirstAddin",
                true,
                190,
                ref contextGUIDS,
                (int)vsCommandStatus.vsCommandStatusUnsupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                (int)vsCommandStyle.vsCommandStylePictAndText,
                vsCommandControlType.vsCommandControlTypeButton);

			command.AddControl(toolsSubMenuCommandBar, 1);

            AppLog.LogMessage("Command bar is added to the Tools menu.");
            return contextGUIDS;
        }
 private void Initialize()
 {
     contextGUIDs = new object[] { };
     commandBars = (CommandBars)_applicationObject.CommandBars;
     mainMenuBar = commandBars["MenuBar"];
 }
Ejemplo n.º 34
0
Archivo: VsAddIn.cs Proyecto: WSCF/WSCF
 private static CommandBar FindCommandBarByName(CommandBars commandBars, string name)
 {
     return commandBars
         .OfType<CommandBar>()
         .FirstOrDefault(cb => cb.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
 }
Ejemplo n.º 35
0
Archivo: VsAddIn.cs Proyecto: WSCF/WSCF
 private static CommandBar GetToolsCommandBar(CommandBars commandBars)
 {
     try
     {
         // Tools can only be located through the indexer.
         return commandBars["Tools"];
     }
     catch
     {
         return null;
     }
 }
Ejemplo n.º 36
0
        private CommandBar getCommandBar(CommandBars bars, string name)
        {
            var enu = bars.GetEnumerator();

            while (enu.MoveNext())
            {
                var control = (CommandBar)enu.Current;
                if (control.accName == name)
                    return control;
            }
            return null;
        }
Ejemplo n.º 37
0
        internal override void Dispose(bool disposing)
        {
            if (disposing)
            {
                // Free managed
                if (_commandBars != null && !_commandBars.IsDisposed)
                {
                    _commandBars.Dispose();
                    _commandBars = null;
                }
            }

            base.Dispose(true);
        }
		public void GenerateMenuItemForPasteXmlAsSchema(AddIn addInInstance, DTE2 applicationObject, Commands2 commands, CommandBars commandBars, object[] contextGUIDS)
		{
			Command cmdObj = commands.AddNamedCommand2(
				addInInstance,
				"PasteSchemaMenu",
				"Paste XML as Schema",
				"Pastes the XML on the clipboard as XSD schema.",
				true,
				239,
				ref contextGUIDS,
				(int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
				(int)vsCommandStyle.vsCommandStylePictAndText,
				vsCommandControlType.vsCommandControlTypeButton);

			CommandBar menuBarCommandBar = commandBars["MenuBar"];

			CommandBarControl editControl = menuBarCommandBar.Controls["Edit"];
			CommandBarPopup editPopup = (CommandBarPopup)editControl;
			CommandBarControl pasteControl = editPopup.CommandBar.Controls["Paste"];

			cmdObj.AddControl(editPopup.CommandBar, pasteControl != null ? pasteControl.Index + 1 : 1);

			AppLog.LogMessage("Paste Schema code menu item is added");
		}