Beispiel #1
0
        internal static bool TryConvert(Guid commandGroup, uint commandId, IntPtr pVariableIn, out EditCommand command)
        {
            KeyInput ki;
            EditCommandKind kind;
            if (!TryConvert(commandGroup, commandId, pVariableIn, out ki, out kind))
            {
                command = null;
                return false;
            }

            command = new EditCommand(ki, kind, commandGroup, commandId);
            return true;
        }
Beispiel #2
0
        internal static bool TryConvert(Guid commandGroup, uint commandId, IntPtr pVariableIn, KeyModifiers modifiers, out EditCommand command)
        {
            KeyInput keyInput;
            EditCommandKind kind;
            if (!TryConvert(commandGroup, commandId, pVariableIn, out keyInput, out kind))
            {
                command = null;
                return false;
            }

            keyInput = KeyInputUtil.ApplyModifiers(keyInput, modifiers);
            command = new EditCommand(keyInput, kind, commandGroup, commandId);
            return true;
        }
Beispiel #3
0
        internal static bool TryConvert(Guid commandGroup, uint commandId, IntPtr pVariableIn, KeyModifiers modifiers, out EditCommand command)
        {
            KeyInput keyInput;
            EditCommandKind kind;
            bool isRawText;
            if (!TryConvert(commandGroup, commandId, pVariableIn, out keyInput, out kind, out isRawText))
            {
                command = null;
                return false;
            }

            // When raw text is provided it already includes the active keyboard modifiers. Don't reapply them
            // here else it can incorrectly modify the provided character.
            if (!isRawText)
            {
                keyInput = KeyInputUtil.ApplyModifiers(keyInput, modifiers);
            }

            command = new EditCommand(keyInput, kind, commandGroup, commandId);
            return true;
        }
Beispiel #4
0
        /// <summary>
        /// Try and convert the Visual Studio command to it's equivalent KeyInput
        /// </summary>
        internal bool TryConvert(Guid commandGroup, uint commandId, IntPtr pvaIn, out EditCommand editCommand)
        {
            editCommand = null;

            // Don't ever process a command when we are in an automation function.  Doing so will cause VsVim to
            // intercept items like running Macros and certain wizard functionality
            if (_adapter.InAutomationFunction)
            {
                return false;
            }

            // Don't intercept commands while incremental search is active.  Don't want to interfere with it
            if (_adapter.IsIncrementalSearchActive(_buffer.TextView))
            {
                return false;
            }

            return OleCommandUtil.TryConvert(commandGroup, commandId, pvaIn, out editCommand);
        }
Beispiel #5
0
 internal static bool TryConvert(Guid commandGroup, uint commandId, out EditCommand command)
 {
     return TryConvert(commandGroup, commandId, IntPtr.Zero, out command);
 }
Beispiel #6
0
        private CommandStatus QueryStatusCore(EditCommand editCommand)
        {
            VimTrace.TraceInfo("VsCommandTarget::QueryStatus {0}", editCommand);

            _bufferCoordinator.DiscardedKeyInput = FSharpOption<KeyInput>.None;

            var action = CommandStatus.PassOn;
            switch (editCommand.EditCommandKind)
            {
                case EditCommandKind.Undo:
                case EditCommandKind.Redo:
                    action = CommandStatus.Enable;
                    break;
                case EditCommandKind.Paste:
                    action = _vimBuffer.ModeKind == ModeKind.Command
                        ? CommandStatus.Enable
                        : CommandStatus.PassOn;
                    break;
                default:
                    if (editCommand.HasKeyInput && _vimBuffer.CanProcess(editCommand.KeyInput))
                    {
                        action = CommandStatus.Enable;
                        if (_resharperUtil.IsInstalled)
                        {
                            action = QueryStatusInResharper(editCommand.KeyInput) ?? CommandStatus.Enable;
                        }
                    }
                    break;
            }

            VimTrace.TraceInfo("VsCommandTarget::QueryStatus ", action);
            return action;
        }
Beispiel #7
0
        /// <summary>
        /// Try and convert the Visual Studio command to it's equivalent KeyInput
        /// </summary>
        internal bool TryConvert(Guid commandGroup, uint commandId, IntPtr variantIn, out EditCommand editCommand)
        {
            editCommand = null;

            // Don't ever process a command when we are in an automation function.  Doing so will cause VsVim to
            // intercept items like running Macros and certain wizard functionality
            if (_vsAdapter.InAutomationFunction)
            {
                return false;
            }

            // Don't intercept commands while incremental search is active.  Don't want to interfere with it
            if (_vsAdapter.IsIncrementalSearchActive(_vimBuffer.TextView))
            {
                return false;
            }

            var modifiers = _keyUtil.GetKeyModifiers(_vsAdapter.KeyboardDevice.Modifiers);
            if (!OleCommandUtil.TryConvert(commandGroup, commandId, variantIn, modifiers, out editCommand))
            {
                return false;
            }

            // Don't process Visual Studio commands.  If the key sequence is mapped to a Visual Studio command
            // then that command wins.
            if (editCommand.EditCommandKind == EditCommandKind.VisualStudioCommand)
            {
                return false;
            }

            return true;
        }
