Example #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public bool startup(string json)
        {
            object[] contextGUIDS = new object[] { };
            Commands2 commands = _dte.Commands as Commands2;
            CommandBar menuBar = (_dte.CommandBars as CommandBars)["MenuBar"];

            try
            {
                int index = 9;
                foreach (CommandBarControl control in menuBar.Controls)
                {
                    if (control.Type == MsoControlType.msoControlPopup)
                    {
                        CommandBarPopup temp = control as CommandBarPopup;
                        if (temp.CommandBar.Name == "Tools")
                        {
                            index = temp.Index + 1;
                            break;
                        }
                    }
                }
                CommandBarPopup popup = menuBar.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, index, true) as CommandBarPopup;
                popup.CommandBar.Name = "Emmet";
                popup.Caption = "E&mmet";
                CommandBar commandBar = popup.CommandBar;
                Command command = null;
                CommandBarButton button = null;

                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Action[]));
                MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(json));
                Action[] actions = serializer.ReadObject(stream) as Action[];

                foreach (var action in actions)
                {
                    if (action.type == "action")
                    {
                        command = commands.AddNamedCommand2(_addIn, action.name, action.label, action.label, false, Type.Missing, ref contextGUIDS, 1);
                        button = command.AddControl(commandBar, commandBar.Controls.Count + 1) as CommandBarButton;
                    }
                    else
                    {
                        CommandBar control = commands.AddCommandBar(action.name, vsCommandBarType.vsCommandBarTypeMenu, commandBar, commandBar.Controls.Count + 1) as CommandBar;
                        if (action.items != null)
                        {
                            foreach (var item in action.items)
                            {
                                command = commands.AddNamedCommand2(_addIn, item.name, item.label, item.label, false, Type.Missing, ref contextGUIDS, 1);
                                button = command.AddControl(control, control.Controls.Count + 1) as CommandBarButton;
                            }
                        }
                    }
                }
                popup.Visible = true;
            }
            catch
            {
                return false;
            }
            return true;
        }
