Beispiel #1
0
        private void ShowMenuItems()
        {
            RemoveMenuItems();
            // only add menu items if not already present
            try
            {
                // get the main menu bar
                CommandBar menuBar = wordApp.CommandBars["Menu Bar"];

                // check for the Dommoni popup menu item
                foreach (CommandBarControl menuItem in menuBar.Controls)
                {
                    if (menuItem.Caption == MENU_ITEM_ROUNDTABLE)
                    {
                        popup = (CommandBarPopup)menuItem;
                    }
                }

                if (popup == null || popup.Controls == null || popup.Controls.Count == 0)
                {
                    // wasn't there, so make it and add all the buttons
                    CommandBarControl helpMenu = menuBar.Controls["&Help"];                     // put it before the Help item
                    popup         = (CommandBarPopup)menuBar.Controls.Add(10, Type.Missing, Type.Missing, helpMenu.Index, false);
                    popup.Caption = MENU_ITEM_ROUNDTABLE;

                    bnSendToRoundTable =
                        (CommandBarButton)popup.Controls.Add(MsoControlType.msoControlButton, Type.Missing, Type.Missing, Type.Missing, false);
                    bnSendToRoundTable.Caption = MENU_ITEM_SEND_TO_ROUNDTABLE;
                    bnSendToRoundTable.Tag     = "SEND";

                    bnOpenFromRoundTable =
                        (CommandBarButton)popup.Controls.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing, false);
                    bnOpenFromRoundTable.Caption = MENU_ITEM_OPEN_FROM_ROUNDTABLE;
                    bnOpenFromRoundTable.Tag     = "OPEN";

                    bnEditSettings =
                        (CommandBarButton)popup.Controls.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing, false);
                    bnEditSettings.Caption = MENU_ITEM_EDIT_SETTINGS;
                    bnEditSettings.Tag     = "EDIT";

                    bnAbout =
                        (CommandBarButton)popup.Controls.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing, false);
                    bnAbout.Caption = MENU_ITEM_ABOUT;
                    bnAbout.Tag     = "ABOUT";
                }
                else
                {
                    // TODO: Add check here. This could cause an error.

                    bnSendToRoundTable   = (CommandBarButton)popup.Controls[MENU_ITEM_SEND_TO_ROUNDTABLE];
                    bnOpenFromRoundTable = (CommandBarButton)popup.Controls[MENU_ITEM_OPEN_FROM_ROUNDTABLE];
                    bnEditSettings       = (CommandBarButton)popup.Controls[MENU_ITEM_EDIT_SETTINGS];
                    bnAbout = (CommandBarButton)popup.Controls[MENU_ITEM_ABOUT];
                }
            }
            catch (System.Exception ex)
            {
                //ErrorHandler.PublishError(ex,logger);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Setups the reviewPal menu item.
        /// </summary>
        private void SetupReviewPalMenuItem()
        {
            const string toolsMenuName = "Tools";

            //Place the command on the tools menu.
            //Find the MenuBar command bar, which is the top-level command bar holding all the main menu items:
            CommandBar menuBarCommandBar =
                ((CommandBars)_visualStudioInstance.CommandBars)["MenuBar"];

            //Find the Tools command bar on the MenuBar command bar:
            CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName];
            CommandBarPopup   toolsPopup   = (CommandBarPopup)toolsControl;

            CommandBar commandBar = toolsPopup.GetType().InvokeMember("CommandBar",
                                                                      BindingFlags.Instance | BindingFlags.GetProperty,
                                                                      null, toolsPopup, null) as CommandBar;

            //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
            {
                AddCommand("ReviewPal", "Review Pal", "Opens up the ReviewPal review list", 1, commandBar, 1, false, null);
            }
            catch (ArgumentException ex)
            {
                //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.
            }
        }
