コード例 #1
0
ファイル: ViewFilter.cs プロジェクト: Plankankul/SpecSharp
        /// <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); }
        }
コード例 #2
0
ファイル: Source.cs プロジェクト: hesam/SketchSharp
 internal static bool CommandOneOnLine( VsCommands2K command ) {
   switch (command) {
     case VsCommands2K.TYPECHAR:
     case VsCommands2K.BACKSPACE:
     case VsCommands2K.TAB:
     case VsCommands2K.BACKTAB:
     case VsCommands2K.DELETE:
     case VsCommands2K.LEFT:
     case VsCommands2K.LEFT_EXT:
     case VsCommands2K.RIGHT:
     case VsCommands2K.RIGHT_EXT:
       return true;
     default:
       return false;
   }
 }
コード例 #3
0
ファイル: Source.cs プロジェクト: hesam/SketchSharp
    public virtual void OnCommand(IVsTextView textView, VsCommands2K command, bool backward) {
      
      if (textView == null) return;

      int line, idx;
      textView.GetCaretPos(out line, out idx);
      TokenInfo info = GetTokenInfo(textView);
      TokenTrigger triggerClass = info.trigger;

      if ((triggerClass & TokenTrigger.MemberSelect)!=0 && (command == VsCommands2K.TYPECHAR) && this.service.Preferences.AutoListMembers) {
        Trace.WriteLine("Source::OnCommand: member select");
        this.Completion( textView, info, false );
      }
     
      if ((triggerClass & TokenTrigger.MatchBraces)!=0 && this.service.Preferences.EnableMatchBraces) {
        if ( (command != VsCommands2K.BACKSPACE) && ((command == VsCommands2K.TYPECHAR) || this.service.Preferences.EnableMatchBracesAtCaret)) {
          Trace.WriteLine("Source::OnCommand: match braces");
          this.MatchBraces(textView, line, idx, info);
        }
      }

      //displayed & a trigger found
      // todo: This means the method tip disappears if you type "ENTER" 
      // while entering method arguments, which is bad.
      if ((triggerClass & TokenTrigger.MethodTip)!=0 && this.methodData.IsDisplayed) {    
        if (CommandOneOnLine(command) && ((triggerClass & TokenTrigger.MethodTip) == TokenTrigger.ParamNext)) {
          //this is an optimization
          Trace.WriteLine("Source::OnCommand: method info - displayed - adjust parameter" );
          methodData.AdjustCurrentParameter( (backward && idx > 0) ? -1 : +1 );
        }
        else {
          //this is the general case
          Trace.WriteLine("Source::OnCommand: method info - displayed - trigger");
          this.MethodTip( textView, line, (backward && idx > 0) ? idx-1 : idx, info);
        }
      }
        //displayed & complex command
      else if (methodData.IsDisplayed && ! CommandOneOnLine(command)) { 
        Trace.WriteLine("Source::OnCommand: method info - displayed - complex command");
        this.MethodTip(textView, line, idx, info);
      }
        //not displayed & trigger found & character typed & method info enabled
      else if ((triggerClass & TokenTrigger.MethodTip)!=0 && (command == VsCommands2K.TYPECHAR) && this.service.Preferences.ParameterInformation) {
        Trace.WriteLine("Source::OnCommand: method info");
        this.MethodTip(textView, line, idx, info);
      }
    }
コード例 #4
0
ファイル: Source.cs プロジェクト: hesam/SketchSharp
 public virtual void OnCommand(IVsTextView textView, VsCommands2K command, bool backward){
   if (textView == null) return;
   int line, column;
   TokenInfo tokenInfo = this.GetTokenInfo(textView, out line, out column);
   if (backward && column > 0) column--;
   TokenTrigger triggerClass = tokenInfo.trigger;
   if ((triggerClass&TokenTrigger.MemberSelect) != 0 && (command == VsCommands2K.TYPECHAR) && this.service.Preferences.AutoListMembers){
     this.Completion(textView, tokenInfo, line, column, false);
     return;
   }
   if ((triggerClass&TokenTrigger.MatchBraces) != 0 && this.service.Preferences.EnableMatchBraces){
     if ((command != VsCommands2K.BACKSPACE) && ((command == VsCommands2K.TYPECHAR) || this.service.Preferences.EnableMatchBracesAtCaret)){
       this.MatchBraces(textView, line, column, tokenInfo);
     }
   }
   if ((triggerClass&TokenTrigger.MethodTip) != 0 && (command == VsCommands2K.TYPECHAR) && this.service.Preferences.ParameterInformation){
     this.MethodTip(textView, tokenInfo, line, column);
     return;
   }
   if (this.methodData.IsDisplayed && CommandOneOnLine(command)){
     this.MethodTip(textView, tokenInfo, line, column);
   }
 }
コード例 #5
0
ファイル: ViewFilter.cs プロジェクト: Plankankul/SpecSharp
        /// <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); }
        }