Example #2
0
        public void create_popup_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
            )
        {
            object[]        contextGUIDS = new object[] { };
            BARS.CommandBar host_bar     = ((BARS.CommandBars)_ssms.DTE2.CommandBars)[host_menu_bar_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);
            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)
        {
            _addInInstance     = (AddIn)addInInst;
            _applicationObject = (DTE2)_addInInstance.DTE;

            if (connectMode == ext_ConnectMode.ext_cm_UISetup || connectMode == ext_ConnectMode.ext_cm_Startup)
            {
                _SSMSHelper = new GenericVSHelper(_applicationObject.RegistryRoot.StartsWith(@"Software\Microsoft\VisualStudio"), new GenericVSHelper.GetTextEditorKeyBindingScopeName(GetTextEditorKeyBindingScopeName), new GenericVSHelper.GetKeyBinding(GetFormatCommandKeyBinding), new GenericVSHelper.SetKeyBinding(SetFormatCommandKeyBinding));

                object []       contextGUIDS = new object[] { };
                Commands2       commandsList = (Commands2)_applicationObject.Commands;
                CommandBarPopup targetPopup  = GetMainMenuPopup("Tools");

                //remove old commands
                List <string> oldCommandNames = new List <string>();
                oldCommandNames.Add("PoorMansTSqlFormatterSSMSAddIn.Connect.PoorMansTSqlFormatterSSMSAddIn");
                oldCommandNames.Add("PoorMansTSqlFormatterSSMSAddIn.AddinConnector.FormatSelectionOrActiveWindow");
                oldCommandNames.Add("PoorMansTSqlFormatterSSMSAddIn.AddinConnector.FormattingOptions");
                RemoveCommands(commandsList, oldCommandNames);

                //add new commands
                Command formatCommand = commandsList.AddNamedCommand2(
                    _addInInstance,
                    "FormatSelectionOrActiveWindow",
                    _SSMSHelper.GeneralResourceManager.GetString("FormatButtonText"),
                    _SSMSHelper.GeneralResourceManager.GetString("FormatButtonToolTip"),
                    true,
                    59,
                    ref contextGUIDS,
                    (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                    (int)vsCommandStyle.vsCommandStyleText,
                    vsCommandControlType.vsCommandControlTypeButton
                    );
                if ((formatCommand != null) && (targetPopup != null))
                {
                    formatCommand.AddControl(targetPopup.CommandBar, 1);
                }
                _formatCommand = formatCommand;
                _SSMSHelper.UpdateSettingsHotkeyIntoVS();

                Command optionsCommand = commandsList.AddNamedCommand2(
                    _addInInstance,
                    "FormattingOptions",
                    _SSMSHelper.GeneralResourceManager.GetString("OptionsButtonText"),
                    _SSMSHelper.GeneralResourceManager.GetString("OptionsButtonToolTip"),
                    true,
                    59,
                    ref contextGUIDS,
                    (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                    (int)vsCommandStyle.vsCommandStyleText,
                    vsCommandControlType.vsCommandControlTypeButton
                    );
                if ((optionsCommand != null) && (targetPopup != null))
                {
                    optionsCommand.AddControl(targetPopup.CommandBar, 2);
                }
            }
        }
Example #4
0
        /// <summary>Environment situation established here.</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>
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            _addInInstance     = (AddIn)addInInst;
            _applicationObject = (DTE2)_addInInstance.DTE;
            if (connectMode == ext_ConnectMode.ext_cm_UISetup || connectMode == ext_ConnectMode.ext_cm_Startup)
            {
                object []       contextGUIDS = new object[] { };
                Commands2       commandsList = (Commands2)_applicationObject.Commands;
                CommandBarPopup targetPopup  = GetMainMenuPopup("Tools");

                //remove old commands
                List <string> oldCommandNames = new List <string>();
                oldCommandNames.Add("PoorMansTSqlFormatterSSMSAddIn.Connect.PoorMansTSqlFormatterSSMSAddIn");
                oldCommandNames.Add("PoorMansTSqlFormatterSSMSAddIn.AddinConnector.FormatSelectionOrActiveWindow");
                oldCommandNames.Add("PoorMansTSqlFormatterSSMSAddIn.AddinConnector.FormattingOptions");
                RemoveCommands(commandsList, oldCommandNames);

                //add new commands
                Command formatCommand = commandsList.AddNamedCommand2(
                    _addInInstance,
                    "FormatSelectionOrActiveWindow",
                    _generalResourceManager.GetString("FormatButtonText"),
                    _generalResourceManager.GetString("FormatButtonToolTip"),
                    true,
                    59,
                    ref contextGUIDS,
                    (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                    (int)vsCommandStyle.vsCommandStyleText,
                    vsCommandControlType.vsCommandControlTypeButton
                    );
                if ((formatCommand != null) && (targetPopup != null))
                {
                    formatCommand.AddControl(targetPopup.CommandBar, 1);
                }
                _formatCommand = formatCommand;
                SetFormatHotkey();

                Command optionsCommand = commandsList.AddNamedCommand2(
                    _addInInstance,
                    "FormattingOptions",
                    _generalResourceManager.GetString("OptionsButtonText"),
                    _generalResourceManager.GetString("OptionsButtonToolTip"),
                    true,
                    59,
                    ref contextGUIDS,
                    (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                    (int)vsCommandStyle.vsCommandStyleText,
                    vsCommandControlType.vsCommandControlTypeButton
                    );
                if ((optionsCommand != null) && (targetPopup != null))
                {
                    optionsCommand.AddControl(targetPopup.CommandBar, 2);
                }
            }
        }
        /// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary>
        /// <param term='application'>Root object of the host application.</param>
        /// <param term='connectMode'>Describes how the Add-in is being loaded.</param>
        /// <param term='addInInst'>Object representing this Add-in.</param>
        /// <seealso class='IDTExtensibility2' />
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            _applicationObject = (DTE2)application;
            _addInInstance     = (AddIn)addInInst;

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

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

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

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

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

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

                    // Create the omega button command, specifying the command name, button text, tooltip, bitmap image,
                    // status, style, and control type.  Add this command to the AlphaToolbar.
                    commandOmega = commands.AddNamedCommand2(_addInInstance, "OmegaButton", "Omega", "Omega Command", false, omega, ref contextGUIDS,
                                                             (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                }
                commandOmega.AddControl(toolbar, 2);
            }
        }
Example #6
0
        void OnSolutionOpened()
        {
            object[]  contextGUIDS  = new object[] { };
            Commands2 commands      = (Commands2)_applicationObject.Commands;
            string    debugMenuName = "Debug";

            //Place the command on the debug 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 Debug command bar on the MenuBar command bar:
            CommandBarControl debugControl = menuBarCommandBar.Controls[debugMenuName];
            CommandBarPopup   debugPopup   = (CommandBarPopup)debugControl;

            //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:
                _commandBreakAll  = commands.AddNamedCommand2(_addInInstance, "BreakAll", "Set Class Breakpoint", "Sets a breakpoint for each member of each class in the current file", true, Type.Missing, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                _commandBreakNone = commands.AddNamedCommand2(_addInInstance, "BreakNone", "Delete All Breakpoints In File", "Deletes all breakpoints in the current file", true, Type.Missing, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                int position = 1;
                foreach (CommandBarControl command in debugPopup.CommandBar.Controls)
                {
                    position++;
                    if (command.accName.ToLower().Contains("disable all breakpoints"))
                    {
                        break;
                    }
                }

                //Add a control for the command to the tools menu:
                if ((_commandBreakAll != null) && (_commandBreakNone != null) && (debugPopup != null))
                {
                    _commandBreakAll.AddControl(debugPopup.CommandBar, position);
                    _commandBreakNone.AddControl(debugPopup.CommandBar, position);
                }

                _commandBreakAll.Bindings  = "Text Editor::ctrl+d, z";
                _commandBreakNone.Bindings = "Text Editor::ctrl+d, x";
            }
            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.
            }
        }
Example #7
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;

                try {
                    CommandBar        menuBarCommandBar;
                    CommandBarControl toolsControl;
                    CommandBarPopup   toolsPopup;
                    CommandBarControl commandBarControl;

                    //Add a command to the Commands collection:
                    Command command = commands.AddNamedCommand2(addInInstance, "PasteXmlAsLinq", "Paste XML as XElement", "Pastes the XML on the clipboard as C# Linq To Xml code", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    String editMenuName;

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

                    try {
                        //  This code will take the culture, append on the name of the menuitem,
                        //  then add the command to the menu. You can find a list of all the top-level menus in the file
                        //  CommandBar.resx.
                        System.Resources.ResourceManager resourceManager = new System.Resources.ResourceManager("PasteXmlAsLinq.CommandBar", System.Reflection.Assembly.GetExecutingAssembly());
                        System.Threading.Thread          thread          = System.Threading.Thread.CurrentThread;
                        System.Globalization.CultureInfo cultureInfo     = thread.CurrentUICulture;
                        editMenuName = resourceManager.GetString(String.Concat(cultureInfo.TwoLetterISOLanguageName, "Edit"));
                        toolsControl = menuBarCommandBar.Controls["Edit"];
                    }
                    catch (Exception) {
                        //  We tried to find a localized version of the word Edit, but one was not found.
                        //  Default to the en-US word, which may work for the current culture.
                        toolsControl = menuBarCommandBar.Controls["Edit"];
                    }

                    //Place the command on the edit menu.
                    toolsPopup = (CommandBarPopup)toolsControl;
                    int pasteControlIndex = 1;

                    //Find the paste control so that the new element can be added after it.
                    foreach (CommandBarControl commandBar in toolsPopup.CommandBar.Controls)
                    {
                        if (String.Compare(commandBar.Caption, "&Paste", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            pasteControlIndex = commandBar.Index + 1;
                            break;
                        }
                    }

                    //Find the appropriate command bar on the MenuBar command bar:
                    commandBarControl = (CommandBarControl)command.AddControl(toolsPopup.CommandBar, pasteControlIndex);
                }
                catch (Exception) {
                }
            }
        }
Example #8
0
        /// <summary>
        /// Adds a new Command and creates a new CommandBar control both of which
        /// can be returned via the AddCommandReturn object that holds refs to both.
        /// </summary>
        /// <param name="name">The name of the Command. Must be handled in the Addin</param>
        /// <param name="caption">The Caption</param>
        /// <param name="description">Tooltip Text</param>
        /// <param name="iconId">Icon Id if you use a custom icon. Otherwise use 0</param>
        /// <param name="commandBar">The Command bar that this command will attach to</param>
        /// <param name="insertionIndex">The InsertionIndex for this CommandBar</param>
        /// <param name="beginGroup">Are we starting a new group on the toolbar (above)</param>
        /// <param name="hotKey">Optional hotkey. Format: "Global::alt+f1"</param>
        /// <returns>AddCommandReturn object that contains a Command and CommandBarControl object that were created</returns>
        private void AddCommand(string name, string caption, string description,
                                int iconId, CommandBar commandBar, int insertionIndex,
                                bool beginGroup, string hotKey)
        {
            object[] contextGuids = new object[] { };

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

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

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

            cb.BeginGroup = beginGroup;
        }
        /// <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;
            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)["Solution"];

                //如果希望添加多个由您的外接程序处理的命令,可以重复此 try/catch 块,
                //  只需确保更新 QueryStatus/Exec 方法,使其包含新的命令名。
                try
                {
                    //将一个命令添加到 Commands 集合:
                    Command command = commands.AddNamedCommand2(_addInInstance, "ReadOnlyCleaner", "移除只读属性", "移除解决方案下所有文件的只读属性", true, 58, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    //将对应于该命令的控件添加到“工具”菜单:
                    if ((command != null))
                    {
                        command.AddControl(menuBarCommandBar, 1);
                    }
                }
                catch (System.ArgumentException)
                {
                    //如果出现此异常,原因很可能是由于具有该名称的命令
                    //  已存在。如果确实如此,则无需重新创建此命令,并且
                    //  可以放心忽略此异常。
                }
            }
        }
