Esempio n. 1
0
        /// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary>
        /// <param term='application'>Root object of the host application.</param>
        /// <param term='connectMode'>Describes how the Add-in is being loaded.</param>
        /// <param term='addInInst'>Object representing this Add-in.</param>
        /// <seealso class='IDTExtensibility2' />
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            _applicationObject = (DTE2)application;
            _addInInstance     = (AddIn)addInInst;
            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:
                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, "AddinTest", "AddinTest", "Executes the command for AddinTest", 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.
                }
            }
        }
Esempio n. 2
0
        private CommandBarPopup GetMainMenuPopup(string targetMenuEnglishName)
        {
            //template-generated code to find the localized name of the target menu
            string toolsMenuName;

            try
            {
                string          resourceName;
                ResourceManager resourceManager = new ResourceManager(typeof(AddinConnector).Namespace + ".CommandBar", Assembly.GetExecutingAssembly());
                CultureInfo     cultureInfo     = new CultureInfo(_applicationObject.LocaleID);

                if (cultureInfo.TwoLetterISOLanguageName == "zh")
                {
                    System.Globalization.CultureInfo parentCultureInfo = cultureInfo.Parent;
                    resourceName = String.Concat(parentCultureInfo.Name, targetMenuEnglishName);
                }
                else
                {
                    resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, targetMenuEnglishName);
                }
                toolsMenuName = resourceManager.GetString(resourceName);
            }
            catch
            {
                //none found, use english as default.
                toolsMenuName = targetMenuEnglishName;
            }

            //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;

            return(toolsPopup);
        }
Esempio n. 3
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;

                //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)["Standard"];

                const int Position = 16;
                // Match Case Command
                try
                {
                    //Add a command to the Commands collection:
                    Command matchCaseCommand = commands.AddNamedCommand2(_addInInstance, "MatchCase", "Match Case Find Option", "Toggles the Match Case Find option", false, 1001, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePict, vsCommandControlType.vsCommandControlTypeButton);

                    if ((matchCaseCommand != null) && (menuBarCommandBar != null))
                    {
                        matchCaseCommand.AddControl(menuBarCommandBar, Position);
                    }
                }
                catch (System.ArgumentException) { }

                //Match Whole Word Command
                try
                {
                    Command matchWholeWordCommand = commands.AddNamedCommand2(_addInInstance, "MatchWholeWord", "Match Whole Word Find Option", "Toggles the Whole Word Find Option", false, 1002, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePict, vsCommandControlType.vsCommandControlTypeButton);
                    if ((matchWholeWordCommand != null) && (menuBarCommandBar != null))
                    {
                        matchWholeWordCommand.AddControl(menuBarCommandBar, Position + 1);
                    }
                }
                catch (System.ArgumentException) { }
            }
        }
Esempio n. 4
0
 public void create_popup_menu(string host_menu_bar_name, string new_bar_name, string tooltip_text, int position)
 {
     BARS.CommandBar new_bar = null;
     // check existing
     try
     {
         // VSI.ServiceCache.ExtensibilityModel.Commands was NULL
         // new_bar = (BARS.CommandBar)((BARS.CommandBars)VSI.ServiceCache.ExtensibilityModel.CommandBars)[new_bar_name];
         new_bar =
             (BARS.CommandBar)((BARS.CommandBars)_ssms.DTE2.CommandBars)[new_bar_name];
         new_bar.Delete();
         new_bar = null;
     }
     catch
     {
     }
     // VSI.ServiceCache.ExtensibilityModel.Commands was NULL
     // BARS.CommandBar host_bar = ((BARS.CommandBars)VSI.ServiceCache.ExtensibilityModel.CommandBars)[host_menu_bar_name];
     BARS.CommandBar host_bar = ((BARS.CommandBars)_ssms.DTE2.CommandBars)[host_menu_bar_name];
     position = (position == 0 ? host_bar.Controls.Count + 1 : position);
     new_bar  = (BARS.CommandBar)_SSMS_commands_collection.AddCommandBar(new_bar_name, vsCommandBarType.vsCommandBarTypeMenu, host_bar, position);
     _addin_command_bars.Add(new_bar);
 }
Esempio n. 5
0
        private void SetupToolsMenuAction()
        {
            try
            {
                object[]  contextGUIDS  = new object[] { };
                Commands2 commands      = (Commands2)_applicationObject.Commands;
                string    toolsMenuName = "Tools";

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

                CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName];
                CommandBarPopup   toolsPopup   = (CommandBarPopup)toolsControl;

                string  name    = "Cyclomatic Complexity";
                Command command =
                    commands.AddNamedCommand2(_addInInstance, "ccm", name, name,
                                              true, 0, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                command.AddControl(toolsPopup.CommandBar, 1);
            }
            catch (ArgumentException)
            {
            }
        }
Esempio n. 6
0
        public void create_popup_menu_and_context_menu_command(
            string host_menu_bar_name,
            string command_name,
            string item_text,
            string tooltip_text,
            int position,
            menu_command_querystatus_handler querystatus_handler,
            menu_command_exec_handler exec_handler,
            string keyBindings = null
            )
        {
            object[] contextGUIDS      = new object[] { };
            string   context_menu_name = "SQL Files Editor Context";

            BARS.CommandBar host_bar     = ((BARS.CommandBars)_ssms.DTE2.CommandBars)[host_menu_bar_name];
            BARS.CommandBar context_menu = ((BARS.CommandBars)_ssms.DTE2.CommandBars)[context_menu_name];

            Command new_command = _SSMS_commands_collection.AddNamedCommand2(_ssms.addin, command_name, item_text, tooltip_text, true, 0, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStyleText, vsCommandControlType.vsCommandControlTypeButton);

            if (new_command == null)
            {
                throw new Exception("SSMSW08 could not create command bar: " + item_text);
            }
            position = (position == 0 ? host_bar.Controls.Count + 1 : position);
            new_command.AddControl(host_bar, position);
            new_command.AddControl(context_menu, context_menu.Controls.Count + 1);
            if (keyBindings != null)
            {
                new_command.Bindings = keyBindings;
            }
            menu_command_handlers handlers = new menu_command_handlers();

            handlers.querystatus_handler = querystatus_handler == null ? this._default_querystatus_handler : querystatus_handler;
            handlers.exec_handler        = exec_handler == null ? this._default_exec_handler : exec_handler;
            this._addin_menu_commands_dictonary.Add(_ssms.addin.ProgID + "." + command_name, handlers);
        }
        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;
                Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)applicationObject.CommandBars)["MenuBar"];
                CommandBarControl toolsControl = menuBarCommandBar.Controls["Tools"];
                CommandBarPopup   toolsPopup   = (CommandBarPopup)toolsControl;

                try
                {
                    Command command = commands.AddNamedCommand2(addInInstance, "AutoAttachAddin", "Auto Attach", "Attach to remote process", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException) { }
            }
        }
Esempio n. 8
0
        /// <summary>实现 IDTExtensibility2 接口的 OnConnection 方法。接收正在加载外接程序的通知。</summary>
        /// <param term='application'>宿主应用程序的根对象。</param>
        /// <param term='connectMode'>描述外接程序的加载方式。</param>
        /// <param term='addInInst'>表示此外接程序的对象。</param>
        /// <seealso class='IDTExtensibility2' />
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            _app   = (DTE2)application;
            _addIn = (AddIn)addInInst;

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

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

                CommandBarControl cmdCtr = this.GetExistCommandBarControl(menuBarCommandBar, "李仙伟");
                if (cmdCtr != null)
                {
                    cmdCtr.Visible = true;
                    return;
                }
                CommandBarControl myToolsControl = menuBarCommandBar.Controls.Add(MsoControlType.msoControlPopup, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
                myToolsControl.Caption = "李仙伟";

                CommandBarPopup toolsPopup = (CommandBarPopup)myToolsControl;

                //如果希望添加多个由您的外接程序处理的命令,可以重复此 try/catch 块,
                //  只需确保更新 QueryStatus/Exec 方法,使其包含新的命令名。
                try
                {
                    //将一个命令添加到 Commands 集合:
                    Command command = this.GetExistCommand(commands, "PlatformSetting");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "PlatformSetting", "目标平台设置(&P)", "批量修改目标平台", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    //将对应于该命令的控件添加到“李仙伟”菜单:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException)
                {
                    //如果出现此异常,原因很可能是由于具有该名称的命令
                    //  已存在。如果确实如此,则无需重新创建此命令,并且
                    //  可以放心忽略此异常。
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "OutPathSetting");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "OutPathSetting", "输出路径设置(&O)", "批量修改输出路径设置", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 2);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "BuildEventSetting");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "BuildEventSetting", "生成事件设置(&E)", "批量修改生成事件", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 3);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "NetFrameweorkSetting");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "NetFrameweorkSetting", ".NET版本设置(&N)", "批量修改.NET版本", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 4);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "CollapseAll");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "CollapseAll", "折叠所有项目(&C)", "折叠所有项目", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 5);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "ExpandAll");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "ExpandAll", "展开所有项目(&X)", "展开所有项目", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 6);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "MultiLoadProjects");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "MultiLoadProjects", "批量加载项目", "批量加载项目", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 7);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "MultiCreateProjects");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "MultiCreateProjects", "批量创建项目", "批量创建项目", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 8);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "DllRefConfig");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "DllRefConfig", "修改项目dll引用", "修改项目dll引用", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 9);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "DllRefFileCopy");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "DllRefFileCopy", "拷贝dll的引用(依赖项)", "拷贝dll的引用(依赖项)", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 10);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "Dll2Lib");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "Dll2Lib", "更新dll到Lib", "更新dll到Lib", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 11);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "SQLCreator");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "SQLCreator", "SQL语句生成器", "SQL语句生成器", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 12);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "GuidCreator");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "GuidCreator", "Guid生成器", "Guid生成器", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 13);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "CheckRepeatDll");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "CheckRepeatDll", "检查Lib库重复的dll", "检查Lib库重复的dll", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 14);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "Selection2Upper");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "Selection2Upper", "Selection2Upper", "Selection2Upper", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 15);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "AboutMe");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "AboutMe", "关于(&A)", "关于", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 16);
                    }
                }
                catch (System.ArgumentException)
                {
                }
            }

            //清理临时文件
            DllRefReflectUtility.ClearTempFiles();
        }
