Example #1
0
        public DTE_Command FindCommand(string InName, DTE_Output InOutput)
        {
            EnvDTE.Command found    = null;
            string         fullName = mAddin.ProgID + "." + InName;

            EnvDTE.Commands commands = mMain.dte2.Commands;

            try
            {
                found = commands.Item(fullName, -1);
            }
            catch (Exception excp)
            {
                found = null;
                string xx = excp.ToString();
            }

            if (found == null)
            {
                return(null);
            }
            else
            {
                return(new DTE_Command(mMain, found));
            }
        }
        /// <summary>
        /// Adds (appends) a binding for the given shortcut
        /// </summary>
        /// <param name="commandName"></param>
        /// <param name="shortcutDef"></param>
        public void BindShortcut(string commandName, string shortcutDef)
        {
            DTE dte = (DTE)serviceProvider.GetService(typeof(DTE));

            EnvDTE.Commands cmds = dte.Commands;
            //EnvDTE.Command shortCutCommand = DTECommands.Item(commandName);
            EnvDTE.Command shortCutCommand = cmds.Item(commandName);
            object[]       newBindings     = AppendKeyboardBinding(shortCutCommand, shortcutDef);
            shortCutCommand.Bindings = newBindings;
        }
Example #3
0
        /// <summary>
        /// Adds (appends) a binding for the given shortcut
        /// </summary>
        /// <param name="commandName"></param>
        /// <param name="shortcutDef"></param>
        public static void BindShortcut(string commandName, string shortcutDef)
        {
            // Make sure we're not using the Default keyboard mapping scheme
            DTE dte = (DTE)((IServiceProvider)package).GetService(typeof(DTE));

            EnvDTE.Commands cmds = dte.Commands;
            Command         cmd  = cmds.Item(commandName);

            object[] newBindings = AppendKeyboardBinding(cmd, shortcutDef);
            cmd.Bindings = newBindings;
        }
Example #4
0
        /// <summary>
        /// Note: Calling this is redundant if the original KeyBinding works in the vsct file.
        /// However, sometimes there is another command bound to the desired keybinding.
        /// In those cases, explicitly defining the key binding here is usually more effective.
        /// </summary>
        internal void UpdateKeyBindings()
        {
            // Make sure we're not using the Default keyboard mapping scheme
            DTE        dte   = (DTE)ServiceProvider.GetService(typeof(DTE));
            Properties props = dte.Properties["Environment", "Keyboard"];
            Property   prop  = props.Item("SchemeName");

            prop.Value = "MyBindings.vsk";

            EnvDTE.Commands cmds = dte.Commands;

            // Add a binding for ExpandSelection(TextEditor)
            {
                Command      cmdToggleComment        = cmds.Item("Edit.ToggleComment");
                const string toggleCommentKeyBinding = "Text Editor::Ctrl+/";
                cmdToggleComment.Bindings = (object)AppendKeyboardBinding(cmdToggleComment, toggleCommentKeyBinding);  // Note: This overrides any key bindings already assigned to this command
            }

            // Add a binding for ExpandSelection(TextEditor)
            {
                Command      cmdExpandSelection        = cmds.Item("1023dc3d-550c-46b8-a3ec-c6b03431642c", 0x1022); // Edit.ExpandSelection
                const string expandSelectionKeyBinding = "Text Editor::Ctrl+W";
                object[]     newBindings = SingleKeyboardBinding(expandSelectionKeyBinding);
                cmdExpandSelection.Bindings = (object)newBindings;
            }

            {
                Command      cmdToggleComment        = cmds.Item("Edit.DuplicateSelection");
                const string toggleCommentKeyBinding = "Text Editor::Ctrl+D";
                cmdToggleComment.Bindings = AppendKeyboardBinding(cmdToggleComment, toggleCommentKeyBinding);

                cmdToggleComment = cmds.Item("Edit.DuplicateAndSelectOriginal");
                const string toggleCommentKeyReverseBinding = "Text Editor::Ctrl+Shift+D";
                cmdToggleComment.Bindings = AppendKeyboardBinding(cmdToggleComment, toggleCommentKeyReverseBinding);
            }

            // Add a binding for MoveMemberUp(TextEditor)
            {
                Command      cmdMoveMemberUP        = cmds.Item("Edit.MoveMemberUp", 0x1031);
                const string moveMemberUPKeyBinding = "Text Editor::Ctrl+Num 8";
                cmdMoveMemberUP.Bindings = (object)AppendKeyboardBinding(cmdMoveMemberUP, moveMemberUPKeyBinding);
            }

            // Add a binding for MoveMemberDown(TextEditor)
            {
                Command      cmdMoveMemberDown        = cmds.Item("Edit.MoveMemberDown", 0x1032);
                const string moveMemberDownKeyBinding = "Text Editor::Ctrl+Num 2";
                cmdMoveMemberDown.Bindings = (object)AppendKeyboardBinding(cmdMoveMemberDown, moveMemberDownKeyBinding);
            }
        }
Example #5
0
        internal static bool BindingExists(string commandName, string shortcutDef)
        {
            DTE dte = (DTE)((IServiceProvider)package).GetService(typeof(DTE));

            EnvDTE.Commands cmds = dte.Commands;
            // Find command
            Command cmd = cmds.Item(commandName);

            if (cmd == null)
            {
                return(false);
            }
            // Check if the binding is attached to it
            object[] existingBindings = (object[])cmd.Bindings;
            if (existingBindings == null)
            {
                return(false);
            }
            // Check if the keyboard binding is already there
            return(existingBindings.Contains(shortcutDef));
        }