Example #10
0
        /// <summary>Реализация метода OnConnection интерфейса IDTExtensibility2. Получение уведомления о загрузке надстройки.</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;
            if (ConnectMode == ext_ConnectMode.ext_cm_UISetup)
            {
                object[]  contextGUIDS = new object[] { };
                Commands2 commands     = (Commands2)applicationObject.Commands;

                try {
                    CommandBar        menuBarCommandBar;
                    CommandBarControl toolsControl;
                    CommandBarPopup   toolsPopup;
                    CommandBarControl commandBarControl;

                    //Добавление команды в коллекцию Commands:
                    Command command = commands.AddNamedCommand2(addInInstance, "PasteXmlAsLinq", "Paste XML as XElement", "Pastes the XML on the clipboard as C# Linq To Xml code", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    String editMenuName;

                    //Поиск панели команд верхнего уровня MenuBar, в которой содержатся все элементы главного меню:
                    menuBarCommandBar = ((CommandBars)applicationObject.CommandBars)["MenuBar"];

                    try {
                        //  С помощью этого кода можно получить региональный язык и региональные параметры, добавить имя элемента меню,
                        //  а затем добавить команду в меню. Список всех меню верхнего уровня можно найти в файле
                        //  CommandBar.resx.
                        System.Resources.ResourceManager resourceManager = new System.Resources.ResourceManager("PasteXmlAsLinq.CommandBar", System.Reflection.Assembly.GetExecutingAssembly());
                        System.Threading.Thread          thread          = System.Threading.Thread.CurrentThread;
                        System.Globalization.CultureInfo cultureInfo     = thread.CurrentUICulture;
                        editMenuName = resourceManager.GetString(String.Concat(cultureInfo.TwoLetterISOLanguageName, "Edit"));
                        toolsControl = menuBarCommandBar.Controls["Edit"];
                    }
                    catch (Exception) {
                        //  Мы пытаемся найти локализованную версию слова Edit, но безуспешно.
                        //  По умолчанию текст установлен в формат en-US, для используемого языка и региональных параметров этот вариант может оказаться приемлемым.
                        toolsControl = menuBarCommandBar.Controls["Edit"];
                    }

                    //Размещение команды в меню редактирования.
                    toolsPopup = (CommandBarPopup)toolsControl;
                    int pasteControlIndex = 1;

                    //Поиск элемента управления вставкой для добавления после него нового элемента.
                    foreach (CommandBarControl commandBar in toolsPopup.CommandBar.Controls)
                    {
                        if (String.Compare(commandBar.Caption, "&Paste", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            pasteControlIndex = commandBar.Index + 1;
                            break;
                        }
                    }

                    //Поиск подходящей панели команд на панели MenuBar:
                    commandBarControl = (CommandBarControl)command.AddControl(toolsPopup.CommandBar, pasteControlIndex);
                }
                catch (Exception) {
                }
            }
        }
Example #11
0
        /// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary>
        /// <param term='application'>Root object of the host application.</param>
        /// <param term='connectMode'>Describes how the Add-in is being loaded.</param>
        /// <param term='addInInst'>Object representing this Add-in.</param>
        /// <seealso class='IDTExtensibility2' />
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            _applicationObject = (DTE2)application;
            _addInInstance     = (AddIn)addInInst;

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

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

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

                    //Add a control for the command to the tools menu:
                    if ((command != null) && (commandBar != null))
                    {
                        //command.AddControl(toolsPopup.CommandBar, 1);
                        command.AddControl(commandBar, 1);
                    }
                    Buisness.InteractWindow.OpenPendingChangesWindow((CommandBars)_applicationObject.CommandBars);
                }
                catch (System.ArgumentException)
                {
                    //If we are here, then the exception is probably because a command with that name
                    //  already exists. If so there is no need to recreate the command and we can
                    //  safely ignore the exception.
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="VSMenuCommand"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="displayName">The display name.</param>
        /// <param name="description">The description.</param>
        public VSMenuCommand(VSMenu menu, string name, string displayName, string description)
        {
            _menu        = menu;
            _name        = name;
            _displayName = displayName;
            _description = description;

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

            Commands2 commands = (Commands2)menu.VSAddin.ApplicationObject.Commands;

            try
            {
                _command = commands.AddNamedCommand2(menu.VSAddin.AddInInstance,
                                                     name, displayName, description,
                                                     true, 0, ref contextGUIDS,
                                                     (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                                                     (int)vsCommandStyle.vsCommandStylePictAndText,
                                                     vsCommandControlType.vsCommandControlTypeButton);
            }
            catch
            {
                // If we get here then the command name probably already exists.
                _command = commands.Item(menu.VSAddin.AddInInstance.ProgID + "." + name, 0);
            }

            _button = (CommandBarButton)_command.AddControl(_menu.Popup.CommandBar, 1);
        }
Example #13
0
        private void AddGenerateCodeBtn()
        {
            Command findCommand = null;

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

            if (findCommand == null)
            {
                findCommand = commands.AddNamedCommand2(
                    _addInInstance,
                    "GenerateCode",
                    "GenerateCode",
                    "GenerateCode",
                    true,
                    59,
                    ref contextUIGuids,
                    (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
            }
            if (findCommand != null)
            {
                //解决方案
                CommandBar codeWindowCommandBar3 = cmdBars["Project"];
                if (codeWindowCommandBar3 != null)
                {
                    findCommandBarButtonButton = (CommandBarButton)findCommand.AddControl(
                        codeWindowCommandBar3, codeWindowCommandBar3.Controls.Count + 1);
                    findCommandBarButtonButton.Caption = "rx_orm 强类型开发设置";
                }
            }
        }
Example #14
0
 private Command GetNewCommandAddedToDTECommands2(Commands2 commands, object[] contextGUIDS)
 {
     return
         (commands.AddNamedCommand2(addIn, TOOLS_COMMAND_NAME, RECORDER_ADD_IN_TOOLS_MENU_ITEM_NAME, TOOLS_COMMAND_DESCRIPTION, true, null,
                                    ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                                    (int)vsCommandStyle.vsCommandStyleText, vsCommandControlType.vsCommandControlTypeButton));
 }
Example #15
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;

                //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, "LastTab", "Reopen closed tab", "Opens the file that was most recently closed", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    if (command != null)
                    {
                        command.Bindings = new object[2]
                        {
                            "Global::Ctrl+Shift+T",
                            "Text Editor::Ctrl+Shift+T"
                        };
                    }
                }
                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.
                }
            }
        }