Esempio n. 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, 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.
                    string          resourceName;
                    ResourceManager resourceManager = new ResourceManager("Randoop.CommandBar", Assembly.GetExecutingAssembly());
                    CultureInfo     cultureInfo     = new CultureInfo(_applicationObject.LocaleID);

                    if (cultureInfo.TwoLetterISOLanguageName == "zh")
                    {
                        System.Globalization.CultureInfo parentCultureInfo = cultureInfo.Parent;
                        resourceName = String.Concat(parentCultureInfo.Name, "Tools");
                    }
                    else
                    {
                        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, "Randoop", "Randoop...", "Executes the command for Randoop", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported+(int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    Command command = commands.AddNamedCommand2(_addInInstance, "Randoop", "Randoop...", "Executes the command for Randoop", true, 1, 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.
                }


                //TODO: right click to activate (p2)
                //_menuManager = new MenuManager(_applicationObject);
                //Dictionary<string, CommandBase> cmds = new Dictionary<string, CommandBase>();
                //CommandBase randoopCommand = new RandoopCommand(_applicationObject);
                //cmds.Add("RandoopCommand", randoopCommand);
                //CommandBarPopup popupMenu = _menuManager.CreatePopupMenu("Assembly", _rm.GetString("RandoopMenuCaption"));
                //AddCommandMenu(popupMenu, cmds["RandoopCommand"], 1);

                #region post-randoop-functions
                //{
                //    //// Add a popup control to group our buttons under --- add submenu (new on Sep. 2012)

                //    _cmdBarPopup = (CommandBarPopup)toolsPopup.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, 2, true);
                //    _cmdBarPopup.Caption = "post Randoop";


                //    _btnReduce = (CommandBarButton)_cmdBarPopup.Controls.Add(MsoControlType.msoControlButton, Type.Missing,
                //        Type.Missing, Type.Missing, true);
                //    _btnReduce.Style = MsoButtonStyle.msoButtonIconAndCaption;
                //    _btnReduce.Caption = "Reducer";
                //    _btnReduce.TooltipText = "This command removes tests that it considers redundant";
                //    ////_btnFreebie.Picture = ImageConverter.ImageToIPicture(Resources.Resource.BarCode);
                //    _btnReduce.Click += new _CommandBarButtonEvents_ClickEventHandler(_btnReduce_Click);

                //    _btnMinimize = (CommandBarButton)_cmdBarPopup.Controls.Add(MsoControlType.msoControlButton, Type.Missing,
                //        Type.Missing, Type.Missing, true);
                //    _btnMinimize.Caption = "Minimizer";
                //    _btnMinimize.TooltipText = "This command transforms each test into a smaller one that still exhibits the same exception";
                //    //_btnLicensed.FaceId = 1845;
                //    _btnMinimize.Click += new _CommandBarButtonEvents_ClickEventHandler(_btnMinimize_Click);

                //    _btnToMSTest = (CommandBarButton)_cmdBarPopup.Controls.Add(MsoControlType.msoControlButton, Type.Missing,
                //        Type.Missing, Type.Missing, true);
                //    _btnToMSTest.Style = MsoButtonStyle.msoButtonIconAndCaption;
                //    _btnToMSTest.Caption = "Converter to MSTest";
                //    _btnToMSTest.Click += new _CommandBarButtonEvents_ClickEventHandler(_btnMSTest_Click);
                //}
                #endregion post-randoop-functions
            }
        }
Esempio n. 10
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 Array custom)
        {
            var contextGUIDS = new object[] { };
            var commands     = (Commands2)_applicationObject.Commands;
            var _commandBars =
                ((CommandBars)_applicationObject.CommandBars);

            // add a top-level menu to stick some global options in
            {
                Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar =
                    ((CommandBars)_applicationObject.CommandBars)["MenuBar"];

                int nenhancerPopupIndex = menuBarCommandBar.Controls.Count + 1;
                var clangMenuRoot       = menuBarCommandBar.Controls.Add(
                    MsoControlType.msoControlPopup,
                    Type.Missing,
                    Type.Missing,
                    nenhancerPopupIndex,
                    true) as CommandBarPopup;
                clangMenuRoot.Caption = "Clang";

                // open the settings dialog
                {
                    _dteHelper.AddNamedCommand2(
                        COMMAND_CLANG_SETTINGS_DLG,
                        "Settings...",
                        "Settings...",
                        false,
                        0);
                    Command commandToAdd =
                        _applicationObject.Commands.Item(GetCommandFullName(COMMAND_CLANG_SETTINGS_DLG), 0);
                    SettingsButton =
                        commandToAdd.AddControl(clangMenuRoot.CommandBar, clangMenuRoot.CommandBar.Controls.Count + 1)
                        as CommandBarButton;
                }

                // get active vcproj, rebuild it with Clang
                {
                    _dteHelper.AddNamedCommand2(
                        COMMAND_CLANG_REBUILD_ACTIVE,
                        "Rebuild Active Project",
                        "Rebuild Active Project",
                        false,
                        0);
                    Command commandToAdd =
                        _applicationObject.Commands.Item(GetCommandFullName(COMMAND_CLANG_REBUILD_ACTIVE), 0);
                    RebuildActiveProjectButton =
                        commandToAdd.AddControl(clangMenuRoot.CommandBar, clangMenuRoot.CommandBar.Controls.Count + 1)
                        as CommandBarButton;
                }
                {
                    _dteHelper.AddNamedCommand2(
                        COMMAND_CLANG_RELINK_ACTIVE,
                        "Relink",
                        "Relink",
                        false,
                        0);
                    Command commandToAdd =
                        _applicationObject.Commands.Item(GetCommandFullName(COMMAND_CLANG_RELINK_ACTIVE), 0);
                    RelinkButton =
                        commandToAdd.AddControl(clangMenuRoot.CommandBar, clangMenuRoot.CommandBar.Controls.Count + 1)
                        as CommandBarButton;
                }
                {
                    _dteHelper.AddNamedCommand2(
                        COMMAND_CLANG_CANCEL_BUILD,
                        "Cancel Build",
                        "Cancel Build",
                        false,
                        0);
                    Command commandToAdd =
                        _applicationObject.Commands.Item(GetCommandFullName(COMMAND_CLANG_CANCEL_BUILD), 0);
                    CancelBuildButton =
                        commandToAdd.AddControl(clangMenuRoot.CommandBar, clangMenuRoot.CommandBar.Controls.Count + 1)
                        as CommandBarButton;
                }
            }
            // add a compile-this-file option to the editor window
            {
                Microsoft.VisualStudio.CommandBars.CommandBar codeWinCommandBar =
                    _dteHelper.GetCommandBarByName("Code Window");

                int pmPopupIndex = codeWinCommandBar.Controls.Count + 1;
                var pmPopup      = codeWinCommandBar.Controls.Add(
                    MsoControlType.msoControlPopup,
                    Type.Missing,
                    Type.Missing,
                    pmPopupIndex,
                    true) as CommandBarPopup;
                pmPopup.Caption = "Clang Compiler";

                CommandBarButton saveAndCompileCmd = _dteHelper.AddButtonToPopup(
                    pmPopup,
                    pmPopup.Controls.Count + 1,
                    "Compile",
                    "Compile");
                CompileCmdEvent        = _applicationObject.Events.get_CommandBarEvents(saveAndCompileCmd) as CommandBarEvents;
                CompileCmdEvent.Click += cvxCompileFile_menuop;

                CommandBarButton saveAndAnalyseCmd = _dteHelper.AddButtonToPopup(
                    pmPopup,
                    pmPopup.Controls.Count + 1,
                    "Run Static Analysis",
                    "Run Static Analysis");
                AnalyseCmdEvent        = _applicationObject.Events.get_CommandBarEvents(saveAndAnalyseCmd) as CommandBarEvents;
                AnalyseCmdEvent.Click += cvxAnalyseFile_menuop;

                CommandBarButton saveAndDasmCmd = _dteHelper.AddButtonToPopup(
                    pmPopup,
                    pmPopup.Controls.Count + 1,
                    "View Disassembly (LLVM)",
                    "View Disassembly (LLVM)");
                DasmCmdEvent        = _applicationObject.Events.get_CommandBarEvents(saveAndDasmCmd) as CommandBarEvents;
                DasmCmdEvent.Click += cvxDasmnFile_menuop;

                CommandBarButton dasmAndPreproCmd = _dteHelper.AddButtonToPopup(
                    pmPopup,
                    pmPopup.Controls.Count + 1,
                    "View Preprocessor Result",
                    "View Preprocessor Result");
                PreproCmdEvent        = _applicationObject.Events.get_CommandBarEvents(dasmAndPreproCmd) as CommandBarEvents;
                PreproCmdEvent.Click += cvxPreProFile_menuop;
            }
        }
