Пример #1
0
        public CommandResult Invoke(Guid group, int id, object args, ref object outargs)
        {
            CommandResult result = _braceCompletionTarget.Invoke(group, id, args, ref outargs);

            if (result.WasExecuted)
            {
                return(result);
            }

            if (group == VSConstants.VSStd2K)
            {
                switch (id)
                {
                case (int)VSConstants.VSStd2KCmdID.TYPECHAR:
                    string text;
                    if (args is char)
                    {
                        text = args.ToString();
                    }
                    else
                    {
                        text = Char.ConvertFromUtf32((System.UInt16)args);
                    }

                    result = this.PerformEditAction(() => _editorOperations.InsertText(text));
                    break;

                case (int)VSConstants.VSStd2KCmdID.BACKSPACE:
                    result = this.PerformEditAction(() => _editorOperations.Backspace());
                    break;

                case (int)VSConstants.VSStd2KCmdID.DELETE:
                    result = this.PerformEditAction(() => _editorOperations.Delete());
                    break;

                case (int)VSConstants.VSStd2KCmdID.CANCEL:
                    _editorOperations.ResetSelection();
                    break;

                case (int)VSConstants.VSStd2KCmdID.DOWN_EXT:
                    _editorOperations.MoveLineDown(true);
                    break;

                case (int)VSConstants.VSStd2KCmdID.DOWN:
                    _editorOperations.MoveLineDown(false);
                    break;

                case (int)VSConstants.VSStd2KCmdID.RIGHT_EXT:
                    _editorOperations.MoveToNextCharacter(true);
                    break;

                case (int)VSConstants.VSStd2KCmdID.RIGHT:
                    _editorOperations.MoveToNextCharacter(false);
                    break;

                case (int)VSConstants.VSStd2KCmdID.LEFT_EXT:
                    _editorOperations.MoveToPreviousCharacter(true);
                    break;

                case (int)VSConstants.VSStd2KCmdID.LEFT:
                    _editorOperations.MoveToPreviousCharacter(false);
                    break;

                case (int)VSConstants.VSStd2KCmdID.UP_EXT:
                    _editorOperations.MoveLineUp(true);
                    break;

                case (int)VSConstants.VSStd2KCmdID.UP:
                    _editorOperations.MoveLineUp(false);
                    break;

                case (int)VSConstants.VSStd2KCmdID.HOME_EXT:
                    _editorOperations.MoveToHome(true);
                    break;

                case (int)VSConstants.VSStd2KCmdID.HOME:
                    _editorOperations.MoveToHome(false);
                    break;

                case (int)VSConstants.VSStd2KCmdID.PAGEUP_EXT:
                    _editorOperations.PageUp(true);
                    break;

                case (int)VSConstants.VSStd2KCmdID.PAGEUP:
                    _editorOperations.PageUp(false);
                    break;

                case (int)VSConstants.VSStd2KCmdID.PAGEDN_EXT:
                    _editorOperations.PageDown(true);
                    break;

                case (int)VSConstants.VSStd2KCmdID.PAGEDN:
                    _editorOperations.PageDown(false);
                    break;

                case (int)VSConstants.VSStd2KCmdID.END_EXT:
                    _editorOperations.MoveToEndOfLine(true);
                    break;

                case (int)VSConstants.VSStd2KCmdID.END:
                    _editorOperations.MoveToEndOfLine(false);
                    break;

                case (int)VSConstants.VSStd2KCmdID.BACKTAB:
                    result = this.PerformEditAction(() => _editorOperations.Unindent());
                    break;

                case (int)VSConstants.VSStd2KCmdID.TAB:
                    result = this.PerformEditAction(() => _editorOperations.Indent());
                    break;

                case (int)VSConstants.VSStd2KCmdID.RETURN:
                    result = this.PerformEditAction(() => _editorOperations.InsertNewLine());
                    break;

                case (int)VSConstants.VSStd2KCmdID.CTLMOVERIGHT:
                    _editorOperations.MoveToNextWord(true);
                    break;

                case (int)VSConstants.VSStd2KCmdID.CTLMOVELEFT:
                    _editorOperations.MoveToPreviousWord(true);
                    break;

                case (int)VSConstants.VSStd2KCmdID.TOPLINE_EXT:
                    _editorOperations.MoveToStartOfDocument(true);
                    break;

                case (int)VSConstants.VSStd2KCmdID.BOTTOMLINE_EXT:
                    _editorOperations.MoveToEndOfDocument(true);
                    break;

                case (int)VSConstants.VSStd2KCmdID.INSERT:
                    bool isEnabled = _editorOperations.Options.IsOverwriteModeEnabled();
                    _editorOperations.Options.SetOptionValue(DefaultTextViewOptions.OverwriteModeId, !isEnabled);
                    break;

                case (int)VSConstants.VSStd2KCmdID.DELETEWORDLEFT:
                    result = this.PerformEditAction(() => _editorOperations.DeleteWordToLeft());
                    break;

                case (int)VSConstants.VSStd2KCmdID.DELETEWORDRIGHT:
                    result = this.PerformEditAction(() => _editorOperations.DeleteWordToRight());
                    break;

                case (int)VSConstants.VSStd2KCmdID.SELECTALL:
                    _editorOperations.SelectAll();
                    break;

                case (int)VSConstants.VSStd2KCmdID.SELECTCURRENTWORD:
                    _editorOperations.SelectCurrentWord();
                    break;

                case (int)VSConstants.VSStd2KCmdID.WORDNEXT:
                    _editorOperations.MoveToNextWord(false);
                    break;

                case (int)VSConstants.VSStd2KCmdID.WORDPREV:
                    _editorOperations.MoveToPreviousWord(false);
                    break;

                case (int)VSConstants.VSStd2KCmdID.TOPLINE:
                    _editorOperations.MoveToStartOfDocument(false);
                    break;

                case (int)VSConstants.VSStd2KCmdID.BOTTOMLINE:
                    _editorOperations.MoveToEndOfDocument(false);
                    break;

                case (int)VSConstants.VSStd2KCmdID.SCROLLUP:
                    _editorOperations.ScrollUpAndMoveCaretIfNecessary();
                    break;

                case (int)VSConstants.VSStd2KCmdID.SCROLLDN:
                    _editorOperations.ScrollDownAndMoveCaretIfNecessary();
                    break;

                case (int)VSConstants.VSStd2KCmdID.COPY:
                    _editorOperations.CopySelection();
                    break;

                case (int)VSConstants.VSStd2KCmdID.CUT:
                    return(this.PerformEditAction(() => _editorOperations.CutSelection()));

                case (int)VSConstants.VSStd2KCmdID.PASTE:
                    string pastedText = args as string;

                    if (pastedText != null)
                    {
                        return(this.PerformEditAction(() => _editorOperations.InsertText(pastedText)));
                    }
                    else
                    {
                        return(this.PerformEditAction(() => _editorOperations.Paste()));
                    }

                case (int)VSConstants.VSStd2KCmdID.UNDO:

                    if (UndoManager != null &&
                        UndoManager.TextBufferUndoHistory.CanUndo)
                    {
                        UndoManager.TextBufferUndoHistory.Undo(1);
                        break;
                    }

                    return(CommandResult.Disabled);

                case (int)VSConstants.VSStd2KCmdID.REDO:

                    if (UndoManager != null &&
                        UndoManager.TextBufferUndoHistory.CanRedo)
                    {
                        UndoManager.TextBufferUndoHistory.Redo(1);
                        break;
                    }

                    return(CommandResult.Disabled);

                default:
                    return(CommandResult.NotSupported);
                }

                _braceCompletionTarget.PostProcessInvoke(CommandResult.Executed, group, id, args, ref outargs);
                return(result);
            }

            return(CommandResult.NotSupported);
        }