Example #16
0
        /// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary>
        /// <param term='application'>Root object of the host application.</param>
        /// <param term='connectMode'>Describes how the Add-in is being loaded.</param>
        /// <param term='addInInst'>Object representing this Add-in.</param>
        /// <seealso class='IDTExtensibility2' />
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            _applicationObject = (DTE2)application;
            _addInInstance = (AddIn)addInInst;
            if (connectMode == ext_ConnectMode.ext_cm_UISetup)
            {
                object[] contextGUIDS = new object[] { };
                Commands2 commands = (Commands2)_applicationObject.Commands;
                Command command = null;

                try
                {
                    command = commands.AddNamedCommand2(
                        _addInInstance,
                        "CSVSAddInToolboxItem",
                        "CSVSAddInToolboxItem",
                        "Add item into VS Toolbox",
                        true,
                        6743,
                        ref contextGUIDS,
                        (int)vsCommandStatus.vsCommandStatusSupported
                        + (int)vsCommandStatus.vsCommandStatusEnabled,
                        (int)vsCommandStyle.vsCommandStylePictAndText,
                        vsCommandControlType.vsCommandControlTypeButton);
                }
                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.
                }

                AddCommandToToolMenubar(_applicationObject, command);
            }
        }
Example #17
0
        private void AddItemCommand(string name, string text, object bindings, int position, int faceId, bool beginGroup)
        {
            object[]    contextGUIDS = new object[] { };
            Commands2   commands     = (Commands2)_applicationObject.Commands;
            CommandBars commandBars  = ((CommandBars)_applicationObject.CommandBars);

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

            try
            {
                Command command = commands.AddNamedCommand2(_addInInstance, name, text, null, true, faceId, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                if (bindings != null)
                {
                    command.Bindings = bindings;
                }
                if (command != null)
                {
                    foreach (CommandBar bar in targetBars)
                    {
                        CommandBarButton button = (CommandBarButton)command.AddControl(bar, position);
                        button.BeginGroup = beginGroup;
                    }
                }
            }
            catch (ArgumentException)
            {
            }
        }
Example #18
0
        public static Command add_NamedCommand(this CommandBarPopup commandBarPopup,
                                               DTE2 dte2, AddIn addIn, string Name,
                                               string ButtonText, string ToolTip,
                                               bool MSOButton, object Bitmap)
        {
            object[]  contextGUIDS = new object[] { };
            Commands2 commands     = (Commands2)dte2.Commands;

            Command command = commands.AddNamedCommand2(addIn,
                                                        Name,
                                                        ButtonText,
                                                        ToolTip,
                                                        MSOButton,
                                                        Bitmap,
                                                        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) && (commandBarPopup != null))
            {
                command.AddControl(commandBarPopup.CommandBar, 1);
                return(command);
            }
            return(null);
        }