Beispiel #3
0
        /// <summary>
        /// Creates the user interface.
        /// </summary>
        public void CreateUserInterface()
        {
            //  Get the sil command name.
            var silCommandId = addIn.ProgID + "." + Command_SeeIL_CommandName;

            //  If we don't have the command, create it.
            if (application.Commands.OfType <Command>().Any(c => c.Name != silCommandId))
            {
                CreateCommands();
            }

            //  Create the control for the Sil command.
            try
            {
                var commandSil = application.Commands.Item(addIn.ProgID + "." + Command_SeeIL_CommandName);

                //  Retrieve the context menu of code windows.
                var commandBars          = (CommandBars)application.CommandBars;
                var codeWindowCommandBar = commandBars["Code Window"];

                //  Clean up duplicate commands.
                CleanUpCodeMenu(codeWindowCommandBar);

                //  Add the one line command.
                controlCodeMenuDisassembleCommand = (CommandBarControl)commandSil.AddControl(codeWindowCommandBar,
                                                                                             codeWindowCommandBar.Controls.Count + 1);
            }
            catch (Exception exception)
            {
                ExceptionHandler.HandleException(@"Failed to create the 'Disassemble' command.", exception);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Adds a new Command and creates a new CommandBar control both of which
        /// can be returned via the AddCommandReturn object that holds refs to both.
        /// </summary>
        /// <param name="name">The name of the Command. Must be handled in the Addin</param>
        /// <param name="caption">The Caption</param>
        /// <param name="description">Tooltip Text</param>
        /// <param name="iconId">Icon Id if you use a custom icon. Otherwise use 0</param>
        /// <param name="commandBar">The Command bar that this command will attach to</param>
        /// <param name="insertionIndex">The InsertionIndex for this CommandBar</param>
        /// <param name="beginGroup">Are we starting a new group on the toolbar (above)</param>
        /// <param name="hotKey">Optional hotkey. Format: "Global::alt+f1"</param>
        /// <returns>AddCommandReturn object that contains a Command and CommandBarControl object that were created</returns>
        private void AddCommand(string name, string caption, string description,
                                int iconId, CommandBar commandBar, int insertionIndex,
                                bool beginGroup, string hotKey)
        {
            object[] contextGuids = new object[] { };

            // *** Check to see if the Command exists already to be safe
            string  commandName = _addInInstance.ProgID + "." + name;
            Command command     = null;

            try
            {
                command = _visualStudioInstance.Commands.Item(commandName, -1);
            }
            catch {; }
            // *** If not create it!
            if (command == null)
            {
                Commands2 commands = (Commands2)_visualStudioInstance.Commands;

                //Add a command to the Commands collection:
                //loading the Custom image icon
                //http://tech.einaregilsson.com/2009/11/20/easy-way-to-have-custom-icons-in-visual-studio-addin/
                command = commands.AddNamedCommand2(_addInInstance,
                                                    name, caption, description,
                                                    false, iconId, ref contextGuids,
                                                    (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                                                    (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
            }
            CommandBarControl cb = (CommandBarControl)command.AddControl(commandBar, insertionIndex);

            cb.BeginGroup = beginGroup;
        }
Beispiel #5
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);
        }
        void add_or_replace_command(int iconStartNumber)
        {
            object []    contextGUIDS = new object[] { };
            Commands     commands     = applicationObject.Commands;
            _CommandBars commandBars  = applicationObject.CommandBars;


            try {
                System.Collections.IEnumerator enm = commands.GetEnumerator();
                while (enm.MoveNext())
                {
                    Command cmd = (Command)enm.Current;
                    if (cmd.Name == "MultiLineFindReplace.Connect.MultiLineFindReplace")
                    {
                        cmd.Delete();
                    }
                }

                System.Diagnostics.Debug.WriteLine("---> iconNumber = " + iconNumber.ToString());
                System.Diagnostics.Debug.WriteLine("---> iconStartNumber = " + iconStartNumber.ToString());
                if (iconNumber < iconStartNumber)
                {
                    iconNumber = iconStartNumber;
                }
                Command command = commands.AddNamedCommand(addInInstance, "MultiLineFindReplace", "Find and Replace (Multi-line)", "Find and Replace with multi-line search and replacement strings", true,
                                                           /*1202*/ iconNumber++, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled);
                CommandBar        commandBar        = (CommandBar)commandBars["Edit"];
                CommandBarControl commandBarControl = command.AddControl(commandBar, 1);
            }
            catch (System.Exception e /*e*/)
            {
                MessageBox.Show("Exception in MultiLineFindReplace add_or_replace_command: " + e.Message);
            }
        }
Beispiel #7
0
 public SheetContextMenuItem(CommandBarControl control)
 {
     Text = Helper.RemoveShortCutKey(control.Caption);
     TooltipText = Helper.RemoveShortCutKey(control.TooltipText);
     CommandControl = control;
     Command = new DelegateCommand(_ => CommandControl.Execute());
 }
Beispiel #8
0
        ///////////////////////////////////////////////////////////////////////
        //
        // MENU ITEMS CREATION
        //
        ///////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Adds the command.
        /// </summary>
        /// <param name="menu">The popup menu.</param>
        /// <param name="cmd">The command.</param>
        /// <param name="position">The position in the menu.</param>
        public void AddCommandMenu(CommandBarPopup popupMenu, CommandBase cmd, int position)
        {
            CommandBarControl menuItem = AddMenuItem(popupMenu, cmd, position);

            AddClickEventHandler(menuItem);
            AddCommandToList(cmd);
        }
Beispiel #9
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, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
        {
            applicationObject = (_DTE)application;
            addInInstance     = (AddIn)addInInst;
            //if(connectMode == Extensibility.ext_ConnectMode.ext_cm_UISetup)
            {
                object []    contextGUIDS = new object[] { };
                Commands     commands     = applicationObject.Commands;
                _CommandBars commandBars  = applicationObject.CommandBars;

                // When run, the Add-in wizard prepared the registry for the Add-in.
                // At a later time, the Add-in or its commands may become unavailable for reasons such as:
                //   1) You moved this project to a computer other than which is was originally created on.
                //   2) You chose 'Yes' when presented with a message asking if you wish to remove the Add-in.
                //   3) You add new commands or modify commands already defined.
                // You will need to re-register the Add-in by building the SmellFinderSetup project,
                // right-clicking the project in the Solution Explorer, and then choosing install.
                // Alternatively, you could execute the ReCreateCommands.reg file the Add-in Wizard generated in
                // the project directory, or run 'devenv /setup' from a command prompt.
                try
                {
                    Command command = Find(commands);
                    if (command == null)
                    {
                        command = commands.AddNamedCommand(addInInstance, "SmellFinder", "SmellFinder", "Executes the command for SmellFinder", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled);
                        CommandBar        commandBar        = (CommandBar)commandBars["Tools"];
                        CommandBarControl commandBarControl = command.AddControl(commandBar, 1);
                    }
                }
                catch (System.Exception /*e*/)
                {
                }
            }
        }
Beispiel #10
0
 /// <summary>
 ///   Removes VCB toolbar and menu from Visual Studio.
 /// </summary>
 /// <param name="dte">
 ///   <c>DTE</c> object (VS environment) to remove from.
 /// </param>
 private static void DeleteBars(DTE dte)
 {
     try {
         CommandBar toolbar = ((CommandBars)dte.CommandBars)[Constants.CommandBarName];
         if (toolbar != null)
         {
             dte.Commands.RemoveCommandBar(toolbar);
         }
     }
     catch {
     }
     // remove menu main entry
     try {
         for (int i = ((CommandBars)dte.CommandBars).ActiveMenuBar.Controls.Count; i > 0; i--)
         {
             CommandBarControl cbc = (CommandBarControl)((CommandBars)dte.CommandBars).ActiveMenuBar.Controls[i].Control;
             if (cbc.Caption == Constants.MenuName)
             {
                 cbc.Delete(false);
                 break;
             }
         }
     }
     catch {
     }
 }
Beispiel #11
0
        /// <summary>
        /// 清除指定名称的项(删除可能VS崩溃没执行删除而残余的菜单)
        /// </summary>
        /// <param name="bar"></param>
        /// <param name="name"></param>
        private void ClearControl(Microsoft.VisualStudio.CommandBars.CommandBar bar, string name)
        {
            int trac = 0;
            CommandBarControl ctr = null;

            while (true)
            {
                trac++;
                if (trac >= 100)
                {
                    return;
                }
                try
                {
                    ctr = bar.Controls[name] as CommandBarControl;
                }
                catch { }
                if (ctr == null)
                {
                    return;
                }
                ctr.Delete(Type.Missing);
                ctr = null;
            }
        }
Beispiel #12
0
        public override void Run(dynamic declaration)
        {
            // note: does not work. http://stackoverflow.com/q/31954364/1188513
            //var app = Application.GetType();
            //app.InvokeMember(qualifiedMemberName.MemberName, BindingFlags.InvokeMethod | BindingFlags.Default, null, Application, null);
            //Application.Run(qualifiedMemberName.ToString());

            //note: this will work, but not implemented yet http://stackoverflow.com/questions/31954364#36889671
            //TaskItem taskitem = Application.CreateItem(OlItemType.olTaskItem);
            //taskitem.Subject = "Rubberduck";
            //taskitem.Body = qualifiedMemberName.MemberName;

            try
            {
                var               app = Application;
                var               exp = app.ActiveExplorer();
                CommandBar        cb  = exp.CommandBars.Add("RubberduckCallbackProxy", Temporary: true);
                CommandBarControl btn = cb.Controls.Add(MsoControlType.msoControlButton, 1);
                btn.OnAction = declaration.QualifiedName.ToString();
                btn.Execute();
                cb.Delete();
            }
            catch {
            }
        }
Beispiel #13
0
        // This method adds a button to the visual studio command bar.
        private void AddButton(CommandBar toolbar, String commandname, String captionname, int iconindex)
        {
            Command newCommand = null;

            try
            {
                newCommand = FindCommand(commandname);
            }
            catch (System.Exception)
            {
                newCommand = CreateCommand(commandname, captionname, iconindex);
            }

            //see if the button exists already, create it if it doesn't
            //this does have the intended effect!
            foreach (CommandBarControl c in toolbar.Controls)
            {
                if (c.Caption == captionname)
                {
                    return;
                }
            }

            //doesn't exist, create it
            CommandBarControl control = (CommandBarControl)newCommand.AddControl(toolbar, 1);
            CommandBarButton  button  = (CommandBarButton)control;

            button.Caption = captionname;
            button.Style   = MsoButtonStyle.msoButtonIcon;
        }
Beispiel #14
0
        /// <summary>
        /// Adds handler to the menu item click event.
        /// </summary>
        /// <param name="menuItem">The menu item.</param>
        private void AddClickEventHandler(CommandBarControl menuItem)
        {
            CommandBarEvents menuItemHandler = (EnvDTE.CommandBarEvents)application.DTE.Events.get_CommandBarEvents(menuItem);

            menuItemHandler.Click += new _dispCommandBarControlEvents_ClickEventHandler(MenuItem_Click);
            menuItemHandlerList.Add(menuItemHandler);
        }
Beispiel #15
0
 public static ICommandBarControlName GetName([CanBeNull] this CommandBarControl control)
 {
     return(control == null
         ? null
         : Names.CommandBarControl(
                control.Parent.GetIdentifier() + CommandBarControlName.HierarchySeperator + control.Caption));
 }
Beispiel #16
0
 public void DeleteOldGitExtMainMenuBar()
 {
     try
     {
         CommandBarControl control =
             GetMenuBar()
             .Controls.Cast <CommandBarControl>()
             .FirstOrDefault(c => c.Caption == OldGitMainMenuName);
         if (control != null)
         {
             control.Delete(false);
         }
         control =
             GetMenuBar()
             .Controls.Cast <CommandBarControl>()
             .FirstOrDefault(c => c.Caption == OldGitExtMainMenuName);
         if (control != null)
         {
             control.Delete(false);
         }
         CommandBar cb =
             CommandBars.Cast <CommandBar>()
             .FirstOrDefault(c => c.Name == OldGitMainMenuName);
         if (cb != null && !cb.BuiltIn)
         {
             cb.Delete();
         }
     }
     catch (Exception)
     {
     }
 }
Beispiel #17
0
        public static CommandBarControl GetAppHarborMenu(DTE2 applicationObject)
        {
            if (_appHarborMenu == null)
            {
                var menuBarCommandBar = ((CommandBars)applicationObject.CommandBars)["MenuBar"];
                const string toolsMenuName = "Tools";
                var toolsControl = menuBarCommandBar.Controls[toolsMenuName];

                _appHarborMenu = menuBarCommandBar.Controls.Add(MsoControlType.msoControlPopup, Id: 1234567890,
                                                               Before: toolsControl.Index + 1);
                _appHarborMenu.Caption = "AppHarbor";

                var popUp = (CommandBarPopup) _appHarborMenu;

                //New AppHarbor Application
                var newAppButton = (CommandBarButton) popUp.Controls.Add(MsoControlType.msoControlButton);
                newAppButton.Caption = "Create New AppHarbor Application";
                newAppButton.Click += EventHandler.NewApplication;

                //Manage Applications
                var manageApplications = (CommandBarButton) popUp.Controls.Add(MsoControlType.msoControlButton);
                manageApplications.Caption = "Manage Applications";
                manageApplications.Click += EventHandler.ManageApplications;

            }
            return _appHarborMenu;
        }
Beispiel #18
0
        public static void CreateLoginToolWindow(CommandBarControl cmdBarCtrl,
                                                 CommandBarButton cmdBarBtn, Assembly addIn_Assembly,
                                                 CommandBarControl cmdBarCtrlBackup, CommandBarControl dbCreateDemoDbControl)
        {
            try
            {
                m_AddIn_Assembly         = addIn_Assembly;
                m_cmdBarCtrlConnect      = cmdBarCtrl;
                m_cmdBarBtnConnect       = cmdBarBtn;
                m_cmdBarCtrlBackup       = cmdBarCtrlBackup;
                m_cmdBarCtrlCreateDemoDb = dbCreateDemoDbControl;

                loginToolWindow = CreateToolWindow(Common.Constants.CLASS_NAME_LOGIN, Common.Constants.LOGIN, NewFormattedGuid());

                if (loginToolWindow.AutoHides)
                {
                    loginToolWindow.AutoHides = false;
                }
                loginToolWindow.Visible            = true;
                loginToolWindow.Width              = 425;
                loginToolWindow.Height             = 170;
                Helper.CheckIfLoginWindowIsVisible = true;
            }
            catch (Exception oEx)
            {
                LoggingHelper.ShowMessage(oEx);
            }
        }
Beispiel #19
0
        private void AddContextMenue()
        {
            var builder = new MenuBuilder(_applicationObject, _addInInstance);

            builder.CreateMenuItem("Project and Solution Context Menus", "Solution", "Run Tests", "Runs all tests in solution", null, 1, "ContinuousTests_RunForSolution", false, 1);
            builder.CreateMenuItem("Project and Solution Context Menus", "Solution Folder", "Run Tests", "Runs all tests in projects", null, 1, "ContinuousTests_RunCodeModelTests", false, 1);
            builder.CreateMenuItem("Project and Solution Context Menus", "Project", "Run Tests", "Runs all tests in project", null, 1, "ContinuousTests_RunCodeModelTests", false, 1);
            builder.CreateMenuItem("Project and Solution Context Menus", "Cross Project Multi Solution Folder", "Run Tests", "Runs all tests in solution folders", null, 1, "ContinuousTests_RunCodeModelTests", false, 1);
            builder.CreateMenuItem("Project and Solution Context Menus", "Cross Project Multi Project", "Run Tests", "Runs all tests in projects", null, 1, "ContinuousTests_RunCodeModelTests", false, 1);
            builder.CreateMenuItem("Project and Solution Context Menus", "Item", "Run Tests", "Runs all tests in project item", null, 1, "ContinuousTests_RunCodeModelTests", false, 1);
            builder.CreateMenuItem("Project and Solution Context Menus", "Folder", "Run Tests", "Runs all tests in project item", null, 1, "ContinuousTests_RunCodeModelTests", false, 1);
            builder.CreateMenuItem("Project and Solution Context Menus", "Cross Project Multi Item", "Run Tests", "Runs all tests in project items", null, 1, "ContinuousTests_RunCodeModelTests", false, 1);
            builder.CreateMenuItem("Project and Solution Context Menus", "Cross Project Multi Project/Folder", "Run Tests", "Runs all tests in projects and solution folders", null, 1, "ContinuousTests_RunCodeModelTests", false, 1);
            builder.CreateMenuItem("Class View Context Menus", "Class View Project", "Run Tests", "Runs all tests in project", null, 1, "ContinuousTests_RunCodeModelTests", false, 1);
            builder.CreateMenuItem("Class View Context Menus", "Class View Item", "Run Tests", "Runs all tests in member", null, 1, "ContinuousTests_RunCodeModelTests", false, 1);
            builder.CreateMenuItem("Class View Context Menus", "Class View Folder", "Run Tests", "Runs all tests in folder", null, 1, "ContinuousTests_RunCodeModelTests", false, 1);
            builder.CreateMenuItem("Class View Context Menus", "Class View Multi-select", "Run Tests", "Runs all tests in members", null, 1, "ContinuousTests_RunCodeModelTests", false, 1);

            CommandBarControl ctl = builder.CreateMenuContainer("Editor Context Menus", "Code Window", "ContinuousTests", "ContinuousTests features", null, 1);

            builder.CreateSubMenuItem(ctl, "Run Test(s)", "Runs all tests in current scope", "Global::ctrl+shift+y,u", 1, "ContinuousTests_RunUnderCursor");
            builder.CreateSubMenuItem(ctl, "Run Related Tests", "Runs all tests related to the code under cursor", "Global::ctrl+shift+y,r", 2, "ContinuousTests_RunRelatedTests");
            builder.CreateSubMenuItem(ctl, "Rerun Last Manual Test Run", "Reruns last manual test run", "Global::ctrl+shift+y,e", 3, "ContinuousTests_RunLastOnDemandRun");
            builder.CreateSubMenuItem(ctl, "Debug Test", "Debug test", "Global::ctrl+shift+y,d", 4, "ContinuousTests_DebugCurrentTest", true, 0);
            builder.CreateSubMenuItem(ctl, "Rerun Last Debug Session", "Reruns last debug session", "Global::ctrl+shift+y,w", 5, "ContinuousTests_RunLastDebug");
            builder.CreateSubMenuItem(ctl, "Get Affected Graph", "Gets the affected graph for this item", "Global::ctrl+shift+y,g", 6, "ContinuousTests_GetAffectedCodeGraph", true, 0);
            builder.CreateSubMenuItem(ctl, "Get Profiled Graph", "Gets the profiled graph for this item", "Global::ctrl+shift+y,p", 7, "ContinuousTests_GetProfiledCodeGraph", true, 0);
            builder.CreateSubMenuItem(ctl, "Get Sequence Diagram", "Gets the sequence diagram of what this test does at runtime", "Global::ctrl+shift+y,s", 8, "ContinuousTests_GetSequenceDiagram", true, 0);
        }
Beispiel #20
0
        /// <summary>
        ///      Implements the OnStartupComplete method of the IDTExtensibility2 interface.
        ///      Receives notification that the host application has completed loading.
        /// </summary>
        /// <param term='custom'>
        ///      Array of parameters that are host application specific.
        /// </param>
        /// <seealso class='IDTExtensibility2' />
        public void OnStartupComplete(ref System.Array custom)
        {
            RemoveMenuItems();             // remove the old ones before we add...

            try
            {
                CommandBar        menuBar  = projectApp.CommandBars["Menu Bar"];
                CommandBarControl helpMenu = menuBar.Controls["&Help"];                 // put it before the Help item
                CommandBarPopup   popup    = (CommandBarPopup)menuBar.Controls.Add(10, Type.Missing, Type.Missing, helpMenu.Index, false);
                popup.Caption = "&RoundTable";

                bnBuildSched         = (CommandBarButton)popup.Controls.Add(MsoControlType.msoControlButton, Type.Missing, Type.Missing, Type.Missing, false);
                bnBuildSched.Caption = "&Build a Schedule from RoundTable";

                bnEditSettings         = (CommandBarButton)popup.Controls.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing, false);
                bnEditSettings.Caption = "&Edit Settings";

                bnAbout         = (CommandBarButton)popup.Controls.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing, false);
                bnAbout.Caption = "&About RoundTable Connected Services for Microsoft Project 2003";

                bnBuildSched.Click   += new _CommandBarButtonEvents_ClickEventHandler(bnBuildSched_Click);
                bnEditSettings.Click += new _CommandBarButtonEvents_ClickEventHandler(bnEditSettings_Click);
                bnAbout.Click        += new _CommandBarButtonEvents_ClickEventHandler(bnAbout_Click);

                //RoundTableSettings rtc = new RoundTableSettings();
                //rtc.load();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #21
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);
        }
Beispiel #22
0
        public void SynchronizeClassView()
        {
            CommandBars cmdBars          = (CommandBars)(Common.chDTE.DTE.CommandBars);
            CommandBar  vsBarProjectItem = cmdBars["Item"];

            menuItemPI = vsBarProjectItem.Controls.Add(MsoControlType.msoControlButton, 1, "", 2, true);
        }
Beispiel #23
0
        public void CreateSubMenuItem(CommandBarControl parent, string caption, string description, string bindings, int place, string commandName, bool hasSeparator, int icon)
        {
            try
            {
                var commands   = (Commands2)_application.Commands;
                var subMenuCtl = (CommandBarPopup)parent;
                var ctl        = getCommandBarControl(subMenuCtl.Controls, caption);
                if (ctl != null)
                {
                    ctl.BeginGroup = hasSeparator;
                    return;
                }
                Command command = getCommand(commands, commandName);
                if (command == null)
                {
                    command = commands.AddNamedCommand2(_addin, commandName, caption, description, false, icon, ref _contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported, (int)vsCommandStyle.vsCommandStylePictAndText);
                }
                command.AddControl(subMenuCtl.CommandBar, place);
                ctl            = getCommandBarControl(subMenuCtl.Controls, caption);
                ctl.BeginGroup = hasSeparator;

                if (bindings != null)
                {
                    command.Bindings = bindings;
                }
            }
            catch
            {
            }
        }
        private void onDisconnect()
        {
            if (m_socket != null)
            {
                m_socket.release();
                m_socket = null;
            }

            if (m_toolBarObj != null)
            {
                m_applicationObject.Commands.RemoveCommandBar(m_toolBarObj);
                m_toolBarObj = null;
            }


            int nCommand = m_commandList.Length;

            for (int ithCmd = 0; ithCmd < nCommand; ++ithCmd)
            {
                CommandObj cmdObj = m_commandList[ithCmd];
                if (cmdObj.command != null)
                {
                    //m_commandList[ithCmd].command.Bindings = "";
                    m_commandList[ithCmd].command.Delete();
                    m_commandList[ithCmd].command = null;
                }
            }

            if (m_menuBarObj != null)
            {
                m_menuBarObj.Delete();
                m_menuBarObj = null;
            }
        }
        private void CreateRibbonBar()
        {
            RibbonBar ribbonBar = axCommandBars.AddRibbonBar("DemoSoft Team Ribbon");

            ribbonBar.EnableDocking(XTPToolBarFlags.xtpFlagStretched);

            // 系统菜单
            CommandBarPopup popupSystem = ribbonBar.AddSystemButton();

            popupSystem.IconId = ResourceId.ID_SYSTEM_ICON;
            popupSystem.CommandBar.Controls.Add(XTPControlType.xtpControlButton, ResourceId.ID_CONFIG_STOCK, "配置程序(&O)", false, false);
            CommandBarControl controlSystem = popupSystem.CommandBar.Controls.Add(XTPControlType.xtpControlButton, ResourceId.ID_APP_HIDE, "退出(&E)", false, false);

            controlSystem.BeginGroup = true;
            popupSystem.CommandBar.SetIconSize(32, 32);

            // 关于菜单
            CommandBarControl controlAbout = ribbonBar.Controls.Add(XTPControlType.xtpControlButton, ResourceId.ID_APP_ABOUT, "关于(&A)", false, false);

            controlAbout.Flags = XTPControlFlags.xtpFlagRightAlign;

            // 主页
            RibbonTab primarySR = ribbonBar.InsertTab(0, "主页(&H)");

            primarySR.Id = ResourceId.ID_HOME;

            // 配置 -> 配置程序
            RibbonGroup       groupConfig      = primarySR.Groups.AddGroup("配置(&C)", ResourceId.ID_CONFIG_BUILD);
            CommandBarControl controlConfigApp = groupConfig.Add(XTPControlType.xtpControlButton, ResourceId.ID_CONFIG_STOCK, "配置程序(&O)", false, false);

            // 生成SR -> 创建SR报表
            RibbonGroup       groupPrimaryStockBuild     = primarySR.Groups.AddGroup("生成SR(&B)", ResourceId.ID_SR_BUILD);
            CommandBarControl controlBuildPrimaryReportS = groupPrimaryStockBuild.Add(XTPControlType.xtpControlSplitButtonPopup, ResourceId.ID_NEW_SR, "创建SR报表(&C)", false, false);

            controlBuildPrimaryReportS.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ResourceId.ID_LOAD_SR_FILE, "读取SR报表(&L)", false, false);
            controlBuildPrimaryReportS.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ResourceId.ID_LOAD_SR_CONFIG, "读取SR策略(&L)", false, false);

            // 视图
            RibbonTab tabView = ribbonBar.InsertTab(3, "视图(&V)");

            tabView.Id = ResourceId.ID_TAB_VIEW;

            // 视图 -> 报表
            RibbonGroup       groupShow        = tabView.Groups.AddGroup("报表(&D)", ResourceId.ID_GROUP_SHOW);
            CommandBarControl controlWorkspace = groupShow.Add(XTPControlType.xtpControlCheckBox, ResourceId.ID_SHOW_WORKSPACE, "工作区(&W)", false, false);

            groupShow.Add(XTPControlType.xtpControlCheckBox, ResourceId.ID_SHOW_STATUS, "状态栏(&S)", false, false);

            // 工具
            RibbonTab tabTools = ribbonBar.InsertTab(4, "工具(&T)");

            tabTools.Id = ResourceId.ID_TAB_TOOLS;

            // 工具 -> 内部工具
            RibbonGroup groupTools = tabTools.Groups.AddGroup("内部工具(&I)", ResourceId.ID_GROUP_TOOLS);

            // Welcome To DemoSoft Team
            ribbonBar.QuickAccessControls.Add(XTPControlType.xtpControlButton, ResourceId.ID_WELCOME, " Home ", false, false);
        }
Beispiel #26
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");
            }
        }
Beispiel #27
0
        private void FireCommandBarEvent(CommandBarControl control)
        {
            var commandEvent = Create <CommandEvent>();

            commandEvent.TriggeredBy = EventTrigger.Click;
            commandEvent.CommandId   = control.GetFullQualifiedId();
            Fire(commandEvent);
        }
Beispiel #28
0
        public void Attach(CommandBarControl ctrl, IMenuAction action)
        {
            var events = (CommandBarEvents)_applicationObject.Events.get_CommandBarEvents(ctrl);

            events.Click += new _dispCommandBarControlEvents_ClickEventHandler(events_Click);
            _events.Add(events);
            _actions[ctrl] = action;
        }
 public void RemoveCreatedControls()
 {
     for (int n = createdControls.Count - 1; n >= 0; n--)
     {
         CommandBarControl control = createdControls[n];
         control.Delete(true);
     }
     createdControls.Clear();
 }
Beispiel #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)
        {
            _applicationObject = (DTE2)application;
            _addInInstance     = (AddIn)addInInst;
            if (connectMode == ext_ConnectMode.ext_cm_UISetup)
            {
                object [] contextGUIDS = new object[] { };
                Commands2 commands     = (Commands2)_applicationObject.Commands;
                string    toolsMenuName;

                try
                {
                    //If you would like to move the command to a different menu, change the word "Tools" to the
                    //  English version of the menu. This code will take the culture, append on the name of the menu
                    //  then add the command to that menu. You can find a list of all the top-level menus in the file
                    //  CommandBar.resx.
                    ResourceManager resourceManager = new ResourceManager("AnAppADay.JediVSIRC.Addin.CommandBar", Assembly.GetExecutingAssembly());
                    CultureInfo     cultureInfo     = new System.Globalization.CultureInfo(_applicationObject.LocaleID);
                    string          resourceName    = String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools");
                    toolsMenuName = resourceManager.GetString(resourceName);
                }
                catch
                {
                    //We tried to find a localized version of the word Tools, but one was not found.
                    //  Default to the en-US word, which may work for the current culture.
                    toolsMenuName = "Tools";
                }

                //Place the command on the tools menu.
                //Find the MenuBar command bar, which is the top-level command bar holding all the main menu items:
                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[toolsMenuName];
                CommandBarPopup   toolsPopup   = (CommandBarPopup)toolsControl;

                //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
                {
                    //Add a command to the Commands collection:
                    Command command = commands.AddNamedCommand2(_addInInstance, "JediVSIRC", "Jedi Visual Studio IRC Window", "Opens the IRC window", 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) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                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.
                }
            }
        }
Beispiel #31
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;
                string    toolsMenuName = "Tools";

                //Place the command on the tools menu.
                //Find the MenuBar command bar, which is the top-level command bar holding all the main menu items:
                var        commandBars       = (CommandBars)_applicationObject.CommandBars;
                CommandBar menuBarCommandBar = commandBars["MenuBar"];

                //Find the Tools command bar on the MenuBar command bar:
                CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName];
                CommandBarPopup   toolsPopup   = (CommandBarPopup)toolsControl;

                //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
                {
                    //Add a command to the Commands collection:
                    Command command = commands.AddNamedCommand2(_addInInstance, "CiteCode", "CiteCode", "Executes the command for CiteCode", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    //Right click command
                    var contextMenuCommandBar = (CommandBar)commandBars["Editor Context Menus"];

                    var editPopUp = (CommandBarPopup)contextMenuCommandBar.Controls["Code Window"];
                    //var editorMenuCommandBarControl = contextMenuCommandBar.Controls["Code Window"];

                    command.AddControl(editPopUp.CommandBar, 1);
                    //Command citeCommand = commands.AddNamedCommand2(_addInInstance, "CiteCommand", "Cite", "Executes the command for CiteCode", true, 59, ref contextGUIDS,
                    //(int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                    //(int)vsCommandStyle.vsCommandStylePictAndText,
                    //vsCommandControlType.vsCommandControlTypeButton);
                    //citeCommand.AddControl(editorMenuCommandBarControl);
                    //(((_applicationObject.CommandBars as CommandBars)["Editor Context Menus"]) as CommandBar).Controls["Code Window"] as CommandBarControl
                    //Command rightClickCommand



                    //Add a control for the command to the tools menu:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                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.
                }
            }
        }
