/// <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) { switch ((VSConstants.VSStd97CmdID)nCmdID) { case VSConstants.VSStd97CmdID.Paste: string updated = RemoveReplPrompts(_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.RETURN: if (PythonToolsPackage.Instance.LangPrefs.IndentMode == vsIndentStyle.vsIndentStyleSmart) { // smart indent AutoIndent.HandleReturn(_textView); return(VSConstants.S_OK); } break; case VSConstants.VSStd2KCmdID.BACKSPACE: if (PythonToolsPackage.Instance.LangPrefs.IndentMode == vsIndentStyle.vsIndentStyleSmart && _textView.Selection.IsEmpty) { int indentSize = _textView.Options.GetIndentSize(); // smart dedent var containingLine = _textView.Caret.Position.BufferPosition.GetContainingLine(); var curLineLine = containingLine.GetText(); int lineOffset = _textView.Caret.Position.BufferPosition.Position - containingLine.Start.Position; if (lineOffset >= indentSize) { bool allSpaces = true; for (int i = lineOffset - 1; i >= lineOffset - indentSize; i--) { if (curLineLine[i] != ' ') { allSpaces = false; break; } } if (allSpaces) { _textView.TextBuffer.Delete(new Span(_textView.Caret.Position.BufferPosition.Position - indentSize, indentSize)); return(VSConstants.S_OK); } } } break; case VSConstants.VSStd2KCmdID.SHOWMEMBERLIST: case VSConstants.VSStd2KCmdID.COMPLETEWORD: var controller = _textView.Properties.GetProperty <IntellisenseController>(typeof(IntellisenseController)); if (controller != null) { controller.TriggerCompletionSession((VSConstants.VSStd2KCmdID)nCmdID == VSConstants.VSStd2KCmdID.COMPLETEWORD); return(VSConstants.S_OK); } break; case VSConstants.VSStd2KCmdID.OUTLN_STOP_HIDING_ALL: tagger = _textView.TextBuffer.GetOutliningTagger(); if (tagger != null) { tagger.Disable(); } // let VS get the event as well break; case VSConstants.VSStd2KCmdID.OUTLN_START_AUTOHIDING: tagger = _textView.TextBuffer.GetOutliningTagger(); if (tagger != null) { tagger.Enable(); } // let VS get the event as well break; case VSConstants.VSStd2KCmdID.COMMENT_BLOCK: case VSConstants.VSStd2KCmdID.COMMENTBLOCK: _textView.CommentBlock(); break; case VSConstants.VSStd2KCmdID.UNCOMMENT_BLOCK: case VSConstants.VSStd2KCmdID.UNCOMMENTBLOCK: _textView.UncommentBlock(); break; } } else if (pguidCmdGroup == GuidList.guidPythonToolsCmdSet) { foreach (var command in PythonToolsPackage.Commands) { if (command.CommandId == nCmdID) { command.DoCommand(this, EventArgs.Empty); return(VSConstants.S_OK); } } } return(_next.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut)); }
/// <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) { switch ((VSConstants.VSStd97CmdID)nCmdID) { 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.RETURN: if (IronRubyToolsPackage.Instance.OptionsPage.AutoIndent) { AutoIndent.HandleReturn(_textView, (IClassifier)_textView.TextBuffer.Properties.GetProperty(typeof(IDlrClassifier))); return(VSConstants.S_OK); } break; #if FEATURE_INTELLISENSE case VSConstants.VSStd2KCmdID.SHOWMEMBERLIST: case VSConstants.VSStd2KCmdID.COMPLETEWORD: var controller = _textView.Properties.GetProperty <IntellisenseController>(typeof(IntellisenseController)); if (controller != null) { controller.TriggerCompletionSession((VSConstants.VSStd2KCmdID)nCmdID == VSConstants.VSStd2KCmdID.COMPLETEWORD); return(VSConstants.S_OK); } break; #endif case VSConstants.VSStd2KCmdID.OUTLN_STOP_HIDING_ALL: tagger = _textView.TextBuffer.GetOutliningTagger(); if (tagger != null) { tagger.Disable(); } // let VS get the event as well break; case VSConstants.VSStd2KCmdID.OUTLN_START_AUTOHIDING: tagger = _textView.TextBuffer.GetOutliningTagger(); if (tagger != null) { tagger.Enable(); } // let VS get the event as well break; case VSConstants.VSStd2KCmdID.COMMENT_BLOCK: case VSConstants.VSStd2KCmdID.COMMENTBLOCK: _textView.CommentBlock(); break; case VSConstants.VSStd2KCmdID.UNCOMMENT_BLOCK: case VSConstants.VSStd2KCmdID.UNCOMMENTBLOCK: _textView.UncommentBlock(); break; } } return(_next.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut)); }