Esempio n. 11
0
        /// <summary>实现 IDTExtensibility2 接口的 OnConnection 方法。接收正在加载外接程序的通知。</summary>
        /// <param term='application'>宿主应用程序的根对象。</param>
        /// <param term='connectMode'>描述外接程序的加载方式。</param>
        /// <param term='addInInst'>表示此外接程序的对象。</param>
        /// <seealso class='IDTExtensibility2' />
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            _applicationObject = (DTE2)application;
            _addInInstance     = (AddIn)addInInst;

            OutputWindow outputWindow = (OutputWindow)_applicationObject.Windows.Item(Constants.vsWindowKindOutput).Object;

            bool bbuildok = true;

            try
            {
                m_OutputWindowPane = outputWindow.OutputWindowPanes.Item("生成");
            }
            catch
            {
                //我们试图查找“工具”一词的本地化版本,但未能找到。
                //  默认值为 en-US 单词,该值可能适用于当前区域性。
                bbuildok = false;
            }

            if (!bbuildok)
            {
                try
                {
                    m_OutputWindowPane = outputWindow.OutputWindowPanes.Item("Build");
                }
                catch
                {
                    //我们试图查找“工具”一词的本地化版本,但未能找到。
                    //  默认值为 en-US 单词,该值可能适用于当前区域性。
                    bbuildok = false;
                }
            }


            // Register for the various build events taht we're hooking in to
            EnvDTE.Events events = _applicationObject.Events;
            m_BuildEvents = (EnvDTE.BuildEvents)events.BuildEvents;
            m_BuildEvents.OnBuildProjConfigBegin += new _dispBuildEvents_OnBuildProjConfigBeginEventHandler(OnBuildProjConfigBegin);
            m_BuildEvents.OnBuildProjConfigDone  += new _dispBuildEvents_OnBuildProjConfigDoneEventHandler(OnBuildProjConfigDone);
            m_BuildEvents.OnBuildBegin           += new _dispBuildEvents_OnBuildBeginEventHandler(this.OnBuildBegin);
            m_BuildEvents.OnBuildDone            += new _dispBuildEvents_OnBuildDoneEventHandler(this.OnBuildDone);

            m_envcfgs = new ThkEnvCfgs();
            if (m_envcfgs.LoadConfig())
            {
                ThkEnvConfig enc = m_envcfgs.GetCurEnvConfig();
                if (enc != null)
                {
                    //if (m_OutputWindowPane != null)
                    //{
                    //    m_OutputWindowPane.OutputString("现在开始自动设置配置信息中的环境变量\n");
                    //}

                    ThkEnvCfgItem[] encitems = enc.EnvConfigItems;
                    foreach (ThkEnvCfgItem ci in encitems)
                    {
                        if (ci.EnvCfgFlatform == null || ci.EnvCfgFlatform.Length == 0 || ci.EnvCfgFlatform == "全部" || ci.EnvCfgFlatform == "")
                        {
                            Environment.SetEnvironmentVariable(ci.EnvCfgItem, ci.EnvCfgValue, EnvironmentVariableTarget.Process);
                            //if (m_OutputWindowPane !=null)
                            //{
                            //    m_OutputWindowPane.OutputString(ci.EnvCfgItem + ":" + ci.EnvCfgValue+"\n");
                            //}
                        }
                    }
                }
                else
                {
                    MessageBox.Show("获取配置中的环境变量信息失败");
                }
            }
            else
            {
                MessageBox.Show("加载配置变量配置文件失败");
            }
            {
                string   path       = System.Environment.CurrentDirectory;
                Assembly myAssembly = Assembly.GetEntryAssembly();
                if (myAssembly == null)
                {
                    myAssembly = Assembly.GetExecutingAssembly();
                }
                if (myAssembly != null)
                {
                    path = myAssembly.Location;
                    DirectoryInfo dr = new DirectoryInfo(path);
                    path = dr.Parent.FullName;  //当前目录的上一级目录
                }
                Environment.SetEnvironmentVariable("THK_VS_ADDIN_PATH", path, EnvironmentVariableTarget.Process);
            }

            //debug
            ThkVCDirSet vcset = m_envcfgs.GetVCConfig();

            if (vcset != null && vcset.EnvConfigItems.Length < 2)
            {
                //vcset.AddVcConfig("VC6", @"D:\develop\VS60\VC98\", "");
                //vcset.AddVcConfig("VC2003", @"D:\develop\vs2002\Vc7\", "");
                //vcset.AddVcConfig("VC2003", @"D:\develop\vs2003\Vc7\", "");
                //vcset.AddVcConfig("VC2005", @"D:\develop\vs2005\Vc\", "");
                //vcset.AddVcConfig("VC2008", @"D:\develop\vs2008\Vc\", "");
                //vcset.AddVcConfig("VC2010", @"D:\develop\vs2010\Vc\", "");
                //vcset.AddVcConfig("VC2012", @"D:\develop\vs2012\Vc\", "");
                //vcset.AddVcConfig("VC2013", @"D:\develop\vs2013\Vc\", "");


                //m_envcfgs.SaveConfig();
            }
            //end of debug

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



                try
                {
                    //若要将此命令移动到另一个菜单,则将“工具”一词更改为此菜单的英文版。
                    //  此代码将获取区域性,将其追加到菜单名中,然后将此命令添加到该菜单中。
                    //  您会在此文件中看到全部顶级菜单的列表
                    //  CommandBar.resx.
                    string          resourceName;
                    ResourceManager resourceManager = new ResourceManager("ThkDevEnc.CommandBar", Assembly.GetExecutingAssembly());
                    CultureInfo     cultureInfo     = new CultureInfo(_applicationObject.LocaleID);

                    if (cultureInfo.TwoLetterISOLanguageName == "zh")
                    {
                        System.Globalization.CultureInfo parentCultureInfo = cultureInfo.Parent;
                        resourceName = String.Concat(parentCultureInfo.Name, "Tools");
                    }
                    else
                    {
                        resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools");
                    }
                    toolsMenuName = resourceManager.GetString(resourceName);
                    if (toolsMenuName == null || toolsMenuName.Length == 0)
                    {
                        toolsMenuName = "工具";
                    }
                }
                catch
                {
                    //我们试图查找“工具”一词的本地化版本,但未能找到。
                    //  默认值为 en-US 单词,该值可能适用于当前区域性。
                    toolsMenuName = "Tools";
                }

                //将此命令置于“工具”菜单上。
                //查找 MenuBar 命令栏,该命令栏是容纳所有主菜单项的顶级命令栏:
                Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"];

                //在 MenuBar 命令栏上查找“工具”命令栏:
                CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName];
                CommandBarPopup   toolsPopup   = (CommandBarPopup)toolsControl;

                //如果希望添加多个由您的外接程序处理的命令,可以重复此 try/catch 块,
                //  只需确保更新 QueryStatus/Exec 方法,使其包含新的命令名。
                //////////////try
                //////////////{
                //////////////    //将一个命令添加到 Commands 集合:
                //////////////    Command command = commands.AddNamedCommand2(_addInInstance, "ProUnlock", "解锁ProE插件", "Executes the command for ProUnlock", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                //////////////    //将对应于该命令的控件添加到“工具”菜单:
                //////////////    if ((command != null) && (toolsPopup != null))
                //////////////    {
                //////////////        command.AddControl(toolsPopup.CommandBar, 1);
                //////////////    }
                //////////////}
                //////////////catch (System.ArgumentException)
                //////////////{
                //////////////    //如果出现此异常,原因很可能是由于具有该名称的命令
                //////////////    //  已存在。如果确实如此,则无需重新创建此命令,并且
                //////////////    //  可以放心忽略此异常。
                //////////////}
                try
                {
                    //将一个命令添加到 Commands 集合:
                    Command command = commands.AddNamedCommand2(_addInInstance, "ProeAttach", "调试ProE", "Executes the command for ThkDevEnc", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    //将对应于该命令的控件添加到“工具”菜单:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException)
                {
                    //如果出现此异常,原因很可能是由于具有该名称的命令
                    //  已存在。如果确实如此,则无需重新创建此命令,并且
                    //  可以放心忽略此异常。
                }
                try
                {
                    //将一个命令添加到 Commands 集合:
                    Command command = commands.AddNamedCommand2(_addInInstance, "CatiaAttach", "调试Catia", "Executes the command for ThkDevEnc", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    //将对应于该命令的控件添加到“工具”菜单:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException)
                {
                    //如果出现此异常,原因很可能是由于具有该名称的命令
                    //  已存在。如果确实如此,则无需重新创建此命令,并且
                    //  可以放心忽略此异常。
                }

                try
                {
                    //将一个命令添加到 Commands 集合:
                    Command command = commands.AddNamedCommand2(_addInInstance, "DevEnvCfg", "森科开发环境", "Executes the command for ThkDevEnc", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    //将对应于该命令的控件添加到“工具”菜单:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException)
                {
                    //如果出现此异常,原因很可能是由于具有该名称的命令
                    //  已存在。如果确实如此,则无需重新创建此命令,并且
                    //  可以放心忽略此异常。
                }
                try
                {
                    //将一个命令添加到 Commands 集合:
                    Command command = commands.AddNamedCommand2(_addInInstance, "VCSet", "当前编译环境", "Executes the command for ThkDevEnc", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    //将对应于该命令的控件添加到“工具”菜单:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException)
                {
                    //如果出现此异常,原因很可能是由于具有该名称的命令
                    //  已存在。如果确实如此,则无需重新创建此命令,并且
                    //  可以放心忽略此异常。
                }

                try
                {
                    //将一个命令添加到 Commands 集合:
                    Command command = commands.AddNamedCommand2(_addInInstance, "UnAttach", "全部分离调试", "Executes the command for ThkDevEnc", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    //将对应于该命令的控件添加到“工具”菜单:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException)
                {
                    //如果出现此异常,原因很可能是由于具有该名称的命令
                    //  已存在。如果确实如此,则无需重新创建此命令,并且
                    //  可以放心忽略此异常。
                }


                try
                {
                    //将一个命令添加到 Commands 集合:
                    Command command = commands.AddNamedCommand2(_addInInstance, "CopyFile", "文件拷贝", "Executes the command for ThkDevEnc", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    //将对应于该命令的控件添加到“工具”菜单:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException)
                {
                    //如果出现此异常,原因很可能是由于具有该名称的命令
                    //  已存在。如果确实如此,则无需重新创建此命令,并且
                    //  可以放心忽略此异常。
                }
            }
        }
Esempio n. 12
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;

                //Place the command on the project context menu
                Microsoft.VisualStudio.CommandBars.CommandBar projectContextMenu = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["Project"];

                CommandBarPopup baseLinePopup = (CommandBarPopup)projectContextMenu.Controls.Add(MsoControlType.msoControlPopup,
                    System.Reflection.Missing.Value, System.Reflection.Missing.Value, 1, true );

                baseLinePopup.Caption = "Baseline";

                CommandBarControl generateTestsControl =
                baseLinePopup.Controls.Add(MsoControlType.msoControlButton,
                System.Reflection.Missing.Value,
                System.Reflection.Missing.Value, 1, true);
                // Set the caption of the submenuitem
                generateTestsControl.Caption = "Generate Unit Tests";

                m_generateTestsHandler = (CommandBarEvents)_applicationObject.Events.get_CommandBarEvents(generateTestsControl);
                m_generateTestsHandler.Click += GenerateTestsClick;

                m_NCrunchMenu =
            ((CommandBars)
             _applicationObject.CommandBars)["NCrunch"];
                //m_FinishedNCrunchSearch = new ManualResetEvent(false);
                //ThreadPool.QueueUserWorkItem((w) =>
                //{
                //    m_NCrunchMenu =
                //        ((Microsoft.VisualStudio.CommandBars.CommandBars)
                //         _applicationObject.CommandBars)["NCrunch"];
                //    m_FinishedNCrunchSearch.Set();
                //});
            }
        }
Esempio n. 13
0
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            _applicationObject = (DTE2)application;
            _addInInstance     = (AddIn)addInInst;


            switch (connectMode)
            {
            case ext_ConnectMode.ext_cm_Startup:      //     The add-in was loaded when Visual Studio started.
            case ext_ConnectMode.ext_cm_AfterStartup: //     The add-in was loaded after Visual Studio started.
            case ext_ConnectMode.ext_cm_External:     //     The add-in was loaded by an external client. (This setting is no longer used by Visual Studio.)
            case ext_ConnectMode.ext_cm_CommandLine:  //     The add-in was loaded from the command line.
            case ext_ConnectMode.ext_cm_Solution:     //     The add-in was loaded with a solution.
            case ext_ConnectMode.ext_cm_UISetup:      //     The add-in was loaded for user interface setup.
                if (!TestCocoon.isTestCocoonAvailable())
                {
                    Log("TestCocoon not installed - Add-In deactivated.");
                    return;
                }
                TestCocoon.AdjustPath();
                object[]  contextGUIDS = new object[] { };
                Commands2 commands     = (Commands2)_applicationObject.Commands;
                string    projectMenuName;

                try
                {
                    ResourceManager resourceManager = new ResourceManager("TestCocoonVs2005AddIn.CommandBar", Assembly.GetExecutingAssembly());
                    CultureInfo     cultureInfo     = new System.Globalization.CultureInfo(_applicationObject.LocaleID);
                    string          resourceName    = String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools");
                    projectMenuName = resourceManager.GetString(resourceName);
                }
                catch (Exception e)
                {
                    Debug(e);
                    projectMenuName = "Tools";
                }

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

                CommandBarControl projectControl = menuBarCommandBar.Controls[projectMenuName];
                CommandBarPopup   projectPopup   = (CommandBarPopup)projectControl;

                try
                {
                    Command commandGenerate = commands.AddNamedCommand2(
                        _addInInstance,
                        "GenerateConfiguration",
                        "Code Coverage Build Mode...",
                        "Generates a code coverage build mode using TestCocoon for the instrumentation",
                        true,
                        0,
                        ref contextGUIDS,
                        (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                        (int)vsCommandStyle.vsCommandStylePictAndText,
                        vsCommandControlType.vsCommandControlTypeButton
                        );

                    if ((commandGenerate != null) && (projectPopup != null))
                    {
                        commandGenerate.AddControl(projectPopup.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException e)
                {
                    Debug(e);
                    //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.
                }
                if (!bAddinInitialized)
                {
                    bAddinInitialized = true;
                    Log("TestCocoon Add-In activated.");
                }
                break;
            }
        }
Esempio n. 14
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)
        {
            try
            {
                _applicationObject = (DTE2)application;
                _addInInstance     = (EnvDTE.AddIn)addInInst;

                if (!menuRegistered)
                {
                    Commands2 commands = (Commands2)_applicationObject.Commands;

                    foreach (Command cmd in commands)
                    {
                        if (cmd.Name == "EntitySpaces.AddIn.ES2019.Connect.EntitySpaces2019")
                        {
                            menuRegistered = true;
                            break;
                        }
                    }

                    if (!menuRegistered)
                    {
                        try
                        {
                            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.
                                string          resourceName;
                                ResourceManager resourceManager = new ResourceManager("EntitySpaces.AddIn.ES2019.CommandBar", Assembly.GetExecutingAssembly());
                                CultureInfo     cultureInfo     = new CultureInfo(_applicationObject.LocaleID);

                                if (cultureInfo.TwoLetterISOLanguageName == "zh")
                                {
                                    System.Globalization.CultureInfo parentCultureInfo = cultureInfo.Parent;
                                    resourceName = String.Concat(parentCultureInfo.Name, "Tools");
                                }
                                else
                                {
                                    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;

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

                            Command command = commands.AddNamedCommand2(_addInInstance, "EntitySpaces2019", "EntitySpaces 2019", "Open the EntitySpaces 2019 Window", true, 1018,
                                                                        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);
                                menuRegistered = true;
                            }
                        }
                        catch (System.ArgumentException eee)
                        {
                        }
                    }
                }

                if (esWindow == null)
                {
                    object programmableObject = null;

                    string   guidString = "{08C42F7C-B8FB-4c8b-B364-37F7E04E78E7}";
                    Windows2 windows2   = (Windows2)_applicationObject.Windows;
                    Assembly asm        = Assembly.GetExecutingAssembly();
                    toolWindow = windows2.CreateToolWindow2(_addInInstance, asm.Location, "EntitySpaces.AddIn.ES2019.MainWindow", "EntitySpaces 2019",
                                                            guidString, ref programmableObject);
                    toolWindow.Visible         = true;
                    esWindow                   = (MainWindow)toolWindow.Object;
                    esWindow.ApplicationObject = _applicationObject;
                }
            }
            catch { }
        }
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
            DTE2 dte = (DTE2)FirstPackage.GetGlobalService(typeof(DTE));

            if (context == null)
            {
                context = new DynaTrace.CodeLink.Context(dte);
            }

            context.log("onConnection - Initialize");

            context.log(DynaTrace.CodeLink.Context.LOG_INFO + "CodeLink Version: " + context.VersionString);

            //from MS-Code only UISetup is necessary, but we need Startup because we have troubles with VS05 (show the menu item)
            // if (connectMode == ext_ConnectMode.ext_cm_UISetup || connectMode == ext_ConnectMode.ext_cm_Startup) {

            if (!_bConnected)
            {
                object[] contextGUIDS = new object[] { };

                string toolsMenuName;
                // if ((!found && connectMode == ext_ConnectMode.ext_cm_Startup) || (connectMode == ext_ConnectMode.ext_cm_UISetup)) {
                bool found = false;
                if (!found)
                {
                    try
                    {
                        ResourceManager resourceManager = new ResourceManager("DynaTrace.CodeLink.CommandBar", Assembly.GetExecutingAssembly());
                        CultureInfo     cultureInfo     = new System.Globalization.CultureInfo(dte.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)dte.CommandBars)["MenuBar"];

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

                    //// Create the menu entry for dynaTrace Configuration Dialog
                    //try
                    //{
                    //    try
                    //    {
                    //        _commandSetup = (Command)commands.Item(COMMAND_NAME + ".Setup", 0);
                    //    }
                    //    catch (Exception) { /* context.log("INFO " + e.ToString()); */}

                    //    if (_commandSetup == null)
                    //        _commandSetup = commands.AddNamedCommand2(_addInInstance, "Setup", "dynaTrace Configuration",
                    //            "Opens the configuration dialog for CodeLink & Launcher", false, 1,
                    //            ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                    //            (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    //    else
                    //        _commandSetup = null;
                    //}
                    //catch (Exception e)
                    //{
                    //    //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.
                    //    context.log(Context.LOG_ERROR + e.ToString());
                    //}

                    //// Create the menu entry for the dynaTrace Launcher
                    //try
                    //{
                    //    try
                    //    {
                    //        _commandLauncher = (Command)commands.Item(COMMAND_NAME + ".dynaTraceLauncher", 0);
                    //    }
                    //    catch (System.Exception) { /* context.log("INFO " + e.ToString()); */}

                    //    //Add a command to the Commands collection:
                    //    if (_commandLauncher == null)
                    //        _commandLauncher = commands.AddNamedCommand2(_addInInstance, "dynaTraceLauncher", "dynaTrace Launcher", "Launches the startup project with dynaTrace Support", false, 1 /*59*/, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    //    else
                    //        _commandLauncher = null; // already there - therefore dont add it again to the tools menu
                    //}
                    //catch (System.Exception e)
                    //{
                    //    context.log(Context.LOG_ERROR + e.ToString());
                    //}

                    ////Add to tools menu
                    //if (toolsPopup != null)
                    //{
                    //    try
                    //    {
                    //        if (_commandSetup != null)
                    //            _commandSetup.AddControl(toolsPopup.CommandBar, 1);
                    //        if (_commandLauncher != null)
                    //            _commandLauncher.AddControl(toolsPopup.CommandBar, 1);
                    //    }
                    //    catch (Exception e)
                    //    {
                    //        context.log(Context.LOG_ERROR + e.ToString());
                    //    }
                    //}
                }
                _bConnected = true;
            }

            // create the launcher implementation class
//            if (_launcher == null)
//            {
//                _launcher = new dynaTraceLauncher.LauncherConnect(_applicationObject, _addInInstance);
//                _launcher.Context = context;
//            }
//            // In VS2010 also create the WebTestPlugin
//#if (VS_2010)
//            try
//            {
//                dynaTrace.VSTS.WebResultAddin.WebTestConnect webTestConnect = new dynaTrace.VSTS.WebResultAddin.WebTestConnect();
//                webTestConnect.OnConnection(application, connectMode, addInInst, ref custom);
//            }
//            catch (Exception e) {context.log(Context.LOG_ERROR + e.ToString());}
//#endifs

            if (context.Config.PluginEnabled)
            {
                context.connect();
            }

            LaunchCommand.Initialize(this);
            LaunchCommand.Instance.Launcher = new Launcher(dte, context);
            ConfigCommand.Initialize(this);
            ConfigCommand.Instance.Context  = context;
            ConfigCommand.Instance.Launcher = LaunchCommand.Instance.Launcher;
            RunTestsMenu.Initialize(this);
        }
Esempio 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     = (EnvDTE.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.
                    string          resourceName;
                    ResourceManager resourceManager = new ResourceManager("JsParser_AddIn.CommandBar", Assembly.GetExecutingAssembly());
                    CultureInfo     cultureInfo     = new CultureInfo(_applicationObject.LocaleID);

                    if (cultureInfo.TwoLetterISOLanguageName == "zh")
                    {
                        System.Globalization.CultureInfo parentCultureInfo = cultureInfo.Parent;
                        resourceName = String.Concat(parentCultureInfo.Name, "Tools");
                    }
                    else
                    {
                        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:
                    var comShow = commands.AddNamedCommand2(_addInInstance,
                                                            "Show",
                                                            "Javascript Parser",
                                                            "Javascript Parser AddIn Show",
                                                            true,
                                                            629,
                                                            ref contextGUIDS,
                                                            (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                                                            (int)vsCommandStyle.vsCommandStylePictAndText,
                                                            vsCommandControlType.vsCommandControlTypeButton
                                                            );

                    //Add a command to the Commands collection:
                    var comFind = commands.AddNamedCommand2(_addInInstance,
                                                            "Find",
                                                            "Javascript Parser Find",
                                                            "Javascript Parser AddIn 'Find' Feature",
                                                            true,
                                                            0,
                                                            ref contextGUIDS,
                                                            (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                                                            (int)vsCommandStyle.vsCommandStylePictAndText,
                                                            vsCommandControlType.vsCommandControlTypeButton
                                                            );

                    //Add a control for the command to the tools menu:
                    if (toolsPopup != null)
                    {
                        if (comShow != null)
                        {
                            comShow.AddControl(toolsPopup.CommandBar, 1);
                        }

                        if (comFind != null)
                        {
                            comFind.Bindings = "Text Editor::SHIFT+ALT+J";
                            comFind.AddControl(toolsPopup.CommandBar, 2);
                        }
                    }
                }
                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.
                }
            }

            //Subscribe to IDE events
            Events events = _applicationObject.Events;

            _documentEvents = events.get_DocumentEvents(null);
            _windowEvents   = events.get_WindowEvents(null);
            _documentEvents.DocumentSaved  += documentEvents_DocumentSaved;
            _documentEvents.DocumentOpened += documentEvents_DocumentOpened;
            _windowEvents.WindowActivated  += windowEvents_WindowActivated;

            _uiThemeProvider           = new DefaultUIThemeProvider();
            _jsParserService           = new JsParserService(Settings.Default);
            _jsParserToolWindowManager = new JsParserToolWindowManager(_jsParserService, _uiThemeProvider, () =>
            {
                return(EnsureWindowCreated());
            });
        }
Esempio n. 17
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)
        {
            //var namesToLookFor = new List<string>()
            //{
            //    //"Cop&y",
            //    //"Copy with Headers",
            //    //"Select &All",
            //    //"Sa&ve Results As",
            //    "Page Set&up",
            //    //"&Print"
            //};
            _applicationObject = (DTE2)application;
            _addInInstance     = (AddIn)addInInst;
            if (connectMode == ext_ConnectMode.ext_cm_Startup)
            {
                object[]  contextGUIDS  = new object[] { };
                Commands2 commands      = (Commands2)_applicationObject.Commands;
                string    toolsMenuName = "Tools";

                foreach (Command c in commands)
                {
                }

                //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"];
                CommandBar resultGridCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["SQL Results Grid Tab Context"];
                //var popup = resultGridCommandBar.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, 1, true) as CommandBarPopup;
                //popup.Caption = "TSET BUTTON";
                //foreach (CommandBar commandBar in (Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)
                //{
                //    if (commandBar.Controls.Cast<CommandBarControl>().Any(c => namesToLookFor.Any(n => c.Caption.Contains(n))))
                //    {
                //        var commandNames = commandBar.Controls.Cast<CommandBarControl>().Select(c => c.Caption).ToList();
                //        int stop = 1;
                //        stop = 2;
                //    }
                //}

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

                _applicationObject.Events.WindowEvents.WindowCreated += WindowEvents_WindowCreated;

                //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, "ViewReferencedValue", "View Referenced Value", "Creates a new query to view the row of the referenced value", 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);
                    //}
                    //foreach (CommandBar commandBar in (Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)
                    //{
                    //    //if (commandBar.Controls.Cast<CommandBarControl>().Any(c => namesToLookFor.Any(n => c.Caption.Contains(n))))
                    //    //{
                    //    //    var commandNames = commandBar.Controls.Cast<CommandBarControl>().Select(c => c.Caption).ToList();
                    //    //    int stop = 1;
                    //    //    stop = 2;
                    //    //}
                    //    command.AddControl(commandBar, 1);
                    //}
                    command.AddControl(resultGridCommandBar, 1);
                }
                catch (System.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.
                }
            }
        }
Esempio n. 18
0
        /// <summary>IDTExtensibility2 인터페이스의 OnConnection 메서드를 구현합니다. 추가 기능이 로드되고 있다는 알림 메시지를 받습니다.</summary>
        /// <param term='application'>호스트 응용 프로그램의 루트 개체입니다.</param>
        /// <param term='connectMode'>추가 기능이 로드되는 방법을 설명합니다.</param>
        /// <param term='addInInst'>이 추가 기능을 나타내는 개체입니다.</param>
        /// <seealso class='IDTExtensibility2' />
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            AddNewSubCommand("OpenSolutionFolderExplorer", "Open Solution Folder with Explorer", 65);
            AddNewSubCommand("OpenSolutionFolderCmd", "Open Command Prompt on Solution Folder", 65);
            AddNewSubCommand("OpenCorrespondingFile", "Toggle Source/Header", 65);
            AddNewSubCommand("OpenFileInSolution", "Quick Open File In Solution", 65);
            AddNewSubCommand("About", "About ZAssist...", 65);
            //AddNewSubCommand("QuickFindFunction", "Quick Find Function", 65);

            _applicationObject = (DTE2)application;
            _addInInstance     = (AddIn)addInInst;
            if (connectMode == ext_ConnectMode.ext_cm_UISetup ||
                connectMode == ext_ConnectMode.ext_cm_Startup ||
                connectMode == ext_ConnectMode.ext_cm_AfterStartup)
            {
                object[]  contextGUIDS = new object[] { };
                Commands2 commands     = (Commands2)_applicationObject.Commands;
                string    toolsMenuName;

                try
                {
                    //명령을 다른 메뉴로 이동하려면 "Tools"를
                    //  영어 버전의 메뉴로 변경합니다. 이 코드는 culture를 메뉴 이름에 추가한 다음
                    //  해당 메뉴에 명령을 추가합니다. 모든 최상위 메뉴의 목록을 확인하려면
                    //  CommandBar.resx 파일을 참조하십시오.
                    ResourceManager resourceManager = new ResourceManager("ZAssist.CommandBar", Assembly.GetExecutingAssembly());
                    CultureInfo     cultureInfo     = new System.Globalization.CultureInfo(_applicationObject.LocaleID);
                    string          resourceName    = String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools");
                    toolsMenuName = resourceManager.GetString(resourceName);
                }
                catch
                {
                    //지역화된 버전의 'Tools'를 찾으려고 시도했지만 찾지 못했습니다.
                    //  기본값을 현재 culture에서 작동할 수 있는 en-US로 지정합니다.
                    toolsMenuName = "Tools";
                }

                //도구 메뉴에 명령을 배치합니다.
                //주 메뉴 항목이 모두 들어 있는 최상위 명령 모음인 MenuBar 명령 모음 찾기:
                Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"];

                //MenuBar 명령 모음에서 도구 명령 모음 찾기:
                CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName];
                CommandBarPopup   toolsPopup   = (CommandBarPopup)toolsControl;

                //추가 기능에서 처리할 명령을 여러 개 추가하면 이 try/catch 블록이 중복될 수 있습니다.
                //  이 경우 QueryStatus/Exec 메서드도 업데이트하여 새 명령 이름을 포함하기만 하면 됩니다.
                try
                {
                    //명령 컬렉션에 명령 추가:
                    CommandBar toolsMenu = ((CommandBars)(_applicationObject.CommandBars))["Tools"];

                    try
                    {
                        /// 아래 문장에서 catch 로 빠진다는 건 ZAssist 가 메뉴에 없다는 말이다.
                        CommandBarPopup k = (CommandBarPopup)(toolsMenu.Controls["ZAssist"]);
                        k.Caption = k.Caption + "";
                    }
                    catch (ArgumentException)
                    {
                        CommandBarPopup commandBarPopup = (CommandBarPopup)toolsMenu.Controls.Add(MsoControlType.msoControlPopup, System.Reflection.Missing.Value, System.Reflection.Missing.Value, 1, true);

                        subMenu         = commandBarPopup;
                        subMenu.Visible = true;
                        subMenu.Caption = "ZAssist";

                        int iMenuIndex = 1;
                        foreach (NewCommandData newCommData in m_commands)
                        {
                            Command newCommand = null;

                            try
                            {
                                newCommand = commands.Item(_addInInstance.ProgID + "." + newCommData.GetCommandName(), -1);
                            }
                            catch (Exception ex)
                            {
                                System.Diagnostics.Debug.Print("이미 존재하는지 검사하는 곳에서 exception 발생 : ", ex.Message);
                            }

                            if (null == newCommand)
                            {
                                newCommand = commands.AddNamedCommand(_addInInstance, newCommData.GetCommandName(), newCommData.GetShowName(), newCommData.GetShowName(), true, newCommData.GetInconIndex(), ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled);
                            }

                            if (newCommand != null)
                            {
                                newCommand.AddControl(subMenu.CommandBar, iMenuIndex);
                            }

                            ++iMenuIndex;
                        }
                    }
                }
                catch (System.ArgumentException ex)
                {
                    //이 경우, 같은 이름의 명령이 이미 있기 때문에 예외가 발생할 수
                    //  있습니다. 이 경우 명령을 다시 만들 필요가 없으며 예외를 무시해도
                    //  됩니다.
                    System.Diagnostics.Debug.Print(ex.Message);
                }
            }
        }
Esempio n. 19
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.
                    string          resourceName;
                    ResourceManager resourceManager = new ResourceManager("FirstAddin.CommandBar", Assembly.GetExecutingAssembly());
                    CultureInfo     cultureInfo     = new CultureInfo(_applicationObject.LocaleID);

                    if (cultureInfo.TwoLetterISOLanguageName == "zh")
                    {
                        System.Globalization.CultureInfo parentCultureInfo = cultureInfo.Parent;
                        resourceName = String.Concat(parentCultureInfo.Name, "Tools");
                    }
                    else
                    {
                        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, "InsertDate", "InsertDate", "Executes the command for FirstAddin", 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.
                }
            }
        }
Esempio n. 20
0
        protected void GenerateTestsClick(object CommandaBarControl,
            ref bool handled, ref bool cancelDefault)
        {
            if(m_NCrunchMenu == null)
            {m_NCrunchMenu =
                ((CommandBars)
                 _applicationObject.CommandBars)["NCrunch"];}
            //m_FinishedNCrunchSearch.Set();

            foreach (var selectedProject in this.GetSelectedProjects())
            {
              this._applicationObject.Solution.SolutionBuild.BuildProject(_applicationObject.Solution.SolutionBuild.ActiveConfiguration.Name,
                selectedProject.UniqueName, true);

              if (this._applicationObject.Solution.SolutionBuild.LastBuildInfo == 0)
              {
                  var testProject = this.AddTestProject(selectedProject);

                  var testAssembly = this.GetAssembly(selectedProject);

                  var tester = new Tester();

                  foreach (var type in testAssembly.GetTypes())
                  {
                      var testSuite = tester.GenerateTests(type);
                      AddTestSuiteToProject(testSuite, testProject);

                      //m_FinishedNCrunchSearch.WaitOne();
                      if (m_NCrunchMenu != null)
                      {
                          var disableCommand = m_NCrunchMenu.Controls["Disable"];
                          var enableCommand = m_NCrunchMenu.Controls["Enable"];

                              disableCommand.Execute();
                              enableCommand.Execute();

                      }
                  }
              }
            }
        }
Esempio n. 21
0
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            if (connectMode == ext_ConnectMode.ext_cm_Startup)
            {
                _app   = (DTE2)application;
                _addIn = (AddIn)addInInst;
                CommandBarPopup depMainPop = null;
                cmdHt    = new Hashtable();
                commands = (Commands2)_app.Commands;

                solevt = _app.Events.SolutionEvents;
                solevt.AfterClosing += new _dispSolutionEvents_AfterClosingEventHandler(solevt_AfterClosing);
                solevt.ProjectAdded += new _dispSolutionEvents_ProjectAddedEventHandler(solevt_ProjectAdded);
                solevt.Opened       += new _dispSolutionEvents_OpenedEventHandler(solevt_Opened);
                Hashtable ht = new Hashtable();
                foreach (Command c in commands)
                {
                    if (c.Name.Contains("DeployAddIn"))
                    {
                        cmdHt.Add(c.Name, c);
                    }
                }

                object[] contextGUIDS = new object[] { };
                string   toolsMenuName;

                try {
                    ResourceManager resourceManager = new ResourceManager("DeployAddIn.CommandBar", Assembly.GetExecutingAssembly());
                    CultureInfo     cultureInfo     = new System.Globalization.CultureInfo(_app.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 menuBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_app.CommandBars)["MenuBar"];

                //Find the Tools command bar on the MenuBar command bar:
                CommandBarControl toolsControl = menuBar.Controls[toolsMenuName];

                CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl;
                try {
                    depMainPop            = (CommandBarPopup)toolsPopup.Controls.Add(vsCommandBarType.vsCommandBarTypePopup, 1, "", 1, true);
                    depMainPop.Caption    = "SQL CLR Deployment";
                    depMainPop.BeginGroup = true;
                    depMainPop.Visible    = true;



                    //Add a command to the Commands collection:
                    AddCmd(depMainPop.CommandBar, "DepProp", "Deployment Properties", "Allows you to set properties for the deployment task.", 1);
                }


                catch (Exception ex1) {
                    MessageBox.Show(ex1.Message, "Error");
                }


                try {
                    CommandBarPopup depSubPop = (CommandBarPopup)depMainPop.Controls.Add(vsCommandBarType.vsCommandBarTypePopup, 1, "", 2, true);
                    depSubPop.Caption    = "Deploy/Drop Assemblies";
                    depSubPop.BeginGroup = true;
                    depSubPop.Visible    = true;



                    AddCmd(depSubPop.CommandBar, "DepAll", "Deploy All (assembly, methods etc)", "Deploys the assembly and all the procedures, functions etc.", 1);
                    AddCmd(depSubPop.CommandBar, "DepAsm", "Deploy Assembly", "Deploys the assembly.", 2);
                    AddCmd(depSubPop.CommandBar, "DepUdt", "Create UDT's", "Creates the user defined types in the assembly.", 3);
                    AddCmd(depSubPop.CommandBar, "DepMeth", "Create Methods", "Creates the procedures, functions etc, in the assembly", 4);
                    AddCmd(depSubPop.CommandBar, "DropAll", "Drop All (assembly, methods etc)", "Drops the assembly and all the procedures, functions etc.", 5);
                    AddCmd(depMainPop.CommandBar, "Debug", "Debug", "Debug the assembly.", 3);
                }
                catch (Exception ex2) {
                    MessageBox.Show(ex2.Message, "Error");
                }
            }
        }
Esempio n. 22
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)
        {
            Mfconsulting.Vsprj2make.RegistryHelper regHlpr = new RegistryHelper();
            string[] monoVersions = regHlpr.GetMonoVersions();

            _applicationObject = (DTE2)application;
            _addInInstance     = (AddIn)addInInst;
            int selectedIndexForComboBox = 1;

            OutputWindow outputWindow = (OutputWindow)_applicationObject.Windows.Item(Constants.vsWindowKindOutput).Object;

            outputWindowPane = outputWindow.OutputWindowPanes.Add("Monoaddin Messages");

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

                _CommandBars    commandBars = (Microsoft.VisualStudio.CommandBars._CommandBars)_applicationObject.CommandBars;
                CommandBar      cmdBarMonoBarra;
                CommandBarPopup popMenu;        // Prj2Make popupmenu
                CommandBarPopup popMenu2;       // Explorer Current Project

                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("monoaddin.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];
                CommandBarControls commandBarControls;
                commandBarControls = ((CommandBarPopup)toolsControl).Controls;


                // Create Makefile
                Command command1 = null;
                // Generate MonoDevelop files
                Command command2 = null;
                // Generate a distribution unit
                Command command3 = null;
                // Import MonoDevelop Solutions
                Command command4 = null;
                // Run on Mono
                Command command5 = null;
                // vsprj2make Options
                Command command6 = null;
                // Explore current solution
                Command command7 = null;
                // Explore current Project
                Command command8 = null;


                // ------------- Add Pop-up menu ----------------
                popMenu2 = (CommandBarPopup)commandBarControls.Add(
                    MsoControlType.msoControlPopup,
                    System.Reflection.Missing.Value, // Object ID
                    System.Reflection.Missing.Value, // Object parameters
                    1,                               // Object before
                    true
                    );

                popMenu2.Caption = "&Windows Explore";

                // ------------- Add Pop-up menu ----------------
                popMenu = (CommandBarPopup)commandBarControls.Add(
                    MsoControlType.msoControlPopup,
                    System.Reflection.Missing.Value, // Object ID
                    System.Reflection.Missing.Value, // Object parameters
                    1,                               // Object before
                    true
                    );

                popMenu.Caption = "Prj&2Make";

                //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 the create makefile command -- command1
                    //command1 = commands.AddNamedCommand2(
                    //    _addInInstance, "CreateMake", "Create &Makefile",
                    //    "Generate Makefile", true, 59, ref contextGUIDS,
                    //    (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                    //    (int)vsCommandStyle.vsCommandStylePictAndText,
                    //    vsCommandControlType.vsCommandControlTypeButton
                    //);

                    // Add the create makefile command -- command1
                    command1 = CreateNamedCommand(
                        _addInInstance,
                        commands,
                        "CreateMake",
                        "Create &Makefile",
                        "Generate Makefile",
                        ref contextGUIDS
                        );

                    //Add a control for the command to the tools menu:
                    if ((command1 == null) && (popMenu != null))
                    {
                        command1 = GetExistingNamedCommand(commands, "Mfconsulting.Vsprj2make.Connect.CreateMake");
                        command1.AddControl(popMenu.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException exc)
                {
                    //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.
                    Trace.WriteLine(String.Format("Error during OnConnect of Add-in:\n {0}", exc.Message));
                }

                try
                {
                    // Add the GenMDFiles command -- command2
                    command2 = CreateNamedCommand(
                        _addInInstance,
                        commands,
                        "GenMDFiles",
                        "Create Mono&Develop Solution",
                        "Generate MonoDevelop Solution",
                        ref contextGUIDS
                        );

                    //Add a control for the command to the tools menu:
                    if ((command2 == null) && (popMenu != null))
                    {
                        command2 = GetExistingNamedCommand(commands, "Mfconsulting.Vsprj2make.Connect.GenMDFiles");
                        command2.AddControl(popMenu.CommandBar, 2);
                    }
                }
                catch (System.ArgumentException exc)
                {
                    Trace.WriteLine(String.Format("Error during OnConnect of Add-in:\n {0}", exc.Message));
                }

                try
                {
                    // Add the generate a dist unit command -- command3
                    command3 = CreateNamedCommand(
                        _addInInstance,
                        commands,
                        "GenDistUnit",
                        "Generate Distribution &Unit",
                        "Generates a distribution unit (zip file)",
                        ref contextGUIDS
                        );

                    //Add a control for the command to the tools menu:
                    if ((command3 == null) && (popMenu != null))
                    {
                        command3 = GetExistingNamedCommand(commands, "Mfconsulting.Vsprj2make.Connect.GenDistUnit");
                        command3.AddControl(popMenu.CommandBar, 3);
                    }
                }
                catch (System.ArgumentException exc)
                {
                    Trace.WriteLine(String.Format("Error during OnConnect of Add-in:\n {0}", exc.Message));
                }

                try
                {
                    // Add the ImportMD Solution command -- command4
                    command4 = CreateNamedCommand(
                        _addInInstance,
                        commands,
                        "PrjxToCsproj",
                        "&Import MonoDevelop Solution...",
                        "Imports a MonoDevelop Solution",
                        ref contextGUIDS
                        );

                    //Add a control for the command to the tools menu:
                    if ((command4 == null) && (popMenu != null))
                    {
                        command4 = GetExistingNamedCommand(commands, "Mfconsulting.Vsprj2make.Connect.PrjxToCsproj");
                        command4.AddControl(popMenu.CommandBar, 4);
                    }
                }
                catch (System.ArgumentException exc)
                {
                    Trace.WriteLine(String.Format("Error during OnConnect of Add-in:\n {0}", exc.Message));
                }

                try
                {
                    // Add the Run on Mono command -- command5
                    command5 = CreateNamedCommand(
                        _addInInstance,
                        commands,
                        "RunOnMono",
                        "&Run on Mono",
                        "Run solution on mono",
                        ref contextGUIDS
                        );

                    //Add a control for the command to the tools menu:
                    if ((command5 == null) && (popMenu != null))
                    {
                        command5 = GetExistingNamedCommand(commands, "Mfconsulting.Vsprj2make.Connect.RunOnMono");
                        command5.AddControl(popMenu.CommandBar, 5);
                    }
                }
                catch (System.ArgumentException exc)
                {
                    Trace.WriteLine(String.Format("Error during OnConnect of Add-in:\n {0}", exc.Message));
                }

                try
                {
                    // Add the Options command -- command6
                    command6 = CreateNamedCommand(
                        _addInInstance,
                        commands,
                        "Options",
                        "&Options...",
                        "Options for prj2make Add-in",
                        ref contextGUIDS
                        );

                    //Add a control for the command to the tools menu:
                    if ((command6 == null) && (popMenu != null))
                    {
                        command6 = GetExistingNamedCommand(commands, "Mfconsulting.Vsprj2make.Connect.Options");
                        command6.AddControl(popMenu.CommandBar, 6);
                    }
                }
                catch (System.ArgumentException exc)
                {
                    Trace.WriteLine(String.Format("Error during OnConnect of Add-in:\n {0}", exc.Message));
                }

                try
                {
                    // Add the ExploreCurrSln command -- command7
                    command7 = CreateNamedCommand(
                        _addInInstance,
                        commands,
                        "ExploreCurrSln",
                        "Current &Solution",
                        "Explore the current solution",
                        ref contextGUIDS
                        );

                    //Add a control for the command to the tools menu:
                    if ((command7 == null) && (popMenu != null))
                    {
                        command7 = GetExistingNamedCommand(commands, "Mfconsulting.Vsprj2make.Connect.ExploreCurrSln");
                        command7.AddControl(popMenu2.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException exc)
                {
                    Trace.WriteLine(String.Format("Error during OnConnect of Add-in:\n {0}", exc.Message));
                }

                try
                {
                    // Add the ExploreCurrDoc command -- command8
                    command8 = CreateNamedCommand(
                        _addInInstance,
                        commands,
                        "ExploreCurrDoc",
                        "Current &Document",
                        "Explore the current Document",
                        ref contextGUIDS
                        );

                    //Add a control for the command to the tools menu:
                    if ((command8 == null) && (popMenu != null))
                    {
                        command8 = GetExistingNamedCommand(commands, "Mfconsulting.Vsprj2make.Connect.ExploreCurrDoc");
                        command8.AddControl(popMenu2.CommandBar, 2);
                    }
                }
                catch (System.ArgumentException exc)
                {
                    Trace.WriteLine(String.Format("Error during OnConnect of Add-in:\n {0}", exc.Message));
                }

                // Mono Toolbar
                CommandBar cmdBarBuild = (CommandBar)commandBars["Build"];

                try
                {
                    cmdBarMonoBarra = (CommandBar)commandBars["MonoBarra"];
                }
                catch (Exception)
                {
                    commands.AddCommandBar("MonoBarra",
                                           vsCommandBarType.vsCommandBarTypeToolbar,
                                           cmdBarBuild,
                                           1
                                           );

                    cmdBarMonoBarra         = (CommandBar)commandBars["MonoBarra"];
                    cmdBarMonoBarra.Visible = true;
                }

                if (testInMonoCommandBarButton == null)
                {
                    // Create the Run on Mono Button
                    testInMonoCommandBarButton = (CommandBarButton)cmdBarMonoBarra.Controls.Add(
                        Microsoft.VisualStudio.CommandBars.MsoControlType.msoControlButton,
                        System.Reflection.Missing.Value,
                        System.Reflection.Missing.Value,
                        1,
                        false
                        );

                    testInMonoCommandBarButton.Caption         = "Run on &Mono";
                    testInMonoCommandBarButton.DescriptionText = "Run solution with the mono runtime";
                    testInMonoCommandBarButton.TooltipText     = "Run on mono";
                    testInMonoCommandBarButton.ShortcutText    = "Run on &Mono";
                    testInMonoCommandBarButton.Style           = MsoButtonStyle.msoButtonCaption;
                    testInMonoCommandBarButton.Click          += new _CommandBarButtonEvents_ClickEventHandler(testInMonoCommandBarButton_Click);
                }

                if (versionComboBox == null)
                {
                    // Create the combobox
                    versionComboBox = (CommandBarComboBox)cmdBarMonoBarra.Controls.Add(
                        Microsoft.VisualStudio.CommandBars.MsoControlType.msoControlDropdown,
                        System.Reflection.Missing.Value,
                        System.Reflection.Missing.Value,
                        2,
                        false
                        );

                    for (int i = 0; i < monoVersions.Length; i++)
                    {
                        versionComboBox.AddItem(monoVersions[i], i + 1);
                        if (monoVersions[i].CompareTo(regHlpr.GetDefaultClr()) == 0)
                        {
                            selectedIndexForComboBox = i + 1;
                        }
                    }

                    versionComboBox.Change += new _CommandBarComboBoxEvents_ChangeEventHandler(versionComboBox_Change);

                    // Select the active index based on
                    // the current mono version
                    versionComboBox.ListIndex = selectedIndexForComboBox;
                }
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Adds the Upgraded Task Window menu item to the tool window items
        /// </summary>
        private void AddToolWindowMenuItem()
        {
            object[]  contextGUIDS = new object[] { };
            Commands2 commands     = (Commands2)_applicationObject.Commands;
            string    viewMenuName;

            try
            {
                //If you would like to move the command to a different menu, change the word "View" 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("UpgradedTaskList.TaskListControl", Assembly.GetExecutingAssembly());
                CultureInfo     cultureInfo     = new System.Globalization.CultureInfo(_applicationObject.LocaleID);
                string          resourceName    = String.Concat(cultureInfo.TwoLetterISOLanguageName, "View");
                viewMenuName = resourceManager.GetString(resourceName);
            }
            catch
            {
                //We tried to find a localized version of the word View, but one was not found.
                //  Default to the en-US word, which may work for the current culture.
                viewMenuName = "View";
            }

            //Place the command on the view 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 View command bar on the MenuBar command bar:
            CommandBarControl viewControl = menuBarCommandBar.Controls[viewMenuName];
            CommandBarPopup   viewPopup   = (CommandBarPopup)viewControl;

            int     taskIndex     = 1;
            Boolean commandExists = false;

            //Add a control for the command to the view menu:
            if (viewPopup != null)
            {
                for (int i = 0; i < viewPopup.CommandBar.Controls.Count; i++)
                {
                    try
                    {
                        // Find the location of the standard task list - make sure the upgraded task list is just above it
                        if (viewPopup.CommandBar.Controls[i].Caption.Equals("Tas&k List"))
                        {
                            taskIndex = i;
                        }
                        if (viewPopup.CommandBar.Controls[i].Caption.Equals("Upgraded Task List"))
                        {
                            commandExists = true;
                        }
                    }
                    catch { }
                }
            }

            // If the command doesn't already exist, add it to the menu
            if (!commandExists)
            {
                //Add a command to the Commands collection:
                Command command = commands.AddNamedCommand2(_addInInstance,
                                                            "UpgradedTaskList",
                                                            "Upgraded Task List",
                                                            "Executes the command for ToolWindowArticle",
                                                            true,
                                                            837,
                                                            ref contextGUIDS,
                                                            (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                                                            (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                command.AddControl(viewPopup.CommandBar, taskIndex);
            }
        }
        private CommandBarPopup GetMainMenuPopup(string targetMenuEnglishName)
        {
            //template-generated code to find the localized name of the target menu
            //MODIFIED: the template code did not account for cases where the target language is not specified in the "CommandBar" resource
            // file, (eg Portuguese or Russian) so (as a cheap hack-ish solution) we create the menu if it doesn't exist.

            string localMenuName = null;

            try
            {
                string          resourceName;
                ResourceManager resourceManager = new ResourceManager(typeof(AddinConnector).Namespace + ".CommandBar", Assembly.GetExecutingAssembly());
                CultureInfo     cultureInfo     = new CultureInfo(_applicationObject.LocaleID);

                //no idea why the two-letter ISO language name was not specific enough (or too specific??) for chinese... this comes from the VS2008 template
                if (cultureInfo.TwoLetterISOLanguageName == "zh")
                {
                    resourceName = String.Concat(cultureInfo.Parent.Name, targetMenuEnglishName);
                }
                else
                {
                    resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, targetMenuEnglishName);
                }

                localMenuName = resourceManager.GetString(resourceName);
            }
            catch
            {
                //Something went wrong with resource handling. In the absence of logging / error-reporting framework, just
                // swallow the error and act same as if we didn't have that language in the resources file (leave null).
            }

            //Find the MenuBar command bar, which is the top-level command bar holding all the main menu items; its name is always consistent (apparently)
            Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"];

            CommandBarPopup targetPopupMenu = null;

            //try to find the target menu entry on the menu bar, using the localized name
            if (!string.IsNullOrEmpty(localMenuName))
            {
                targetPopupMenu = GetCommandBarControlOrNull(menuBarCommandBar.Controls, localMenuName);
            }

            //if there was no local name, or the menu entry was not found using the local name, try English
            if (targetPopupMenu == null)
            {
                targetPopupMenu = GetCommandBarControlOrNull(menuBarCommandBar.Controls, targetMenuEnglishName);
            }

            //if the menu entry still wasn't found, then create it (temporarily) using English. A more elegant long-term solution
            // might be to ask the user, but that would also be much more complicated. Let's see whether anyone cares.
            if (targetPopupMenu == null)
            {
                int newEntryPosition = menuBarCommandBar.Controls.Count - 2; //leave space for "Window" and "Help".
                targetPopupMenu = (CommandBarPopup)menuBarCommandBar.Controls.Add(MsoControlType.msoControlPopup, System.Type.Missing, System.Type.Missing, newEntryPosition, true);
                targetPopupMenu.CommandBar.Name = targetMenuEnglishName;
                targetPopupMenu.Caption         = targetMenuEnglishName;
            }

            return(targetPopupMenu);
        }
        /// <summary>Create our menu items.</summary>
        private void createMenus()
        {
            try
            {
                this.logMessage("Connect::createMenus()", System.Diagnostics.EventLogEntryType.Information);

                object[]  contextGUIDS  = new object[] { };
                Commands2 commands      = (Commands2)_applicationObject.Commands;
                string    toolsMenuName = "";

                // Get the localized name for the 'View' menu.
                try
                {
                    this.logMessage("Connect::createMenus  Get Menuname", System.Diagnostics.EventLogEntryType.Information);
                    string          resourceName;
                    ResourceManager resourceManager = new ResourceManager("Inflectra.SpiraTest.IDEIntegration.VisualStudio.Resources.CommandBar", Assembly.GetExecutingAssembly());
                    CultureInfo     cultureInfo     = new CultureInfo(_applicationObject.LocaleID);

                    if (cultureInfo.TwoLetterISOLanguageName == "zh")
                    {
                        System.Globalization.CultureInfo parentCultureInfo = cultureInfo.Parent;
                        resourceName = this._resources.GetString("strMenuName");
                    }
                    else
                    {
                        resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, this._resources.GetString("strMenuName"));
                    }
                    toolsMenuName = resourceManager.GetString(resourceName);
                }
                catch (Exception ex)
                {
                    Connect.logEventMessage("Connect::createMenus  Get Menuname", ex, System.Diagnostics.EventLogEntryType.Error);
                }

                this.logMessage("Connect::createMenu  toolsMenuName: \"" + toolsMenuName + "\"", System.Diagnostics.EventLogEntryType.Information);

                //Get the main menubar & View submenu.
                Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"];
                CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName];
                CommandBarPopup   toolsPopup   = (CommandBarPopup)toolsControl;

                this.logMessage("Connect::createMenu  Add named Command", System.Diagnostics.EventLogEntryType.Information);

                //Create the command.
                Command viewTree = commands.AddNamedCommand2(
                    _addInInstance,
                    "viewTree",
                    this._resources.GetString("mnuViewTreeBtn"),
                    this._resources.GetString("mnuViewTreeTip"),
                    false,
                    2,
                    ref contextGUIDS,
                    (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                    (int)vsCommandStyle.vsCommandStylePictAndText,
                    vsCommandControlType.vsCommandControlTypeButton
                    );
                //Add the commands to the menu bar.
                this.logMessage("Connect::createMenu  Add to Toolbar", System.Diagnostics.EventLogEntryType.Information);
                try
                {
                    if (toolsPopup.CommandBar != null)
                    {
                        if (viewTree != null)
                        {
                            viewTree.AddControl(toolsPopup.CommandBar, 1);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Connect.logEventMessage("Connect::createMenu  Add to Toolbar", ex, System.Diagnostics.EventLogEntryType.Error);
                }
            }
            catch (Exception ex)
            {
                Connect.logEventMessage("Connect::createMenu", ex, System.Diagnostics.EventLogEntryType.Error);
            }
            #region For A Submenu, not used.
            ////Find the 'Spirateam Integration' command bar, or create a new one.
            //Microsoft.VisualStudio.CommandBars.CommandBar spiraCommandBar = null;
            //try
            //{
            //    spiraCommandBar = ( (Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars )[Branding.strMenuView];
            //}
            //catch
            //{
            //    //If this threw an error, we need to create a new one.
            //    spiraCommandBar = (Microsoft.VisualStudio.CommandBars.CommandBar)commands.AddCommandBar(
            //        Branding.strMenuView,
            //        vsCommandBarType.vsCommandBarTypeMenu,
            //        toolsPopup.CommandBar,
            //        1);
            //}

            ////Create the two commands.
            //Command viewTree = commands.AddNamedCommand2(
            //    _addInInstance,
            //    "viewTree",
            //    Generic.mnuViewTreeBtn,
            //    Generic.mnuViewTreeTip,
            //    true,
            //    10,
            //    ref contextGUIDS,
            //    (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
            //    (int)vsCommandStyle.vsCommandStylePictAndText,
            //    vsCommandControlType.vsCommandControlTypeButton
            //    );
            //Command viewDetail = commands.AddNamedCommand2(
            //    _addInInstance,
            //    "viewDetail",
            //    Generic.mnuViewDetailBtn,
            //    Generic.mnuViewDetailTip,
            //    true,
            //    13,
            //    ref contextGUIDS,
            //    (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
            //    (int)vsCommandStyle.vsCommandStylePictAndText,
            //    vsCommandControlType.vsCommandControlTypeButton
            //    );

            ////Add the commands to the menu bar.
            //try
            //{
            //    if (spiraCommandBar != null)
            //    {
            //        if (viewTree != null) viewTree.AddControl(spiraCommandBar, 1);
            //        if (viewDetail != null) viewDetail.AddControl(spiraCommandBar, 2);
            //    }

            //}
            //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.
            //}

            #endregion
        }
Esempio n. 26
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;

            executeSqlEvents = _applicationObject.Events.CommandEvents["{52692960-56BC-4989-B5D3-94C47A513E8D}", 1];
            executeSqlEvents.BeforeExecute += ExecuteSqlEventsBeforeExecute;
            executeSqlEvents.AfterExecute  += ExecuteSqlEventsAfterExecute;


            if (connectMode == ext_ConnectMode.ext_cm_Startup)
            {
                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:
                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;

                CommandBarPopup _ourAddinMenu = menuBarCommandBar.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, toolsControl.Index, true) as CommandBarPopup;
                _ourAddinMenu.Caption = "My Addin Toolbar Item";

                //Create our custom command bar
                CommandBarButton ourCustomToolbarButton;
                CommandBars      cmdBars = (CommandBars)_applicationObject.CommandBars;

                ourCustomToolbar = cmdBars.Add("Our add-in Toolbar", MsoBarPosition.msoBarTop, System.Type.Missing, true);

                //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, "MyAddin1", "Make A New Query", "Executes the command for MyAddin1", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    Command command2 = commands.AddNamedCommand2(_addInInstance, "MyAddin1ToolWindowForm", "Popup window", "Opens Popup", 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(_ourAddinMenu.CommandBar, 1);
                    }

                    if ((command2 != null) && (toolsPopup != null))
                    {
                        command2.AddControl(_ourAddinMenu.CommandBar, 2);

                        //Attach our command to the command bar
                        ourCustomToolbarButton       = (CommandBarButton)command2.AddControl(ourCustomToolbar, ourCustomToolbar.Controls.Count + 1);
                        ourCustomToolbarButton.Style = MsoButtonStyle.msoButtonIconAndCaption;
                        ourCustomToolbar.Visible     = true;
                    }
                }
                catch (System.ArgumentException e)
                {
                    //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.
                }
            }
        }
Esempio n. 27
0
        /// <summary>实现 IDTExtensibility2 接口的 OnConnection 方法。接收正在加载外接程序的通知。</summary>
        /// <param term='application'>宿主应用程序的根对象。</param>
        /// <param term='connectMode'>描述外接程序的加载方式。</param>
        /// <param term='addInInst'>表示此外接程序的对象。</param>
        /// <seealso class='IDTExtensibility2' />
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            m_applicationObject = (DTE2)application;
            m_addInInstance     = (AddIn)addInInst;

            if ((connectMode == ext_ConnectMode.ext_cm_Startup || connectMode == ext_ConnectMode.ext_cm_AfterStartup) && m_socket == null)
            {
                initializeCallback();

                object [] contextGUIDS  = new object[] { };
                Commands2 commands      = (Commands2)m_applicationObject.Commands;
                string    toolsMenuName = "Tools";

                //将此命令置于“工具”菜单上。
                //查找 MenuBar 命令栏,该命令栏是容纳所有主菜单项的顶级命令栏:
                Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)m_applicationObject.CommandBars)["MenuBar"];

                //在 MenuBar 命令栏上查找“工具”命令栏:
//                  CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName];
//                  CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl;

                m_menuBarObj         = menuBarCommandBar.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, Type.Missing, true);
                m_menuBarObj.Caption = "Code Atlas";
                CommandBarPopup toolsPopup = (CommandBarPopup)m_menuBarObj;

                // 增加工具栏
                //m_toolBarObj = m_applicationObject.Commands.AddCommandBar("Code Atlas Tools", vsCommandBarType.vsCommandBarTypeToolbar);

                //如果希望添加多个由您的外接程序处理的命令,可以重复此 try/catch 块,
                //  只需确保更新 QueryStatus/Exec 方法,使其包含新的命令名。
                try
                {
                    foreach (Command cmd in commands)
                    {
                        foreach (CommandObj cmdObj in m_commandList)
                        {
                            if (cmd.Name == "CodeAtlas.Connect." + cmdObj.name)
                            {
                                cmdObj.command = cmd;
                            }
                        }
                    }

                    int nCommand = m_commandList.Length;
                    for (int ithCmd = 0; ithCmd < nCommand; ++ithCmd)
                    {
                        if (m_commandList[ithCmd].command == null)
                        {
                            m_commandList[ithCmd].command = commands.AddNamedCommand2(
                                m_addInInstance,
                                m_commandList[ithCmd].name,
                                m_commandList[ithCmd].displayName,
                                "Executes the command for CodeAtlas",
                                false, Type.Missing, ref contextGUIDS,
                                (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                                (int)vsCommandStyle.vsCommandStyleText,
                                vsCommandControlType.vsCommandControlTypeButton);
                        }
                        Command cmd = m_commandList[ithCmd].command;

                        //将对应于该命令的控件添加到“工具”菜单:
                        cmd.AddControl(toolsPopup.CommandBar, ithCmd + 1);
                        //cmd.AddControl(m_toolBarObj, ithCmd + 1);
                        string key = m_commandList[ithCmd].key;
                        if (key != null && key.Length > 0)
                        {
                            cmd.Bindings = key;
                            //cmd.Bindings = "文本编辑器::alt+LEFT";
                        }
                    }
                }
                catch (System.ArgumentException exception)
                {
                    //如果出现此异常,原因很可能是由于具有该名称的命令
                    //  已存在。如果确实如此,则无需重新创建此命令,并且
                    //  可以放心忽略此异常。
                }
                m_socket = new SocketThread("127.0.0.1", 12346, "127.0.0.1", 12345, onSocketCallback);
                m_socket.run();
            }
        }
        private void AddPermanentUI()
        {
            object[]  contextGUIDS = new object[] { };
            Commands2 commands     = (Commands2)applicationObject.Commands;

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

            //Find the Tools command bar on the MenuBar command bar:
            CommandBarControl toolsControl = menuBarCommandBar.Controls["File"];
            CommandBarPopup   toolsPopup   = (CommandBarPopup)toolsControl;
            CommandBar        oBar         = null;
            CommandBarButton  oBtn         = null;

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

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

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

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

                //User Code End
            }
            catch (System.ArgumentException)
            {
                // If we are here, then the exception is probably
                // because a command with that name already exists.
                // If so there is no need to recreate the command and we can
                // safely ignore the exception.
            }
        }
Esempio n. 29
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)
        {
            try
            {
                settingsObject = new Settings();
                if (IfSolutionPathExists())
                {
                    MessageBox.Show(string.Format("SolutionPath exists already.{0}{1}{2}{3}",
                                                  Environment.NewLine, settingsObject.TableSolutionPath, Environment.NewLine, "Delete SolutionPath then try again."),
                                    "Canceling Run");
                    return;
                }

                _applicationObject = (DTE2)application;
                _addInInstance     = (AddIn)addInInst;

                SetupOutputWindow(_applicationObject);
                startTime = DateTime.Now.ToLongTimeString();


                // Create generator
                codeGenerator = new CodeGenerator(_applicationObject);

                // Event Handlers
                MessageService.MessageGenerated    += new MessageService.MessageGeneratedEventHandler(MessageWriter_MessageGenerated);
                CodeGenerator.T4TransformCompleted += TemplatesGenerator_T4TransformCompleted;

                // CodeGeneration Part 1
                // Part 2 after TransformAllT4Templates
                codeGenerator.CreateTableSolution();
                codeGenerator.RenameT4Templates();
                codeGenerator.ReplaceInT4Templates();
                codeGenerator.TransformAllT4Templates();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "CodeGeneration Part 1 failed");
            }

            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:
                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, "PrismTable", "PrismTable", "Executes the command for PrismTable", 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.
                }
            }
        }