Example #19
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;
            if (ConnectMode == ext_ConnectMode.ext_cm_UISetup)
            {
                object[]  contextGUIDS = new object[] { };
                Commands2 commands     = (Commands2)applicationObject.Commands;

                try {
                    CommandBar        menuBarCommandBar;
                    CommandBarControl toolsControl;
                    CommandBarPopup   toolsPopup;
                    CommandBarControl commandBarControl;

                    //将一个命令添加到 Commands 集合:
                    Command command = commands.AddNamedCommand2(addInInstance, "PasteXmlAsLinq", "Paste XML as XElement", "Pastes the XML on the clipboard as C# Linq To Xml code", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    String editMenuName;

                    //查找 MenuBar 命令栏,该命令栏是容纳所有主菜单项的顶级命令栏:
                    menuBarCommandBar = ((CommandBars)applicationObject.CommandBars)["MenuBar"];

                    try {
                        //  此代码将获取区域性,将其追加到菜单项的名称中,
                        //  然后将此命令添加到菜单中。您可以在以下文件中看到全部顶级菜单的列表:
                        //  CommandBar.resx.
                        System.Resources.ResourceManager resourceManager = new System.Resources.ResourceManager("PasteXmlAsLinq.CommandBar", System.Reflection.Assembly.GetExecutingAssembly());
                        System.Threading.Thread          thread          = System.Threading.Thread.CurrentThread;
                        System.Globalization.CultureInfo cultureInfo     = thread.CurrentUICulture;
                        editMenuName = resourceManager.GetString(String.Concat(cultureInfo.TwoLetterISOLanguageName, "Edit"));
                        toolsControl = menuBarCommandBar.Controls["Edit"];
                    }
                    catch (Exception) {
                        //  我们尝试查找 Edit 一词的本地化版本,但未能找到。
                        //  默认值为 en-US 一词,该值可能适用于当前区域性。
                        toolsControl = menuBarCommandBar.Controls["Edit"];
                    }

                    //将此命令置于“编辑”菜单上。
                    toolsPopup = (CommandBarPopup)toolsControl;
                    int pasteControlIndex = 1;

                    //查找“粘贴”控件,以便可在其后添加新的元素。
                    foreach (CommandBarControl commandBar in toolsPopup.CommandBar.Controls)
                    {
                        if (String.Compare(commandBar.Caption, "&Paste", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            pasteControlIndex = commandBar.Index + 1;
                            break;
                        }
                    }

                    //在 MenuBar 命令栏上查找相应的命令栏:
                    commandBarControl = (CommandBarControl)command.AddControl(toolsPopup.CommandBar, pasteControlIndex);
                }
                catch (Exception) {
                }
            }
        }
        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";

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

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

                try
                {
                    Command command = commands.AddNamedCommand2(_addInInstance, "SPProjectServiceAddIn", "SPProjectServiceAddIn", "Executes the command for SPProjectServiceAddIn", 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)
                {
                }
            }

            TestSPService();
        }
Example #21
0
        private void CreateMenuItems()
        {
            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, "Sync", "Sync Quick Test with Code", "Executes the command for QuickTestVS", 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))
                {
                    var button = command.AddControl(toolsPopup.CommandBar, 2) as CommandBarButton;
                    button.BeginGroup = true;
                }
            }
            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.
            }
        }
Example #22
0
        private bool CreateCommand()
        {
            try
            {
                Commands2 hCommands = m_hApplicationObject.Commands as Commands2;
                m_hCommand = hCommands.Item("CodeBeautifier.Connect." + m_strCommandName, 0);

                return(false);
            }
            catch (ArgumentException)
            {
                // Build command
                object[]  contextGUIDS = new object[] { };
                Commands2 hCommands    = m_hApplicationObject.Commands as Commands2;
                m_hCommand = hCommands.AddNamedCommand2(m_hAddInInstance,
                                                        (String)m_strCommandName,
                                                        (String)m_strCommandCaption,
                                                        (String)m_strCommandName,
                                                        true,
                                                        m_iIconIdx,
                                                        contextGUIDS,
                                                        (int)vsCommandStatus.vsCommandStatusSupported,
                                                        (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                return(true);
            }
        }
Example #23
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 to the Commands collection:
                    Command commandTurnOnLineNumbers  = commands.AddNamedCommand2(_addInInstance, "TurnOnLineNumbers", "TurnOnLineNumbers", "Executes the command for TurnOnLineNumbers", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    Command commandTurnOffLineNumbers = commands.AddNamedCommand2(_addInInstance, "TurnOffLineNumbers", "TurnOffLineNumbers", "Executes the command for TurnOnLineNumbers", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

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

                    //Add a control for commandTurnOffLineNumbers to the tools menu:
                    if ((commandTurnOffLineNumbers != null) && (toolsPopup != null))
                    {
                        commandTurnOffLineNumbers.AddControl(toolsPopup.CommandBar, 2);
                    }
                }
                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.
                    Microsoft.VisualBasic.Interaction.MsgBox(string.Format("Exception with commands: {0} {1}", exc.Message, exc.InnerException));
                }
            }
        }
Example #24
0
        public Command CreateCommand(string name, string title, string description, string HotKey, ExecuteDelegate executeMethod, StatusDelegate statusMethod)
        {
            object[] contextGUIDS = new object[] { };
            Command  result       = null;

            string fullname = GetFullName(name);

            result = GetCommand(fullname);


            if (result == null)
            {
                Commands2 commands = (Commands2)ApplicationObject.Commands;
                result = commands.AddNamedCommand2(
                    AddInInstance,
                    name,
                    title,
                    description,
                    true,
                    0,
                    ref contextGUIDS,
                    (int)vsCommandStatus.vsCommandStatusSupported +
                    (int)vsCommandStatus.vsCommandStatusEnabled,
                    (int)vsCommandStyle.vsCommandStylePictAndText,
                    vsCommandControlType.vsCommandControlTypeButton);

                // *** If a hotkey was provided try to set it
                //result.Bindings = bindings;
                if (HotKey != null && HotKey != "")
                {
                    object[] bindings = (object[])result.Bindings;
                    if (bindings != null)
                    {
                        bindings    = new object[1];
                        bindings[0] = (object)HotKey;
                        try
                        {
                            result.Bindings = (object)bindings;
                        }
                        catch
                        {
                            // Do nothing
                        }
                    }
                }
            }

            if (!CommandList.ContainsKey(fullname))
            {
                CommandHandle handle = new CommandHandle();
                handle.CommandObject = result;
                handle.ExecuteMethod = executeMethod;
                handle.StatusMethod  = statusMethod;

                CommandList.Add(fullname, handle);
            }

            return(result);
        }
Example #25
0
        private Command GetCommand(string commandName, string caption, string tooltip, int iconIndex,
                                   vsCommandStyle commandStyle, Commands2 commands)
        {
            var contextGUIDS = new object[] {};

            // Add command
            Command command = GetCommand(commandName);

            if (_visualStudioCommands.ContainsKey(commandName))
            {
                return(command);
            }

            if (command == null && iconIndex > 0)
            {
                try
                {
                    command = commands.AddNamedCommand2(_addIn,
                                                        commandName, caption, tooltip, false, iconIndex,
                                                        ref contextGUIDS,
                                                        (int)vsCommandStatus.vsCommandStatusSupported |
                                                        (int)vsCommandStatus.vsCommandStatusEnabled,
                                                        (int)commandStyle,
                                                        vsCommandControlType.vsCommandControlTypeButton);
                }
                catch (Exception)
                {
                }
            }

            if (command == null && commandStyle != vsCommandStyle.vsCommandStylePict)
            {
                command = commands.AddNamedCommand2(_addIn,
                                                    commandName, caption, tooltip, true, -1, ref contextGUIDS,
                                                    (int)vsCommandStatus.vsCommandStatusSupported +
                                                    (int)vsCommandStatus.vsCommandStatusEnabled,
                                                    (int)commandStyle,
                                                    vsCommandControlType.vsCommandControlTypeButton);
            }

            if (command != null)
            {
                _visualStudioCommands[commandName] = command;
            }
            return(command);
        }