Пример #2
0
        int IOleCommandTarget.Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            var eval = _interactive.Evaluator;

            // preprocessing
            if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97)
            {
                switch ((VSConstants.VSStd97CmdID)nCmdID)
                {
                case VSConstants.VSStd97CmdID.Cut:
                    if (_editorOps.CutSelection())
                    {
                        return(VSConstants.S_OK);
                    }
                    break;

                case VSConstants.VSStd97CmdID.Copy:
                    if (_editorOps.CopySelection())
                    {
                        return(VSConstants.S_OK);
                    }
                    break;

                case VSConstants.VSStd97CmdID.Paste:
                    string pasting = eval.FormatClipboard();
                    if (pasting != null)
                    {
                        PasteReplCode(
                            _interactive,
                            pasting,
                            (eval as PythonInteractiveEvaluator)?.LanguageVersion ?? PythonLanguageVersion.None
                            ).DoNotWait();

                        return(VSConstants.S_OK);
                    }
                    break;
                }
            }
            else if (pguidCmdGroup == CommonConstants.Std2KCmdGroupGuid)
            {
                //switch ((VSConstants.VSStd2KCmdID)nCmdID) {
                //}
            }
            else if (pguidCmdGroup == GuidList.guidPythonToolsCmdSet)
            {
                switch (nCmdID)
                {
                case PkgCmdIDList.comboIdReplScopes:
                    ScopeComboBoxHandler(pvaIn, pvaOut);
                    return(VSConstants.S_OK);

                case PkgCmdIDList.comboIdReplEvaluators:
                    EvaluatorComboBoxHandler(pvaIn, pvaOut);
                    return(VSConstants.S_OK);

                case PkgCmdIDList.comboIdReplScopesGetList:
                    ScopeComboBoxGetList(pvaOut);
                    return(VSConstants.S_OK);

                case PkgCmdIDList.comboIdReplEvaluatorsGetList:
                    EvaluatorComboBoxGetList(pvaOut);
                    return(VSConstants.S_OK);

                case PkgCmdIDList.cmdidNewInteractiveWindow:
                    return(CloneInteractiveWindow());

                case PkgCmdIDList.cmdidOpenInteractiveScopeInEditor:
                    var path = GetCurrentScopeSourcePath();
                    if (!string.IsNullOrEmpty(path))
                    {
                        PythonToolsPackage.NavigateTo(_serviceProvider, path, Guid.Empty, 0);
                        return(VSConstants.S_OK);
                    }
                    break;
                }
            }

            return(_next.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
Пример #3
0
        /// <summary>
        /// Called from VS when we should handle a command or pass it on.
        /// </summary>
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            // preprocessing
            if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97)
            {
                PythonReplEvaluator eval;
                switch ((VSConstants.VSStd97CmdID)nCmdID)
                {
                case VSConstants.VSStd97CmdID.Cut:
                    if (_textView.Properties.TryGetProperty(typeof(PythonReplEvaluator), out eval))
                    {
                        if (_editorOps.CutSelection())
                        {
                            return(VSConstants.S_OK);
                        }
                    }
                    break;

                case VSConstants.VSStd97CmdID.Copy:
                    if (_textView.Properties.TryGetProperty(typeof(PythonReplEvaluator), out eval))
                    {
                        if (_editorOps.CopySelection())
                        {
                            return(VSConstants.S_OK);
                        }
                    }
                    break;

                case VSConstants.VSStd97CmdID.Paste:
                    if (_textView.Properties.TryGetProperty(typeof(PythonReplEvaluator), out eval))
                    {
                        string pasting = eval.FormatClipboard() ?? Clipboard.GetText();
                        if (pasting != null)
                        {
                            PasteReplCode(eval, pasting);

                            return(VSConstants.S_OK);
                        }
                    }
                    else
                    {
                        string updated = RemoveReplPrompts(_pyService, _textView.Options.GetNewLineCharacter());
                        if (updated != null)
                        {
                            _editorOps.ReplaceSelection(updated);
                            return(VSConstants.S_OK);
                        }
                    }
                    break;

                case VSConstants.VSStd97CmdID.GotoDefn: return(GotoDefinition());

                case VSConstants.VSStd97CmdID.FindReferences: return(FindAllReferences());
                }
            }
            else if (pguidCmdGroup == CommonConstants.Std2KCmdGroupGuid)
            {
                OutliningTaggerProvider.OutliningTagger tagger;
                switch ((VSConstants.VSStd2KCmdID)nCmdID)
                {
                case VSConstants.VSStd2KCmdID.FORMATDOCUMENT:
                    FormatCode(new SnapshotSpan(_textView.TextBuffer.CurrentSnapshot, 0, _textView.TextBuffer.CurrentSnapshot.Length), false);
                    return(VSConstants.S_OK);

                case VSConstants.VSStd2KCmdID.FORMATSELECTION:
                    FormatCode(_textView.Selection.StreamSelectionSpan.SnapshotSpan, true);
                    return(VSConstants.S_OK);

                case VSConstants.VSStd2KCmdID.SHOWMEMBERLIST:
                case VSConstants.VSStd2KCmdID.COMPLETEWORD:
                    var controller = _textView.Properties.GetProperty <IntellisenseController>(typeof(IntellisenseController));
                    if (controller != null)
                    {
                        IntellisenseController.ForceCompletions = true;
                        try {
                            controller.TriggerCompletionSession(
                                (VSConstants.VSStd2KCmdID)nCmdID == VSConstants.VSStd2KCmdID.COMPLETEWORD,
                                true
                                );
                        } finally {
                            IntellisenseController.ForceCompletions = false;
                        }
                        return(VSConstants.S_OK);
                    }
                    break;

                case VSConstants.VSStd2KCmdID.QUICKINFO:
                    controller = _textView.Properties.GetProperty <IntellisenseController>(typeof(IntellisenseController));
                    if (controller != null)
                    {
                        controller.TriggerQuickInfo();
                        return(VSConstants.S_OK);
                    }
                    break;

                case VSConstants.VSStd2KCmdID.PARAMINFO:
                    controller = _textView.Properties.GetProperty <IntellisenseController>(typeof(IntellisenseController));
                    if (controller != null)
                    {
                        controller.TriggerSignatureHelp();
                        return(VSConstants.S_OK);
                    }
                    break;

                case VSConstants.VSStd2KCmdID.OUTLN_STOP_HIDING_ALL:
                    tagger = _textView.GetOutliningTagger();
                    if (tagger != null)
                    {
                        tagger.Disable();
                    }
                    // let VS get the event as well
                    break;

                case VSConstants.VSStd2KCmdID.OUTLN_START_AUTOHIDING:
                    tagger = _textView.GetOutliningTagger();
                    if (tagger != null)
                    {
                        tagger.Enable();
                    }
                    // let VS get the event as well
                    break;

                case VSConstants.VSStd2KCmdID.COMMENT_BLOCK:
                case VSConstants.VSStd2KCmdID.COMMENTBLOCK:
                    if (_textView.CommentOrUncommentBlock(comment: true))
                    {
                        return(VSConstants.S_OK);
                    }
                    break;

                case VSConstants.VSStd2KCmdID.UNCOMMENT_BLOCK:
                case VSConstants.VSStd2KCmdID.UNCOMMENTBLOCK:
                    if (_textView.CommentOrUncommentBlock(comment: false))
                    {
                        return(VSConstants.S_OK);
                    }
                    break;

                case VSConstants.VSStd2KCmdID.EXTRACTMETHOD:
                    ExtractMethod();
                    return(VSConstants.S_OK);

                case VSConstants.VSStd2KCmdID.RENAME:
                    RefactorRename();
                    return(VSConstants.S_OK);
                }
            }
            else if (pguidCmdGroup == GuidList.guidPythonToolsCmdSet)
            {
                switch (nCmdID)
                {
                case PkgCmdIDList.comboIdReplScopes:
                    ScopeComboBoxHandler(pvaIn, pvaOut);
                    return(VSConstants.S_OK);

                case PkgCmdIDList.comboIdReplScopesGetList:
                    ScopeComboBoxGetList(pvaOut);
                    return(VSConstants.S_OK);

                case PkgCmdIDList.cmdidRefactorRenameIntegratedShell:
                    RefactorRename();
                    return(VSConstants.S_OK);

                case PkgCmdIDList.cmdidExtractMethodIntegratedShell:
                    ExtractMethod();
                    return(VSConstants.S_OK);
                }
            }

            return(_next.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }