Exemplo n.º 1
0
        internal static bool QueryStatus(this IOleCommandTarget oleCommandTarget, OleCommandData oleCommandData, OLECMDF status)
        {
            OLECMD command;
            var    hr = QueryStatus(oleCommandTarget, oleCommandData, out command);

            if (hr != VSConstants.S_OK)
            {
                return(false);
            }

            var ret = (OLECMDF)command.cmdf;

            return(status == (ret & status));
        }
Exemplo n.º 2
0
        internal static int QueryStatus(this IOleCommandTarget oleCommandTarget, OleCommandData oleCommandData, out OLECMD command)
        {
            var commandGroup = oleCommandData.Group;
            var cmds         = new OLECMD[1];

            cmds[0] = new OLECMD {
                cmdID = oleCommandData.Id
            };
            var result = oleCommandTarget.QueryStatus(
                ref commandGroup,
                1,
                cmds,
                oleCommandData.VariantIn);

            command = cmds[0];
            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Try and convert the given insert command to an OleCommand.  This should only be done
        /// for InsertCommand values which we want to custom process
        /// </summary>
        private bool TryGetOleCommandData(InsertCommand command, out OleCommandData commandData)
        {
            if (command.IsBack)
            {
                commandData = new OleCommandData(VSConstants.VSStd2KCmdID.BACKSPACE);
                return(true);
            }

            if (command.IsDelete)
            {
                commandData = new OleCommandData(VSConstants.VSStd2KCmdID.DELETE);
                return(true);
            }

            if (command.IsInsert)
            {
                var insert = (InsertCommand.Insert)command;
                if (insert.Text != null && insert.Text.Length == 1)
                {
                    commandData = OleCommandData.CreateTypeChar(insert.Text[0]);
                    return(true);
                }
            }

            if (command.IsInsertTab)
            {
                commandData = new OleCommandData(VSConstants.VSStd2KCmdID.TAB);
                return(true);
            }

            if (command.IsInsertNewLine)
            {
                commandData = new OleCommandData(VSConstants.VSStd2KCmdID.RETURN);
                return(true);
            }

            commandData = OleCommandData.Empty;
            return(false);
        }
Exemplo n.º 4
0
        internal static bool TryConvert(EditCommand editCommand, out OleCommandData oleCommandData)
        {
            switch (editCommand.EditCommandKind)
            {
            case EditCommandKind.GoToDefinition:
                oleCommandData = new OleCommandData(VSConstants.VSStd97CmdID.GotoDecl);
                return(true);

            case EditCommandKind.Paste:
                oleCommandData = new OleCommandData(VSConstants.VSStd2KCmdID.PASTE);
                return(true);

            case EditCommandKind.Undo:
                oleCommandData = new OleCommandData(VSConstants.VSStd2KCmdID.UNDO);
                return(true);

            case EditCommandKind.Redo:
                oleCommandData = new OleCommandData(VSConstants.VSStd2KCmdID.REDO);
                return(true);

            case EditCommandKind.Comment:
                oleCommandData = new OleCommandData(VSConstants.VSStd2KCmdID.COMMENTBLOCK);
                return(true);

            case EditCommandKind.Uncomment:
                oleCommandData = new OleCommandData(VSConstants.VSStd2KCmdID.UNCOMMENTBLOCK);
                return(true);

            case EditCommandKind.UserInput:
                return(TryConvert(editCommand.KeyInput, out oleCommandData));

            case EditCommandKind.VisualStudioCommand:
            default:
                oleCommandData = OleCommandData.Empty;
                return(false);
            }
        }
Exemplo n.º 5
0
 internal static bool TryConvert(EditCommand editCommand, out OleCommandData oleCommandData)
 {
     switch (editCommand.EditCommandKind)
     {
         case EditCommandKind.GoToDefinition:
             oleCommandData = new OleCommandData(VSConstants.VSStd97CmdID.GotoDecl);
             return true;
         case EditCommandKind.Paste:
             oleCommandData = new OleCommandData(VSConstants.VSStd2KCmdID.PASTE);
             return true;
         case EditCommandKind.Undo:
             oleCommandData = new OleCommandData(VSConstants.VSStd2KCmdID.UNDO);
             return true;
         case EditCommandKind.Redo:
             oleCommandData = new OleCommandData(VSConstants.VSStd2KCmdID.REDO);
             return true;
         case EditCommandKind.Comment:
             oleCommandData = new OleCommandData(VSConstants.VSStd2KCmdID.COMMENTBLOCK);
             return true;
         case EditCommandKind.Uncomment:
             oleCommandData = new OleCommandData(VSConstants.VSStd2KCmdID.UNCOMMENTBLOCK);
             return true;
         case EditCommandKind.UserInput:
             return TryConvert(editCommand.KeyInput, out oleCommandData);
         case EditCommandKind.VisualStudioCommand:
         default:
             oleCommandData = OleCommandData.Empty;
             return false;
     }
 }
Exemplo n.º 6
0
 internal static bool TryConvert(OleCommandData oleCommandData, out KeyInput keyInput)
 {
     EditCommandKind editCommandKind;
     return TryConvert(oleCommandData.Group, oleCommandData.Id, oleCommandData.VariantIn, out keyInput, out editCommandKind);
 }
Exemplo n.º 7
0
        /// <summary>
        /// Try and convert the KeyInput value into an OleCommandData instance.  If simulateStandardKeyBindings is set
        /// to true then "standard" Visual Studio key bindings will be assumed and this will be reflected in the 
        /// resulting command information
        /// </summary>
        internal static bool TryConvert(KeyInput keyInput, bool simulateStandardKeyBindings, out OleCommandData oleCommandData)
        {
            var hasShift = 0 != (keyInput.KeyModifiers & KeyModifiers.Shift);
            VSConstants.VSStd2KCmdID? cmdId = null;
            switch (keyInput.Key)
            {
                case VimKey.Enter:
                    cmdId = VSConstants.VSStd2KCmdID.RETURN;
                    break;
                case VimKey.Escape:
                    cmdId = VSConstants.VSStd2KCmdID.CANCEL;
                    break;
                case VimKey.Delete:
                    cmdId = VSConstants.VSStd2KCmdID.DELETE;
                    break;
                case VimKey.Back:
                    cmdId = VSConstants.VSStd2KCmdID.BACKSPACE;
                    break;
                case VimKey.Up:
                    cmdId = simulateStandardKeyBindings && hasShift
                        ? VSConstants.VSStd2KCmdID.UP_EXT
                        : VSConstants.VSStd2KCmdID.UP;
                    break;
                case VimKey.Down:
                    cmdId = simulateStandardKeyBindings && hasShift
                        ? VSConstants.VSStd2KCmdID.DOWN_EXT
                        : VSConstants.VSStd2KCmdID.DOWN;
                    break;
                case VimKey.Left:
                    cmdId = simulateStandardKeyBindings && hasShift
                        ? VSConstants.VSStd2KCmdID.LEFT_EXT
                        : VSConstants.VSStd2KCmdID.LEFT;
                    break;
                case VimKey.Right:
                    cmdId = simulateStandardKeyBindings && hasShift
                        ? VSConstants.VSStd2KCmdID.RIGHT_EXT
                        : VSConstants.VSStd2KCmdID.RIGHT;
                    break;
                case VimKey.Tab:
                    cmdId = simulateStandardKeyBindings && hasShift
                        ? VSConstants.VSStd2KCmdID.BACKTAB
                        : VSConstants.VSStd2KCmdID.TAB;
                    break;
                case VimKey.PageUp:
                    cmdId = simulateStandardKeyBindings && hasShift
                        ? VSConstants.VSStd2KCmdID.PAGEUP_EXT
                        : VSConstants.VSStd2KCmdID.PAGEUP;
                    break;
                case VimKey.PageDown:
                    cmdId = simulateStandardKeyBindings && hasShift
                        ? VSConstants.VSStd2KCmdID.PAGEDN_EXT
                        : VSConstants.VSStd2KCmdID.PAGEDN;
                    break;
                case VimKey.Insert:
                    cmdId = VSConstants.VSStd2KCmdID.TOGGLE_OVERTYPE_MODE;
                    break;
            }

            if (cmdId.HasValue)
            {
                oleCommandData = new OleCommandData(cmdId.Value);
                return true;
            }

            if (keyInput.RawChar.IsSome())
            {
                oleCommandData = OleCommandData.CreateTypeChar(keyInput.Char);
                return true;
            }
            else
            {
                oleCommandData = OleCommandData.Empty;
                return false;
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Try and convert the KeyInput into the appropriate Visual Studio command.  The conversion will be done
 /// without any consideration of Visual Studio standard commands.  It will map as if VsVim was in 
 /// complete control of key bindings
 /// </summary>
 internal static bool TryConvert(KeyInput keyInput, out OleCommandData oleCommandData)
 {
     return TryConvert(keyInput, false, out oleCommandData);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Try and convert the given insert command to an OleCommand.  This should only be done
        /// for InsertCommand values which we want to custom process
        /// </summary>
        private bool TryGetOleCommandData(InsertCommand command, out OleCommandData commandData)
        {
            if (command.IsBack)
            {
                commandData = new OleCommandData(VSConstants.VSStd2KCmdID.BACKSPACE);
                return true;
            }

            if (command.IsDelete)
            {
                commandData = new OleCommandData(VSConstants.VSStd2KCmdID.DELETE);
                return true;
            }

            if (command.IsInsert)
            {
                var insert = (InsertCommand.Insert)command;
                if (insert.Item != null && insert.Item.Length == 1)
                {
                    commandData = OleCommandData.CreateTypeChar(insert.Item[0]);
                    return true;
                }
            }

            if (command.IsInsertTab)
            {
                commandData = new OleCommandData(VSConstants.VSStd2KCmdID.TAB);
                return true;
            }

            if (command.IsInsertNewLine)
            {
                commandData = new OleCommandData(VSConstants.VSStd2KCmdID.RETURN);
                return true;
            }

            commandData = OleCommandData.Empty;
            return false;
        }
Exemplo n.º 10
0
        internal static int QueryStatus(this IOleCommandTarget oleCommandTarget, OleCommandData oleCommandData)
        {
            OLECMD command;

            return(QueryStatus(oleCommandTarget, oleCommandData, out command));
        }
Exemplo n.º 11
0
        internal static bool TryConvert(OleCommandData oleCommandData, out KeyInput keyInput)
        {
            EditCommandKind editCommandKind;

            return(TryConvert(oleCommandData.Group, oleCommandData.Id, oleCommandData.VariantIn, out keyInput, out editCommandKind));
        }
Exemplo n.º 12
0
        /// <summary>
        /// Try and convert the KeyInput value into an OleCommandData instance.  If simulateStandardKeyBindings is set
        /// to true then "standard" Visual Studio key bindings will be assumed and this will be reflected in the
        /// resulting command information
        /// </summary>
        internal static bool TryConvert(KeyInput keyInput, bool simulateStandardKeyBindings, out OleCommandData oleCommandData)
        {
            var hasShift = 0 != (keyInput.KeyModifiers & KeyModifiers.Shift);

            VSConstants.VSStd2KCmdID?cmdId = null;
            switch (keyInput.Key)
            {
            case VimKey.Enter:
                cmdId = VSConstants.VSStd2KCmdID.RETURN;
                break;

            case VimKey.Escape:
                cmdId = VSConstants.VSStd2KCmdID.CANCEL;
                break;

            case VimKey.Delete:
                cmdId = VSConstants.VSStd2KCmdID.DELETE;
                break;

            case VimKey.Back:
                cmdId = VSConstants.VSStd2KCmdID.BACKSPACE;
                break;

            case VimKey.Up:
                cmdId = simulateStandardKeyBindings && hasShift
                        ? VSConstants.VSStd2KCmdID.UP_EXT
                        : VSConstants.VSStd2KCmdID.UP;
                break;

            case VimKey.Down:
                cmdId = simulateStandardKeyBindings && hasShift
                        ? VSConstants.VSStd2KCmdID.DOWN_EXT
                        : VSConstants.VSStd2KCmdID.DOWN;
                break;

            case VimKey.Left:
                cmdId = simulateStandardKeyBindings && hasShift
                        ? VSConstants.VSStd2KCmdID.LEFT_EXT
                        : VSConstants.VSStd2KCmdID.LEFT;
                break;

            case VimKey.Right:
                cmdId = simulateStandardKeyBindings && hasShift
                        ? VSConstants.VSStd2KCmdID.RIGHT_EXT
                        : VSConstants.VSStd2KCmdID.RIGHT;
                break;

            case VimKey.Tab:
                cmdId = simulateStandardKeyBindings && hasShift
                        ? VSConstants.VSStd2KCmdID.BACKTAB
                        : VSConstants.VSStd2KCmdID.TAB;
                break;

            case VimKey.PageUp:
                cmdId = simulateStandardKeyBindings && hasShift
                        ? VSConstants.VSStd2KCmdID.PAGEUP_EXT
                        : VSConstants.VSStd2KCmdID.PAGEUP;
                break;

            case VimKey.PageDown:
                cmdId = simulateStandardKeyBindings && hasShift
                        ? VSConstants.VSStd2KCmdID.PAGEDN_EXT
                        : VSConstants.VSStd2KCmdID.PAGEDN;
                break;

            case VimKey.Insert:
                cmdId = VSConstants.VSStd2KCmdID.TOGGLE_OVERTYPE_MODE;
                break;
            }

            if (cmdId.HasValue)
            {
                oleCommandData = new OleCommandData(cmdId.Value);
                return(true);
            }

            if (keyInput.RawChar.IsSome())
            {
                oleCommandData = OleCommandData.CreateTypeChar(keyInput.Char);
                return(true);
            }
            else
            {
                oleCommandData = OleCommandData.Empty;
                return(false);
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// Try and convert the KeyInput into the appropriate Visual Studio command.  The conversion will be done
 /// without any consideration of Visual Studio standard commands.  It will map as if VsVim was in
 /// complete control of key bindings
 /// </summary>
 internal static bool TryConvert(KeyInput keyInput, out OleCommandData oleCommandData)
 {
     return(TryConvert(keyInput, false, out oleCommandData));
 }