Example #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;
            if (connectMode == ext_ConnectMode.ext_cm_UISetup)
            {
                object [] contextGUIDS  = new object[] { };
                Commands2 commands      = (Commands2)_applicationObject.Commands;
                string    toolsMenuName = "Project and Solution Context Menus";

                //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)[toolsMenuName];
                CommandBarPopup toolsPopup = (CommandBarPopup)menuBarCommandBar.Controls["Item"];

                //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, "Push", "Push To JIRA", "Executes the command for TestAddin", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStyleText, vsCommandControlType.vsCommandControlTypeButton);
                    Command command2 = commands.AddNamedCommand2(_addInInstance, "Fetch", "Fetch From JIRA", "Executes the command for TestAddin", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStyleText, vsCommandControlType.vsCommandControlTypeButton);
                    Command command3 = commands.AddNamedCommand2(_addInInstance, "All", "Fetch All From JIRA", "Executes the command for TestAddin", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStyleText, vsCommandControlType.vsCommandControlTypeButton);

                    //Add a control for the command to the Item context menu:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                    if ((command2 != null) && (toolsPopup != null))
                    {
                        command2.AddControl(toolsPopup.CommandBar, 1);
                    }
                    if ((command3 != null) && (toolsPopup != null))
                    {
                        command3.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.
                }
            }
        }