Beispiel #8
0
        internal bool ExecCore(EditCommand editCommand, out Action action)
        {
            VimTrace.TraceInfo("VsCommandTarget::Exec {0}", editCommand);
            action = null;

            switch (editCommand.EditCommandKind)
            {
                case EditCommandKind.Undo:
                    // The user hit the undo button.  Don't attempt to map anything here and instead just
                    // run a single Vim undo operation
                    _vimBuffer.UndoRedoOperations.Undo(1);
                    return true;

                case EditCommandKind.Redo:
                    // The user hit the redo button.  Don't attempt to map anything here and instead just
                    // run a single Vim redo operation
                    _vimBuffer.UndoRedoOperations.Redo(1);
                    return true;

                case EditCommandKind.Paste:
                    return Paste();

                case EditCommandKind.GoToDefinition:
                    // The GoToDefinition command will often cause a selection to occur in the
                    // buffer.  We don't want that to cause us to enter Visual Mode so clear it
                    // out.  This command can cause the active document to switch if the target
                    // of the goto def is in another file.  This file won't be registered as the
                    // active file yet so just clear out the active selections
                    action = () =>
                        {
                            _textManager.TextViews
                                .Where(x => !x.Selection.IsEmpty)
                                .ForEach(x => x.Selection.Clear());
                        };
                    return false;

                case EditCommandKind.Comment:
                case EditCommandKind.Uncomment:
                    // The comment / uncomment command will often induce a selection on the
                    // editor even if there was no selection before the command was run (single line
                    // case).
                    if (_textView.Selection.IsEmpty)
                    {
                        action = () => { _textView.Selection.Clear(); };
                    }
                    return false;

                case EditCommandKind.UserInput:
                case EditCommandKind.VisualStudioCommand:
                    if (editCommand.HasKeyInput)
                    {
                        var keyInput = editCommand.KeyInput;

                        // Discard the input if it's been flagged by a previous QueryStatus
                        if (_bufferCoordinator.DiscardedKeyInput.IsSome(keyInput))
                        {
                            return true;
                        }

                        // Try and process the command with the IVimBuffer
                        if (TryProcessWithBuffer(keyInput))
                        {
                            return true;
                        }
                    }
                    return false;
                default:
                    Debug.Assert(false);
                    return false;
            }
        }
Beispiel #9
0
        private bool Exec(EditCommand editCommand)
        {
            VimTrace.TraceInfo("VsCommandTarget::Exec {0}", editCommand);
            if (editCommand.IsUndo)
            {
                // The user hit the undo button.  Don't attempt to map anything here and instead just
                // run a single Vim undo operation
                _vimBuffer.UndoRedoOperations.Undo(1);
                return true;
            }
            else if (editCommand.IsRedo)
            {
                // The user hit the redo button.  Don't attempt to map anything here and instead just
                // run a single Vim redo operation
                _vimBuffer.UndoRedoOperations.Redo(1);
                return true;
            }
            else if (editCommand.HasKeyInput)
            {
                var keyInput = editCommand.KeyInput;

                // Discard the input if it's been flagged by a previous QueryStatus
                if (_bufferCoordinator.DiscardedKeyInput.IsSome(keyInput))
                {
                    return true;
                }

                // Try and process the command with the IVimBuffer
                if (TryProcessWithBuffer(keyInput))
                {
                    return true;
                }
            }

            return false;
        }
Beispiel #10
0
        internal bool ExecCore(EditCommand editCommand)
        {
            VimTrace.TraceInfo("VsCommandTarget::Exec {0}", editCommand);
            switch (editCommand.EditCommandKind)
            {
                case EditCommandKind.Undo:
                    // The user hit the undo button.  Don't attempt to map anything here and instead just
                    // run a single Vim undo operation
                    _vimBuffer.UndoRedoOperations.Undo(1);
                    return true;

                case EditCommandKind.Redo:
                    // The user hit the redo button.  Don't attempt to map anything here and instead just
                    // run a single Vim redo operation
                    _vimBuffer.UndoRedoOperations.Redo(1);
                    return true;

                case EditCommandKind.GoToDefinition:
                    // Let Visual Studio process this command
                    return false;

                case EditCommandKind.UserInput:
                case EditCommandKind.VisualStudioCommand:
                    if (editCommand.HasKeyInput)
                    {
                        var keyInput = editCommand.KeyInput;

                        // Discard the input if it's been flagged by a previous QueryStatus
                        if (_bufferCoordinator.DiscardedKeyInput.IsSome(keyInput))
                        {
                            return true;
                        }

                        // Try and process the command with the IVimBuffer
                        if (TryProcessWithBuffer(keyInput))
                        {
                            return true;
                        }
                    }
                    return false;
                default:
                    Debug.Assert(false);
                    return false;
            }
        }