Beispiel #32
0
        private int AddSubMenu(out CommandBarControl menuItem, CommandBarPopup parent, out CommandBarEvents eventHandler, int position, string caption, string imagePath, string maskedImagePath)
        {
            menuItem         = parent.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, position, true);
            menuItem.Caption = caption;

            eventHandler = (CommandBarEvents)_applicationObject.Events.get_CommandBarEvents(menuItem);

            return(position + 1);
        }
        internal static CommandBarControlNodeFactory Create(CommandBarControl control)
        {
            if (control is CommandBarPopup)
            {
                return new CommandBarPopupNodeFactory(control as CommandBarPopup);
            }
            if (control is CommandBarComboBox)
            {
                return new CommandBarComboBoxNodeFactory(control as CommandBarComboBox);
            }
            if (control is CommandBarButton)
            {
                return new CommandBarButtonNodeFactory(control as CommandBarButton);
            }

            return null;
        }
Beispiel #34
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)
        {
            _application = (DTE2)application;
            _addInInstance = (AddIn)addInInst;

            _contextMenu = ((CommandBars)_application.CommandBars)["Code Window"];
            _encoderizer = (CommandBarPopup)_contextMenu.Controls.Add(MsoControlType.msoControlPopup, Missing.Value, Missing.Value, 1, true);
            _encoderizer.Caption = "VS Encoderizer";

            _javascriptStringEncode = _encoderizer.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, 1, true);
            _javascriptStringEncode.Caption = "Javascript String Encode";
            _javascriptStringEncodeEvents = (CommandBarEvents)_application.Events.CommandBarEvents[_javascriptStringEncode];
            _javascriptStringEncodeEvents.Click += JavaScriptStringEncode;

            _urlPathEncode = _encoderizer.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, 1, true);
            _urlPathEncode.Caption = "Url Path Encode";
            _urlPathEncodeEvents = (CommandBarEvents)_application.Events.CommandBarEvents[_urlPathEncode];
            _urlPathEncodeEvents.Click += UrlPathEncode;

            _urlDecode = _encoderizer.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, 1, true);
            _urlDecode.Caption = "Url Decode";
            _urlDecodeEvents = (CommandBarEvents)_application.Events.CommandBarEvents[_urlDecode];
            _urlDecodeEvents.Click += UrlDecode;

            _urlEncode = _encoderizer.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, 1, true);
            _urlEncode.Caption = "Url Encode";
            _urlEncodeEvents = (CommandBarEvents)_application.Events.CommandBarEvents[_urlEncode];
            _urlEncodeEvents.Click += UrlEncode;

            _htmlAttributeEncode = _encoderizer.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, 1, true);
            _htmlAttributeEncode.Caption = "Html Attribute Encode";
            _htmlAttributeEncodeEvents = (CommandBarEvents)_application.Events.CommandBarEvents[_htmlAttributeEncode];
            _htmlAttributeEncodeEvents.Click += HtmlAttributeEncode;

            _htmlDecode = _encoderizer.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, 1, true);
            _htmlDecode.Caption = "Html Decode";
            _htmlDecodeEvents = (CommandBarEvents)_application.Events.CommandBarEvents[_htmlDecode];
            _htmlDecodeEvents.Click += HtmlDecode;

            _htmlEncode = _encoderizer.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, 1, true);
            _htmlEncode.Caption = "Html Encode";
            _htmlEncodeEvents = (CommandBarEvents)_application.Events.CommandBarEvents[_htmlEncode];
            _htmlEncodeEvents.Click += HtmlEncode;
        }