Example #27
0
        /// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary>
        /// <param term='application'>Root object of the host application.</param>
        /// <param term='connectMode'>Describes how the Add-in is being loaded.</param>
        /// <param term='addInInst'>Object representing this Add-in.</param>
        /// <seealso class='IDTExtensibility2' />
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            _applicationObject = (DTE2)application;
            _addInInstance     = (AddIn)addInInst;
            if (connectMode == ext_ConnectMode.ext_cm_UISetup)
            {
                object [] contextGUIDS = new object[] { };
                Commands2 commands     = (Commands2)_applicationObject.Commands;
                string    toolsMenuName;

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

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

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

                //This try/catch block can be duplicated if you wish to add multiple commands to be handled by your Add-in,
                //  just make sure you also update the QueryStatus/Exec method to include the new command names.
                try
                {
                    //Add a command to the Commands collection:
                    Command command = commands.AddNamedCommand2(_addInInstance, "JediVSIRC", "Jedi Visual Studio IRC Window", "Opens the IRC window", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    //Add a control for the command to the tools menu:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException)
                {
                    //If we are here, then the exception is probably because a command with that name
                    //  already exists. If so there is no need to recreate the command and we can
                    //  safely ignore the exception.
                }
            }
        }
Example #28
0
        /// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary>
        /// <param term='application'>Root object of the host application.</param>
        /// <param term='connectMode'>Describes how the Add-in is being loaded.</param>
        /// <param term='addInInst'>Object representing this Add-in.</param>
        /// <seealso class='IDTExtensibility2' />
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            _applicationObject = (DTE2)application;
            _addInInstance     = (AddIn)addInInst;
            if (connectMode == ext_ConnectMode.ext_cm_UISetup)
            {
                object [] contextGUIDS  = new object[] { };
                Commands2 commands      = (Commands2)_applicationObject.Commands;
                string    toolsMenuName = "Tools";

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

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

                //This try/catch block can be duplicated if you wish to add multiple commands to be handled by your Add-in,
                //  just make sure you also update the QueryStatus/Exec method to include the new command names.
                try
                {
                    //Add a command to the Commands collection:
                    Command command = commands.AddNamedCommand2(_addInInstance, "CiteCode", "CiteCode", "Executes the command for CiteCode", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

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

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

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



                    //Add a control for the command to the tools menu:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException)
                {
                    //If we are here, then the exception is probably because a command with that name
                    //  already exists. If so there is no need to recreate the command and we can
                    //  safely ignore the exception.
                }
            }
        }
Example #29
0
        public Desktop(string name, string text, DTE2 appObject, AddIn addInInstance, CommandBar bar, Commands2 commands)
        {
            _appObject = appObject;
            var contextGUIDS = new object[] { };

            _command = commands.AddNamedCommand2(addInInstance, name, text, string.Empty, true, 0, ref contextGUIDS);
            _command.AddControl(bar, bar.Controls.Count + 1);
            _controls = bar.Controls.Cast <CommandBarControl>();
            _control  = _controls.Last();
        }
Example #30
0
        private void RegisterSimpleCommand(Commands2 commands, string name, string buttonText, string bindings)
        {
            object[] contextGUIDS = new object[] { };
            Command  cmd          = commands.AddNamedCommand2(_addInInstance, name, buttonText, string.Empty, true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

            if (bindings != null)
            {
                cmd.Bindings = bindings;
            }
        }
Example #31
0
        /// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary>
        /// <param term='application'>Root object of the host application.</param>
        /// <param term='connectMode'>Describes how the Add-in is being loaded.</param>
        /// <param term='addInInst'>Object representing this Add-in.</param>
        /// <seealso class='IDTExtensibility2' />
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            _applicationObject = (DTE2)application;
            _addInInstance = (AddIn)addInInst;
            _textDocKeyEvents = ((Events2) _applicationObject.Events).get_TextDocumentKeyPressEvents();
            _commands = (Commands2) _applicationObject.Commands;

            try {
                _commands.AddNamedCommand2(_addInInstance, "Toggle", "Toggle TestCase", "Toggle test naming replacements on or off", false);
            } catch (Exception) {
            }

            _textDocKeyEvents.BeforeKeyPress += new _dispTextDocumentKeyPressEvents_BeforeKeyPressEventHandler(BeforeKeyPress);
        }
Example #32
0
        private void RegisterSimpleCommand(Commands2 commands, string name, string buttonText, string bindings)
        {
            object[] contextGUIDS = new object[] { };
            Command cmd = commands.AddNamedCommand2(_addInInstance, name, buttonText, string.Empty, true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

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

			CommandBar menuBarCommandBar = commandBars["MenuBar"];

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

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

			AppLog.LogMessage("Paste Schema code menu item is added");
		}
Example #34
0
    private Command _AddIndividualCommand(Commands2 cmds, vsCommandStatus statusValue, ICommand c)
    {
        object[] contextGUIDS = new object[] { };
        vsCommandStyle style = vsCommandStyle.vsCommandStylePict;

        String buttonText = c.CommandText;
        String toolTip = c.CommandText;
        Command command = cmds.AddNamedCommand2(_addInInstance
            , c.CommandText
            , buttonText
            , toolTip
            , false
            , null
            , ref contextGUIDS
            , (int)statusValue
            , (int)style
            , vsCommandControlType.vsCommandControlTypeButton
        );
        return command;
    }
    	public object[] AddCommandBarToToolsMenu(AddIn addInInstance, DTE2 applicationObject, Commands2 commands, object[] contextGUIDS, CommandBars commandBars)
        {
            Command command = commands.AddNamedCommand2(
                addInInstance,
                "WsContractFirst",
                "Web Services Contract-First...",
                "Executes the command for WsContractFirstAddin",
                true,
                190,
                ref contextGUIDS,
                (int)vsCommandStatus.vsCommandStatusUnsupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                (int)vsCommandStyle.vsCommandStylePictAndText,
                vsCommandControlType.vsCommandControlTypeButton);

			command.AddControl(toolsSubMenuCommandBar, 1);

            AppLog.LogMessage("Command bar is added to the Tools menu.");
            return contextGUIDS;
        }
Example #36
0
 private static void AddCommand(Commands2 c, AddIn a, object[] o, string name, string display, string tip)
 {
     c.AddNamedCommand2(a, name, display, tip, true, 59, ref o, StatusSupported + StatusEnabled, StyleText);
 }
        public object[] GenerateMenuItemForWSCodeGen(AddIn addInInstance, DTE2 applicationObject, Commands2 commands, object[] contextGUIDS)
        {
            Command cmdObj = commands.AddNamedCommand2(
            	addInInstance,
            	"WsContractFirstContextMenu",
            	"Generate Web Service Code...",
            	"Executes the command for WsContractFirstAddin ContextMenu",
            	true,
            	190,
            	ref contextGUIDS,
            	(int)vsCommandStatus.vsCommandStatusUnsupported + (int)vsCommandStatus.vsCommandStatusEnabled,
            	(int)vsCommandStyle.vsCommandStylePictAndText,
            	vsCommandControlType.vsCommandControlTypeButton);

			cmdObj.AddControl(subMenuCommandBar, 1);

            // BDS 11/21/2005: Add this menu item to the web project 
            // template.
			cmdObj.AddControl(webSubMenuCommandBar, 1);

            AppLog.LogMessage("Generate Web Serive Code menu item is added.");
            return contextGUIDS;
        }
Example #38
0
        private Command GetCommand(string commandName, string caption, string tooltip, int iconIndex,
            vsCommandStyle commandStyle, Commands2 commands)
        {
            var contextGUIDS = new object[] {};

            // Add command
            Command command = GetCommand(commandName);
            if (_visualStudioCommands.ContainsKey(commandName))
                return command;

            if (command == null && iconIndex > 0)
            {
                try
                {
                    command = commands.AddNamedCommand2(_addIn,
                        commandName, caption, tooltip, false, iconIndex,
                        ref contextGUIDS,
                        (int) vsCommandStatus.vsCommandStatusSupported |
                        (int) vsCommandStatus.vsCommandStatusEnabled,
                        (int) commandStyle,
                        vsCommandControlType.vsCommandControlTypeButton);
                }
                catch (Exception)
                {
                }
            }

            if (command == null && commandStyle != vsCommandStyle.vsCommandStylePict)
            {
                command = commands.AddNamedCommand2(_addIn,
                    commandName, caption, tooltip, true, -1, ref contextGUIDS,
                    (int) vsCommandStatus.vsCommandStatusSupported +
                    (int) vsCommandStatus.vsCommandStatusEnabled,
                    (int) commandStyle,
                    vsCommandControlType.vsCommandControlTypeButton);
            }

            if (command != null)
            {
                _visualStudioCommands[commandName] = command;
            }
            return command;
        }
Example #39
0
 private Command GetNewCommandAddedToDTECommands2(Commands2 commands, object[] contextGUIDS)
 {
     return
         commands.AddNamedCommand2(addIn, TOOLS_COMMAND_NAME, RECORDER_ADD_IN_TOOLS_MENU_ITEM_NAME, TOOLS_COMMAND_DESCRIPTION, true, null,
                                   ref contextGUIDS, (int) vsCommandStatus.vsCommandStatusSupported + (int) vsCommandStatus.vsCommandStatusEnabled,
                                   (int) vsCommandStyle.vsCommandStyleText, vsCommandControlType.vsCommandControlTypeButton);
 }
Example #40
0
 /// <summary>
 /// Adds new command to the specified command collection.
 /// </summary>
 private Command CreateCommand(AddIn addInInstance, Commands2 commands)
 {
     return commands.AddNamedCommand2(
         addInInstance,
         CommandName,
         CommandText,
         CommandTooltip,
         false,
         IconBitmapCode);
 }