Beispiel #11
0
        private CommandStatus QueryStatus(EditCommand editCommand)
        {
            VimTrace.TraceInfo("VsCommandTarget::QueryStatus {0}", editCommand);

            var action = CommandStatus.PassOn;
            foreach (var commandTarget in _commandTargets)
            {
                action = commandTarget.QueryStatus(editCommand);
                if (action != CommandStatus.PassOn)
                {
                    break;
                }
            }

            VimTrace.TraceInfo("VsCommandTarget::QueryStatus ", action);
            return action;
        }
Beispiel #12
0
        internal bool Exec(EditCommand editCommand, out Action action)
        {
            VimTrace.TraceInfo("VsCommandTarget::Exec {0}", editCommand);
            action = null;

            // If the KeyInput was already handled then pretend we handled it here
            if (editCommand.HasKeyInput && _vimBufferCoordinator.IsDiscarded(editCommand.KeyInput))
            {
                return true;
            }

            var result = false;
            foreach (var commandTarget in _commandTargets)
            {
                if (commandTarget.Exec(editCommand, out action))
                {
                    result = true;
                    break;
                }
            }

            return result;
        }
Beispiel #13
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;
     }
 }
Beispiel #14
0
        internal bool ExecCore(EditCommand editCommand, out Action action)
        {
            VimTrace.TraceInfo("VsCommandTarget::Exec {0}", editCommand);
            action = null;

            switch (editCommand.EditCommandKind)
            {
            case EditCommandKind.Undo:
                // The user hit the undo button.  Don't attempt to map anything here and instead just
                // run a single Vim undo operation
                _vimBuffer.UndoRedoOperations.Undo(1);
                return(true);

            case EditCommandKind.Redo:
                // The user hit the redo button.  Don't attempt to map anything here and instead just
                // run a single Vim redo operation
                _vimBuffer.UndoRedoOperations.Redo(1);
                return(true);

            case EditCommandKind.Paste:
                return(Paste());

            case EditCommandKind.GoToDefinition:
                // The GoToDefinition command will often cause a selection to occur in the
                // buffer.  We don't want that to cause us to enter Visual Mode so clear it
                // out.  This command can cause the active document to switch if the target
                // of the goto def is in another file.  This file won't be registered as the
                // active file yet so just clear out the active selections
                action = () =>
                {
                    _textManager.TextViews
                    .Where(x => !x.Selection.IsEmpty)
                    .ForEach(x => x.Selection.Clear());
                };
                return(false);

            case EditCommandKind.Comment:
            case EditCommandKind.Uncomment:
                // The comment / uncomment command will often induce a selection on the
                // editor even if there was no selection before the command was run (single line
                // case).
                if (_textView.Selection.IsEmpty)
                {
                    action = () => { _textView.Selection.Clear(); };
                }
                return(false);

            case EditCommandKind.UserInput:
            case EditCommandKind.VisualStudioCommand:
                if (editCommand.HasKeyInput)
                {
                    var keyInput = editCommand.KeyInput;

                    // Discard the input if it's been flagged by a previous QueryStatus
                    if (_bufferCoordinator.DiscardedKeyInput.IsSome(keyInput))
                    {
                        return(true);
                    }

                    // Try and process the command with the IVimBuffer
                    if (TryProcessWithBuffer(keyInput))
                    {
                        return(true);
                    }
                }
                return(false);

            default:
                Debug.Assert(false);
                return(false);
            }
        }
Beispiel #15
0
        /// <summary>
        /// Try and convert the Visual Studio command to it's equivalent KeyInput
        /// </summary>
        internal bool TryConvert(Guid commandGroup, uint commandId, IntPtr variantIn, out EditCommand editCommand)
        {
            editCommand = null;

            // Don't ever process a command when we are in an automation function.  Doing so will cause VsVim to
            // intercept items like running Macros and certain wizard functionality
            if (_vsAdapter.InAutomationFunction)
            {
                return(false);
            }

            // Don't intercept commands while incremental search is active.  Don't want to interfere with it
            if (_vsAdapter.IsIncrementalSearchActive(_vimBuffer.TextView))
            {
                return(false);
            }

            var modifiers = _keyUtil.GetKeyModifiers(_vsAdapter.KeyboardDevice.Modifiers);

            if (!OleCommandUtil.TryConvert(commandGroup, commandId, variantIn, modifiers, out editCommand))
            {
                return(false);
            }

            // Don't process Visual Studio commands.  If the key sequence is mapped to a Visual Studio command
            // then that command wins.
            if (editCommand.EditCommandKind == EditCommandKind.VisualStudioCommand)
            {
                return(false);
            }

            return(true);
        }