Beispiel #35
0
 private static void ApplyControlAttribute(CommandBarControl control, string attribute, string value, GetImageDelegate getImage)
 {
     switch (attribute)
     {
         case "caption":
             control.Caption = value;
             break;
         case "height":
             int height;
             if (int.TryParse(value, out height))
             {
                 control.Height = height;
             }
             else
             {
                 Debug.Print("Could not parse 'height' attribute: {0}", value);
             }
             break;
         case "onAction":
             control.OnAction = value;
             break;
         case "enabled":
             bool enabled;
             if (bool.TryParse(value, out enabled))
             {
                 control.Enabled = enabled;
             }
             else
             {
                 Debug.Print("Could not parse 'enabled' attribute: {0}", value);
             }
             break;
         case "beginGroup":
             bool beginGroup;
             if (bool.TryParse(value, out beginGroup))
             {
                 control.BeginGroup = beginGroup;
             }
             else
             {
                 Debug.Print("Could not parse 'beginGroup' attribute: {0}", value);
             }
             break;
         case "helpFile":
             control.HelpFile = value;
             break;
         case "helpContextId":
             int helpContextId;
             if (int.TryParse(value, out helpContextId))
             {
                 control.HelpContextId = helpContextId;
             }
             else
             {
                 Debug.Print("Could not parse 'helpContextId' attribute: {0}", value);
             }
             break;
         case "tag":
             control.Tag = value;
             break;
         case "tooltipText":
             control.TooltipText = value;
             break;
         case "shortcutText":
             if (control is CommandBarButton)
             {
                 (control as CommandBarButton).ShortcutText = value;
             }
             else
             {
                 Debug.Print("shortcutText only supported on Buttons");
             }
             break;
         case "faceId":
             if (control is CommandBarButton)
             {
                 int faceId;
                 if (int.TryParse(value, out faceId))
                 {
                     (control as CommandBarButton).FaceId = faceId;
                 }
                 else
                 {
                     Debug.Print("Could not parse 'faceId' attribute: {0}", value);
                 }
             }
             else
             {
                 Debug.Print("faceId only supported on Buttons");
             }
             break;
         case "image":
             if (control is CommandBarButton)
             {
                 Bitmap image = getImage(value);
                 if (image != null)
                 {
                     (control as CommandBarButton).SetButtonImage(image);
                 }
                 else
                 {
                     Debug.Print("Could not find or load image {0}", value);
                 }
             }
             else
             {
                 Debug.Print("image only supported on Buttons");
             }
             break;
         case "style":
         case "MsoButtonStyle":  // Compatible with original style code.
             if (control is CommandBarButton)
             {
                 if (Enum.IsDefined(typeof(MsoButtonStyle), value))
                     (control as CommandBarButton).Style = (MsoButtonStyle)Enum.Parse(typeof(MsoButtonStyle), value, false);
                 else
                     (control as CommandBarButton).Style = MsoButtonStyle.msoButtonAutomatic;
             }
             else
             {
                 Debug.Print("style only supported on Buttons");
             }
             break;
         default:
             Debug.Print("Unknown attribute '{0}' - ignoring.", attribute);
             break;
     }
 }
Beispiel #36
0
 private static void ApplyControlAttributes(CommandBarControl control, XmlNode xmlNode, GetImageDelegate getImage)
 {
     foreach (XmlAttribute att in xmlNode.Attributes)
     {
         ApplyControlAttribute(control, att.Name, att.Value, getImage);
     }
 }
 protected CommandBarControlNodeFactory(CommandBarControl control, bool isContainer)
 {
     _control = control;
     _isContainer = isContainer;
 }
Beispiel #38
0
 public void CleanupOldSubMenuItemByDeletion(CommandBarControl parent, string caption)
 {
     try
     {
         var commands = (Commands2)_application.Commands;
         var subMenuCtl = (CommandBarPopup)parent;
         var ctl = getCommandBarControl(subMenuCtl.Controls, caption);
         if (ctl != null)
             subMenuCtl.Controls[caption].Delete();
     }
     catch
     {
     }
 }
Beispiel #39
0
        public void CreateSubMenuItem(CommandBarControl parent, string caption, string description, string bindings, int place, string commandName, bool hasSeparator, int icon)
        {
            try
            {
                var commands = (Commands2)_application.Commands;
                var subMenuCtl = (CommandBarPopup)parent;
                var ctl = getCommandBarControl(subMenuCtl.Controls, caption);
                if (ctl != null)
                {
                    ctl.BeginGroup = hasSeparator;
                    return;
                }
                Command command = getCommand(commands, commandName);
                if (command == null)
                    command = commands.AddNamedCommand2(_addin, commandName, caption, description, false, icon, ref _contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported, (int)vsCommandStyle.vsCommandStylePictAndText);
                command.AddControl(subMenuCtl.CommandBar, place);
                ctl = getCommandBarControl(subMenuCtl.Controls, caption);
                ctl.BeginGroup = hasSeparator;

                if (bindings != null)
                    command.Bindings = bindings;
            }
            catch
            {
            }
        }
Beispiel #40
0
 public void CreateSubMenuItem(CommandBarControl parent, string caption, string description, string bindings, int place, string commandName)
 {
     CreateSubMenuItem(parent, caption, description, bindings, place, commandName, false, 0);
 }
Beispiel #41
0
 public void UnregisterUI()
 {
     _uiControl.Delete();
     _uiControl = null;
 }
Beispiel #42
0
 public void RegisterUI(CommandBar menu, int index = 1, bool isFirstInGroup = false)
 {
     List<CommandBarControl> toRemove = new List<CommandBarControl>();
     foreach(CommandBarControl control in menu.Controls)
     {
         int commandId;
         string commandGroup;
         UICommands.DTE.Commands.CommandInfo(control, out commandGroup, out commandId);
         if (new Guid(commandGroup) == CommandGroupGuid && commandId == CommandId)
             toRemove.Add(control);
     }
     foreach(var value in toRemove)
         value.Delete();
     var dteCommand = UICommands.DTE.Commands.Named(CanonicalName);
     _uiControl = (CommandBarControl)dteCommand.AddControl(menu, index);
     _uiControl.BeginGroup = isFirstInGroup;
 }
Beispiel #43
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)
        {
            _application = (DTE2)application;
            _addInInstance = (AddIn)addInInst;

            var commandBar = ((CommandBars)_application.CommandBars)["Code Window"];
            var commandBarPopup = (CommandBarPopup)commandBar.Controls.Add(MsoControlType.msoControlPopup, Missing.Value, Missing.Value, 1, true);
            commandBarPopup.Caption = "RegExerciser";

            _searchWithRegex = commandBarPopup.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, 1, true);
            _searchWithRegex.Caption = "Search With Regular Expression";
            _searchWithRegexEvents = (CommandBarEvents)_application.Events.CommandBarEvents[_searchWithRegex];
            _searchWithRegexEvents.Click += SearchWithRegex;

            _testRegex = commandBarPopup.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, 1, true);
            _testRegex.Caption = "Test Regular Expression";
            _testRegexEvents = (CommandBarEvents)_application.Events.CommandBarEvents[_testRegex];
            _testRegexEvents.Click += TestRegex;
        }