public virtual void HandleGoto(VsCommands cmd) { TextSpan ts = new TextSpan(); // Get the caret position this.textView.GetCaretPos(out ts.iStartLine, out ts.iStartIndex); ts.iEndLine = ts.iStartLine; ts.iEndIndex = ts.iStartIndex; // Get the tip text at that location. // Wait, since the user specifically requested this one... TextSpan span; string url = this.source.OnSyncGoto(cmd, this.textView, ts.iEndLine, ts.iEndIndex, out span); if (url == null || url.Trim() == "") // nothing to show { return; } // Open the referenced document, and scroll to the given location. VsShellInterop.IVsUIHierarchy hierarchy; uint[] itemID = new uint[1]; VsShellInterop.IVsWindowFrame frame; IVsTextView view; VsShell.OpenDocument(this.service.site, url, VsConstants.CLSID_VsCodeWindow, out hierarchy, itemID, out frame, out view); if (view != null) { view.EnsureSpanVisible(span); view.SetSelection(span.iStartLine, span.iStartIndex, span.iEndLine, span.iEndIndex); } }
public override string Goto(VsCommands cmd, IVsTextView textView, int line, int col, out TextSpan span) { span = new TextSpan(); Cci.SourceContext targetPosition = new Cci.SourceContext(); switch (cmd) { case VsCommands.GotoDecl: targetPosition = this.scAuthoringScope.GetPositionOfDeclaration(line, col); break; case VsCommands.GotoDefn: targetPosition = this.scAuthoringScope.GetPositionOfDefinition(line, col); break; case VsCommands.GotoRef: targetPosition = this.scAuthoringScope.GetPositionOfReference(line, col); break; } if (targetPosition.Document != null) { span.iEndIndex = targetPosition.EndColumn - 1; span.iEndLine = targetPosition.EndLine - 1; span.iStartIndex = targetPosition.StartColumn - 1; span.iStartLine = targetPosition.StartLine - 1; return(targetPosition.Document.Name); } else { //TODO: return URL to object browser for imported type information. } return(null); }
public override string Goto(VsCommands cmd, IVsTextView textView, int line, int col, out TextSpan span){ span = new TextSpan(); System.Compiler.SourceContext targetPosition = new System.Compiler.SourceContext(); switch (cmd){ case VsCommands.GotoDecl: targetPosition = this.scAuthoringScope.GetPositionOfDeclaration(line, col); break; case VsCommands.GotoDefn: targetPosition = this.scAuthoringScope.GetPositionOfDefinition(line, col); break; case VsCommands.GotoRef: targetPosition = this.scAuthoringScope.GetPositionOfReference(line, col); break; } if (targetPosition.Document != null){ span.iEndIndex = targetPosition.EndColumn-1; span.iEndLine = targetPosition.EndLine-1; span.iStartIndex = targetPosition.StartColumn-1; span.iStartLine = targetPosition.StartLine-1; return targetPosition.Document.Name; }else{ //TODO: return URL to object browser for imported type information. } return null; }
public void Initialize() { VsCommands.Initialize(); CommandsBox.Text = VsCommands.Commands.Aggregate((a, b) => $"{a}{Environment.NewLine}{b}"); AssignedClickLabel.Text = CustomOptions.ClickAction; AssignedRightLabel.Text = CustomOptions.RightAction; AssignedLeftLabel.Text = CustomOptions.LeftAction; }
protected override int ExecCommand(ref Guid guidCmdGroup, uint nCmdId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) { // todo: we really need to pass all of IOleCommandTarget through to the control // so it can decide what to implement. In fact, we should do all of // IOleInPlaceUIWindow so the control can even add menu items. if (guidCmdGroup == VsConstants.guidStandardCommandSet97) { VsCommands cmd = (VsCommands)nCmdId; int msg = 0; IntPtr wParam = IntPtr.Zero; switch (cmd) { case VsCommands.Cut: msg = NativeWindowHelper.WM_CUT; break; case VsCommands.Copy: msg = NativeWindowHelper.WM_COPY; break; case VsCommands.Paste: msg = NativeWindowHelper.WM_PASTE; break; case VsCommands.Undo: msg = NativeWindowHelper.WM_UNDO; break; case VsCommands.Delete: msg = NativeWindowHelper.WM_KEYDOWN; wParam = (IntPtr)(int)Keys.Delete; break; } if (msg != 0) { Control target = Control.FromHandle(NativeWindowHelper.GetFocus()); if (target != null) { IntPtr rc = NativeWindowHelper.SendMessage(target.Handle, msg, wParam, IntPtr.Zero); if ((int)rc == 0) { return(0); } } } } return(base.ExecCommand(ref guidCmdGroup, nCmdId, nCmdexecopt, pvaIn, pvaOut)); }
/// <summary> /// Override this method to intercept the IOleCommandTarget::QueryStatus call. /// </summary> /// <param name="guidCmdGroup"></param> /// <param name="cmd"></param> /// <returns>Usually returns OLECMDF_ENABLED | OLECMDF_SUPPORTED /// or return OLECMDERR_E_UNKNOWNGROUP if you don't handle this command /// </returns> protected virtual int QueryCommandStatus(ref Guid guidCmdGroup, uint nCmdId) { if (guidCmdGroup == VsConstants.guidStandardCommandSet97) { VsCommands cmd = (VsCommands)nCmdId; switch (cmd) { case VsCommands.GotoDefn: case VsCommands.GotoDecl: case VsCommands.GotoRef: return((int)OLECMDF.OLECMDF_SUPPORTED | (int)OLECMDF.OLECMDF_ENABLED); } } else if (guidCmdGroup == VsConstants.guidStandardCommandSet2K) { VsCommands2K cmd = (VsCommands2K)nCmdId; switch (cmd) { case VsCommands2K.COMMENT_BLOCK: case VsCommands2K.UNCOMMENT_BLOCK: if (this.source == null || !this.source.CommentSupported) { break; } return((int)OLECMDF.OLECMDF_SUPPORTED | (int)OLECMDF.OLECMDF_ENABLED); case VsCommands2K.SHOWMEMBERLIST: case VsCommands2K.COMPLETEWORD: case VsCommands2K.PARAMINFO: return((int)OLECMDF.OLECMDF_SUPPORTED | (int)OLECMDF.OLECMDF_ENABLED); case VsCommands2K.QUICKINFO: if (this.service.Preferences.EnableQuickInfo) { return((int)OLECMDF.OLECMDF_SUPPORTED | (int)OLECMDF.OLECMDF_ENABLED); } break; case VsCommands2K.HANDLEIMEMESSAGE: return(0); } } unchecked { return((int)OleDocumentError.OLECMDERR_E_UNKNOWNGROUP); } }
public virtual string OnSyncGoto(VsCommands cmd, IVsTextView textView, int line, int col, out TextSpan span) { // synchronous parse and return definition location. string text = this.GetTextUpToLine(line+1); string fname = this.GetFilePath(); ParseReason reason = ParseReason.Autos; AuthoringSink sink = new AuthoringSink(reason, line, col); AuthoringScope scope = this.service.ParseSource(text, line, col, fname, sink, reason); if (scope != null) { return scope.Goto(cmd, textView, line, col, out span); } else { span = new TextSpan(); } return null; }
public virtual void HandleGoto(VsCommands cmd) { TextSpan ts = new TextSpan(); // Get the caret position this.textView.GetCaretPos(out ts.iStartLine, out ts.iStartIndex); ts.iEndLine = ts.iStartLine; ts.iEndIndex = ts.iStartIndex; // Get the tip text at that location. // Wait, since the user specifically requested this one... TextSpan span; string url = this.source.OnSyncGoto(cmd, this.textView, ts.iEndLine, ts.iEndIndex, out span); if (url == null || url.Trim() == "") { // nothing to show return; } // Open the referenced document, and scroll to the given location. VsShellInterop.IVsUIHierarchy hierarchy; uint itemID; VsShellInterop.IVsWindowFrame frame; IVsTextView view; VsShell.OpenDocument(this.service.site, url, out hierarchy, out itemID, out frame, out view); if (view != null) { view.EnsureSpanVisible(span); view.SetSelection(span.iStartLine, span.iStartIndex, span.iEndLine, span.iEndIndex); } }
public abstract string Goto(VsCommands cmd, IVsTextView textView, int line, int col, out TextSpan span);
/// <summary> /// Override this method to intercept the IOleCommandTarget::Exec call. /// </summary> /// <returns>Usually returns 0 if ok, or OLECMDERR_E_NOTSUPPORTED</returns> protected virtual int ExecCommand(ref Guid guidCmdGroup, uint nCmdId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) { if (guidCmdGroup == VsConstants.guidStandardCommandSet97) { VsCommands cmd = (VsCommands)nCmdId; switch (cmd) { case VsCommands.GotoDefn: case VsCommands.GotoDecl: case VsCommands.GotoRef: HandleGoto(cmd); return(0); } } else if (guidCmdGroup == VsConstants.guidStandardCommandSet2K) { VsCommands2K cmd = (VsCommands2K)nCmdId; switch (cmd) { case VsCommands2K.COMMENT_BLOCK: this.source.CommentSelection(this.textView); return(0); case VsCommands2K.UNCOMMENT_BLOCK: this.source.UnCommentSelection(this.textView); return(0); case VsCommands2K.COMPLETEWORD: { int line; int idx; this.source.Completion(this.textView, this.source.GetTokenInfo(this.textView, out line, out idx), line, idx, true); return(0); } case VsCommands2K.SHOWMEMBERLIST: { int line; int idx; this.source.Completion(this.textView, this.source.GetTokenInfo(this.textView, out line, out idx), line, idx, false); return(0); } case VsCommands2K.PARAMINFO: { int line; int idx; this.source.MethodTip(this.textView, this.source.GetTokenInfo(this.textView, out line, out idx), line, idx); return(0); } case VsCommands2K.QUICKINFO: { HandleQuickInfo(); return(0); } case VsCommands2K.SHOWCONTEXTMENU: this.service.ShowContextMenu(VsConstants.IDM_VS_CTXT_CODEWIN, VsConstants.guidSHLMainMenu); return(0); case VsCommands2K.HANDLEIMEMESSAGE: if (pvaOut != IntPtr.Zero) { Marshal.GetNativeVariantForObject(false, pvaOut); //debug this make sure it's right ... } return(this.nextTarget.Exec(ref guidCmdGroup, nCmdId, nCmdexecopt, pvaIn, pvaOut)); case VsCommands2K.BACKSPACE: case VsCommands2K.BACKTAB: case VsCommands2K.LEFT: case VsCommands2K.LEFT_EXT: { // check method data to see if we need to AdjustCurrentParameter appropriately. this.source.OnCommand(this.textView, cmd, true); int rc = this.nextTarget.Exec(ref guidCmdGroup, nCmdId, nCmdexecopt, pvaIn, pvaOut); return(rc); } case VsCommands2K.TYPECHAR: default: { // check general trigger characters for intellisense, but insert the new char into // the text buffer first. int rc = this.nextTarget.Exec(ref guidCmdGroup, nCmdId, nCmdexecopt, pvaIn, pvaOut); this.source.OnCommand(this.textView, cmd, false); return(rc); } } } unchecked { return((int)OleDocumentError.OLECMDERR_E_NOTSUPPORTED); } }