예제 #1
0
        public override void HandlePostExec(ref Guid guidCmdGroup, uint nCmdId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut, bool bufferWasChanged)
        {
            VsCommands2K cmd = (VsCommands2K)nCmdId;

            // Special handling of "Toggle all outlining" command
            //CodingUnit: 2010.02.19 normal action back in Toggle All Outlining

            /*if (guidCmdGroup == typeof(VsCommands2K).GUID)
             * {
             *      if ((VsCommands2K)nCmdId == VsCommands2K.OUTLN_TOGGLE_ALL)
             *      {
             *              Source.CollapseAllRegions();
             *              return;
             *      }
             * }*/

            base.HandlePostExec(ref guidCmdGroup, nCmdId, nCmdexecopt, pvaIn, pvaOut, bufferWasChanged);

            if (guidCmdGroup == VSConstants.VSStd2K)
            {
                // workaround: for some reason, UP and DOWN commands are not passed to Source in base.HandlePostExec
                if (cmd == VsCommands2K.UP || cmd == VsCommands2K.DOWN)
                {
                    Source.OnCommand(TextView, cmd, '\0');
                }

                if (_startLine >= 0 && Source.MethodData.IsDisplayed)
                {
                    int line;
                    int pos;

                    TextView.GetCaretPos(out line, out pos);

                    if (line != _startLine || pos != _startPos)
                    {
                        bool backward =
                            cmd == VsCommands2K.BACKSPACE ||
                            cmd == VsCommands2K.BACKTAB ||
                            cmd == VsCommands2K.LEFT ||
                            cmd == VsCommands2K.LEFT_EXT;

                        TokenInfo     info         = Source.GetTokenInfo(line, pos);
                        TokenTriggers triggerClass = info.Trigger;

                        if (!backward && (triggerClass & TokenTriggers.MethodTip) == TokenTriggers.ParameterNext)
                        {
                            Source.MethodData.AdjustCurrentParameter(1);
                        }
                        else
                        {
                            Source.MethodTip(TextView, line, pos, info);
                        }
                    }
                }
            }
        }
예제 #2
0
        /// <include file='doc\ViewFilter.uex' path='docs/doc[@for="ViewFilter.HanelPostExec"]/*' />
        /// <summary>This method hooks up HandleSmartIndent and Source.OnCommand.  </summary>
        public virtual void HandlePostExec(ref Guid guidCmdGroup, uint nCmdId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (guidCmdGroup == VsMenus.guidStandardCommandSet2K)
            {
                VsCommands2K cmd = (VsCommands2K)nCmdId;
                char         ch  = '\0';
                if (cmd == VsCommands2K.TYPECHAR && pvaIn != IntPtr.Zero)
                {
                    Variant v = Variant.ToVariant(pvaIn);
                    ch = v.ToChar();

#if TRACE_EXEC
                    Trace.WriteLine(String.Format("ExecCommand: {0}, '{1}', {2}", cmd.ToString(), ch.ToString(), (int)ch));
#endif
                }

                switch (cmd)
                {
                case VsCommands2K.RETURN:
                    gotEnterKey = true;
                    // Handle smart-indentation after core text editor has
                    // actually performed the newline operation.
                    if (!this.wasCompletionActive && this.service.Preferences.IndentStyle == IndentingStyle.Smart)
                    {
                        if (HandleSmartIndent())
                        {
                            break;
                        }
                    }
                    break;

                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:
                    // check general trigger characters for intellisense
                    this.source.OnCommand(this.textView, cmd, ch);
                    break;
                }
            }
            return;
        }
예제 #3
0
        private void TryHighlightBraces(IVsTextView textView, VsCommands2K command, int line, int idx, TokenInfo tokenInfo)
        {
            // Highlight brace to the left from the caret
            if ((tokenInfo.Trigger & TokenTriggers.MatchBraces) != 0 && Service.Preferences.EnableMatchBraces)
            {
                if ((command != VsCommands2K.BACKSPACE) &&
                    (    /*(command == VsCommands2K.TYPECHAR) ||*/
                        Service.Preferences.EnableMatchBracesAtCaret))
                {
                    //if (!this.LanguageService.IsParsing)
                    HighlightBraces(textView, line, idx);
                    return;
                }
            }

            return;
        }
예제 #4
0
 public override void HandlePostExec(ref Guid guidCmdGroup, uint nCmdId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut, bool bufferWasChanged)
 {
     if (guidCmdGroup == typeof(VsCommands2K).GUID)
     {
         VsCommands2K cmd = (VsCommands2K)nCmdId;
         switch (cmd)
         {
         case VsCommands2K.UP:
         case VsCommands2K.UP_EXT:
         case VsCommands2K.UP_EXT_COL:
         case VsCommands2K.DOWN:
         case VsCommands2K.DOWN_EXT:
         case VsCommands2K.DOWN_EXT_COL:
             Source.OnCommand(TextView, cmd, '\0');
             return;
         }
     }
     base.HandlePostExec(ref guidCmdGroup, nCmdId, nCmdexecopt, pvaIn, pvaOut, bufferWasChanged);
 }
예제 #5
0
        /// <inheritdoc/>
        /// <remarks>
        /// This method handles execution of the <see cref="VsCommands2K.COMMENT_BLOCK"/>
        /// and <see cref="VsCommands2K.UNCOMMENT_BLOCK"/> commands by calling
        /// <see cref="CommentSelection"/> and <see cref="UncommentSelection"/> (respectively)
        /// and returning <see langword="true"/>.
        /// </remarks>
        protected override bool HandlePreExec(ref Guid commandGroup, uint commandId, OLECMDEXECOPT executionOptions, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (commandGroup == typeof(VsCommands2K).GUID)
            {
                VsCommands2K cmd = (VsCommands2K)commandId;
                switch (cmd)
                {
                case VsCommands2K.COMMENT_BLOCK:
                    this.CommentSelection();
                    return(true);

                case VsCommands2K.UNCOMMENT_BLOCK:
                    this.UncommentSelection();
                    return(true);
                }
            }

            return(base.HandlePreExec(ref commandGroup, commandId, executionOptions, pvaIn, pvaOut));
        }
예제 #6
0
        //public override void ProcessHiddenRegions(System.Collections.ArrayList hiddenRegions) {
        //    base.ProcessHiddenRegions(hiddenRegions);
        //    return;
        //}

        //class TextSpanEqCmp : IEqualityComparer<TextSpan> {
        //    public bool Equals(TextSpan x, TextSpan y) {
        //        return x.iStartLine == y.iStartLine && x.iEndLine == y.iEndLine
        //               && x.iEndIndex == y.iEndIndex && x.iStartIndex == y.iStartIndex;
        //    }

        //    public int GetHashCode(TextSpan x) {
        //        return x.iStartLine ^ x.iEndLine ^ x.iEndIndex ^ x.iStartIndex;
        //    }

        //    public static readonly TextSpanEqCmp Instance = new TextSpanEqCmp();
        //}

        //bool _processingOfHiddenRegions;

        //public override MethodData CreateMethodData() {
        //    return MethodData = base.CreateMethodData();
        //}

        public override void OnCommand(IVsTextView textView, VsCommands2K command, char ch)
        {
            if (textView == null || Service == null || !Service.Preferences.EnableCodeSense)
            {
                return;
            }

            base.OnCommand(textView, command, ch);
            return;

            int line, idx;

            textView.GetCaretPos(out line, out idx);

            TokenInfo tokenBeforeCaret = GetTokenInfo(line, idx);

            TryHighlightBraces(textView, command, line, idx, tokenBeforeCaret);

            // This code open completion list if user enter '.'.
            if ((tokenBeforeCaret.Trigger & TokenTriggers.MemberSelect) != 0 && (command == VsCommands2K.TYPECHAR))
            {
                var spaces = new[] { '\t', ' ', '\u000B', '\u000C' };
                var str    = GetText(line, 0, line, idx - 1).Trim(spaces);

                while (str.Length <= 0 && line > 0)   // skip empy lines
                {
                    line--;
                    str = GetLine(line + 1).Trim(spaces);
                }

                if (str.Length > 0)
                {
                    var lastChar = str[str.Length - 1];

                    // Don't show completion list if previous char not one of following:
                    if (char.IsLetterOrDigit(lastChar) || lastChar == ')' || lastChar == ']')
                    {
                        Completion(textView, line, idx, true);
                    }
                }
            }
        }
예제 #7
0
        /// <inheritdoc/>
        /// <remarks>
        /// This command filter supports the <see cref="VsCommands2K.COMMENT_BLOCK"/>
        /// and <see cref="VsCommands2K.UNCOMMENT_BLOCK"/> commands. The commands are
        /// enabled when <see cref="ITextBuffer.CheckEditAccess"/> is <see langword="true"/>.
        /// </remarks>
        protected override OLECMDF QueryCommandStatus(ref Guid group, uint id, OleCommandText oleCommandText)
        {
            if (group == typeof(VsCommands2K).GUID)
            {
                VsCommands2K cmd = (VsCommands2K)id;
                switch (cmd)
                {
                case VsCommands2K.COMMENT_BLOCK:
                case VsCommands2K.UNCOMMENT_BLOCK:
                    if (TextView.TextBuffer.CheckEditAccess())
                    {
                        return(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED);
                    }
                    else
                    {
                        return(OLECMDF.OLECMDF_SUPPORTED);
                    }
                }
            }

            return(base.QueryCommandStatus(ref group, id, oleCommandText));
        }
예제 #8
0
        protected override CommandStatus QueryCommandStatus(ref Guid group, uint id)
        {
            if (group == typeof(VsCommands2K).GUID)
            {
                VsCommands2K cmd = (VsCommands2K)id;
                switch (cmd)
                {
                case VsCommands2K.COMMENT_BLOCK:
                case VsCommands2K.UNCOMMENT_BLOCK:
                    if (TextView.TextBuffer.CheckEditAccess())
                    {
                        return(CommandStatus.Supported | CommandStatus.Enabled);
                    }
                    else
                    {
                        return(CommandStatus.Supported);
                    }
                }
            }

            return(base.QueryCommandStatus(ref group, id));
        }
예제 #9
0
 internal virtual bool HandlePostExec(ref Guid guidCmdGroup, uint nCmdId, uint nCmdexecopt, bool commit, IntPtr pvaIn, IntPtr pvaOut)
 {
     if (guidCmdGroup == typeof(VsCommands2K).GUID)
     {
         VsCommands2K cmd = (VsCommands2K)nCmdId;
         switch (cmd)
         {
         case VsCommands2K.RETURN:
             if (this.completorActiveDuringPreExec && commit)
             {
                 // if the completor was active during the pre-exec we want to let it handle the command first
                 // so we didn't deal with this in pre-exec. If we now get the command, we want to end
                 // the editing of the expansion. We also return that we handled the command so auto-indenting doesn't happen
                 EndTemplateEditing(false);
                 this.completorActiveDuringPreExec = false;
                 return(true);
             }
             break;
         }
     }
     this.completorActiveDuringPreExec = false;
     return(false);
 }
예제 #10
0
        //public override void ProcessHiddenRegions(System.Collections.ArrayList hiddenRegions) {
        //    base.ProcessHiddenRegions(hiddenRegions);
        //    return;
        //}
        //class TextSpanEqCmp : IEqualityComparer<TextSpan> {
        //    public bool Equals(TextSpan x, TextSpan y) {
        //        return x.iStartLine == y.iStartLine && x.iEndLine == y.iEndLine
        //               && x.iEndIndex == y.iEndIndex && x.iStartIndex == y.iStartIndex;
        //    }
        //    public int GetHashCode(TextSpan x) {
        //        return x.iStartLine ^ x.iEndLine ^ x.iEndIndex ^ x.iStartIndex;
        //    }
        //    public static readonly TextSpanEqCmp Instance = new TextSpanEqCmp();
        //}
        //bool _processingOfHiddenRegions;
        //public override MethodData CreateMethodData() {
        //    return MethodData = base.CreateMethodData();
        //}
        public override void OnCommand(IVsTextView textView, VsCommands2K command, char ch)
        {
            if (textView == null || Service == null || !Service.Preferences.EnableCodeSense)
                return;

            base.OnCommand(textView, command, ch);
            return;

            int line, idx;
            textView.GetCaretPos(out line, out idx);

            TokenInfo tokenBeforeCaret = GetTokenInfo(line, idx);

            TryHighlightBraces(textView, command, line, idx, tokenBeforeCaret);

            // This code open completion list if user enter '.'.
            if ((tokenBeforeCaret.Trigger & TokenTriggers.MemberSelect) != 0 && (command == VsCommands2K.TYPECHAR)) {
                var spaces = new[] { '\t', ' ', '\u000B', '\u000C' };
                var str = GetText(line, 0, line, idx - 1).Trim(spaces);

                while (str.Length <= 0 && line > 0) { // skip empy lines
                    line--;
                    str = GetLine(line + 1).Trim(spaces);
                }

                if (str.Length > 0) {
                    var lastChar = str[str.Length - 1];

                    // Don't show completion list if previous char not one of following:
                    if (char.IsLetterOrDigit(lastChar) || lastChar == ')' || lastChar == ']')
                        Completion(textView, line, idx, true);
                }
            }
        }
예제 #11
0
        internal virtual bool HandlePreExec(ref Guid guidCmdGroup, uint nCmdId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (!this.expansionActive || this.expansionSession == null)
            {
                return(false);
            }

            this.completorActiveDuringPreExec = this.IsCompletorActive(this.view);

            if (guidCmdGroup == typeof(VsCommands2K).GUID)
            {
                VsCommands2K cmd = (VsCommands2K)nCmdId;
#if TRACE_EXEC
                Trace.WriteLine(String.Format("ExecCommand: {0}", cmd.ToString()));
#endif
                switch (cmd)
                {
                case VsCommands2K.CANCEL:
                    if (this.completorActiveDuringPreExec)
                    {
                        return(false);
                    }
                    EndTemplateEditing(true);
                    return(true);

                case VsCommands2K.RETURN:
                    bool leaveCaret = false;
                    int  line = 0, col = 0;
                    if (NativeMethods.Succeeded(this.view.GetCaretPos(out line, out col)))
                    {
                        TextSpan span = GetExpansionSpan();
                        if (!TextSpanHelper.ContainsExclusive(span, line, col))
                        {
                            leaveCaret = true;
                        }
                    }
                    if (this.completorActiveDuringPreExec)
                    {
                        return(false);
                    }
                    if (this.completorActiveDuringPreExec)
                    {
                        return(false);
                    }
                    EndTemplateEditing(leaveCaret);
                    if (leaveCaret)
                    {
                        return(false);
                    }
                    return(true);

                case VsCommands2K.BACKTAB:
                    if (this.completorActiveDuringPreExec)
                    {
                        return(false);
                    }
                    this.expansionSession.GoToPreviousExpansionField();
                    return(true);

                case VsCommands2K.TAB:
                    if (this.completorActiveDuringPreExec)
                    {
                        return(false);
                    }
                    this.expansionSession.GoToNextExpansionField(0);     // fCommitIfLast=false
                    return(true);

#if TRACE_EXEC
                case VsCommands2K.TYPECHAR:
                    if (pvaIn != IntPtr.Zero)
                    {
                        Variant v  = Variant.ToVariant(pvaIn);
                        char    ch = v.ToChar();
                        Trace.WriteLine(String.Format("TYPECHAR: {0}, '{1}', {2}", cmd.ToString(), ch.ToString(), (int)ch));
                    }
                    return(true);
#endif
                }
            }
            return(false);
        }
예제 #12
0
        public void OnCommand(IVsTextView textView, VsCommands2K command, char ch)
        {
            if (textView == null || this.service == null || !this.service.Preferences.EnableCodeSense)
                return;

            bool backward = (command == VsCommands2K.BACKSPACE || command == VsCommands2K.BACKTAB || command == VsCommands2K.LEFT || command == VsCommands2K.LEFT_EXT);

            int line, idx;

            var hr = textView.GetCaretPos(out line, out idx);
            if (NativeMethods.Failed(hr))
                return;

            TokenInfo info = GetTokenInfo(line, idx);
            TokenTriggers triggerClass = info.Trigger;


            var matchBraces = false;
            var methodTip = false;
            MethodTipMiscellany misc = 0;

            if ((triggerClass & TokenTriggers.MemberSelect) != 0 && (command == VsCommands2K.TYPECHAR))
            {
                BackgroundRequestReason reason = ((triggerClass & TokenTriggers.MatchBraces) != 0) ? BackgroundRequestReason.MemberSelectAndHighlightBraces : BackgroundRequestReason.MemberSelect;
                this.Completion(textView, info, reason, RequireFreshResults.No);
            }
            else if (this.service.Preferences.EnableMatchBraces &&
                ((command != VsCommands2K.BACKSPACE) && ((command == VsCommands2K.TYPECHAR) || this.service.Preferences.EnableMatchBracesAtCaret)))
            {

                // For brace matching when the caret is before the opening brace, we need to check the token at next index
                TokenInfo nextInfo = GetTokenInfo(line, idx + 1); // ??? overflow
                TokenTriggers nextTriggerClass = nextInfo.Trigger;

                if (((nextTriggerClass & (TokenTriggers.MatchBraces)) != 0) || ((triggerClass & (TokenTriggers.MatchBraces)) != 0))
                    matchBraces = true;
            }

            if ((triggerClass & TokenTriggers.MethodTip) != 0   // open paren, close paren, or comma
                && (command == VsCommands2K.TYPECHAR))          // they typed it, not just arrowed over it
            {
                methodTip = true;

                misc = MethodTipMiscellany.JustPressedOpenParen;
                if ((triggerClass & TokenTriggers.ParameterNext) != 0)
                    misc = MethodTipMiscellany.JustPressedComma;
                if ((triggerClass & TokenTriggers.ParameterEnd) != 0)
                    misc = MethodTipMiscellany.JustPressedCloseParen;
            }
            else if (this.methodData.IsDisplayed)
            {
                if (command == VsCommands2K.BACKSPACE)
                {
                    // the may have just erased a paren or comma, need to re-parse
                    methodTip = true;
                    misc = MethodTipMiscellany.JustPressedBackspace;
                }
                else
                {
                    this.methodData.Refresh(MethodTipMiscellany.Typing);
                }
            }

            if (matchBraces && methodTip)
            {
                // matchBraces = true and methodTip = true

                // backward is true when command is one of these: VsCommands2K.BACKSPACE | VsCommands2K.BACKTAB | VsCommands2K.LEFT | VsCommands2K.LEFT_EXT (1)
                // matchBraces = true when command is not BACKSPACE => BACKSPACE is excluded from the set (1)
                // methodTip = true when command is TYPECHAR or BACKSPACE => BACKSPACE is already excluded and TYPECHAR is not contained in set (1)
                // ergo: backward is always false here
                Debug.Assert(!backward);
                MatchBracesAndMethodTip(textView, line, idx, misc, info);
            }
            else if (matchBraces)
            {
                MatchBraces(textView, line, idx, info);
            }
            else if (methodTip)
            {
                MethodTip(textView, line, (backward && idx > 0) ? idx - 1 : idx, info, misc, RequireFreshResults.No);
            }
        }
예제 #13
0
        protected override int ExecCommand(ref Guid guidCmdGroup, uint nCmdId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if(guidCmdGroup == VSConstants.GUID_VSStandardCommandSet97)
            {
                var cmdId = (VSConstants.VSStd97CmdID)nCmdId;

                switch(cmdId)
                {
                    case VSConstants.VSStd97CmdID.FindReferences:
                        FindReferences();
                        return VSConstants.S_OK;
                }
            }

            //Debug.WriteLine(guidCmdGroup + " " + nCmdId);
            const uint ShowSmartTag = 147;
            if (guidCmdGroup == VSConstants.VSStd2K && nCmdId == ShowSmartTag)
            {
                var textView = TextView.ToITextView();
                var smartTagBroker = textView.GetSmartTagBroker();

                foreach (var session in smartTagBroker.GetSessions(textView))
                {
                    var span = session.ApplicableToSpan.GetSpan(textView.TextSnapshot);

                    if (span.Contains(textView.Caret.Position.BufferPosition.Position))
                    {
                        session.State = SmartTagState.Expanded;
                        return VSConstants.S_OK;
                    }
                }

                //if (smartTagBroker != null && smartTagBroker.IsSmartTagActive(textView))
                return VSConstants.S_OK;
            }

            // hi_octane : found a lot of mistakes comparing the switch
            // ids with PkgCmdID.h and NemerleMenus.cs
            // decided modify the code
            // leaving only two files required to be synchronized

            string txt = null;
            switch ((MenuCmd.CmdId)nCmdId)
            {
                case MenuCmd.CmdId.IplementInterface:

                    break;
                case MenuCmd.CmdId.SetAsMain:
                    txt = "cmdidSetAsMain";
                    break;
                case MenuCmd.CmdId.ExtendSelection:
                    // cmdIdExtendSelection
                    ExpandSelection();
                    // it's prevent repeated execution of comand in base.ExecCommand()
                    return VSConstants.S_OK;
                case MenuCmd.CmdId.ShrinkSelection:
                    // cmdIdShrinkSelection
                    ShrinkSelection();
                    return VSConstants.S_OK;
                case MenuCmd.CmdId.FindInheritors: //cmdIdFindInheritors
                case MenuCmd.CmdId.FindInheritorsCtxt: //cmdIdFindInheritorsCtxt
                    FindInheritors();
                    return VSConstants.S_OK;
                case MenuCmd.CmdId.Rename:
                    txt = "cmdIdRename";
                    RunRenameRefactoring();
                    return VSConstants.S_OK;
                case MenuCmd.CmdId.Inline: // cmdIdInline
                    RunInlineRefactoring();
                    return VSConstants.S_OK;
                case MenuCmd.CmdId.Options:
                    // cmdIdOptions
                    ShowOptions();
                    return VSConstants.S_OK;
                case MenuCmd.CmdId.AstToolWindow: // AstToolWindow
                    Source.ProjectInfo.ProjectNode.Package.OnAstToolWindowShow(null, null);
                    return VSConstants.S_OK;
                case MenuCmd.CmdId.AddHighlighting: // cmdIdAddHighlighting
                    HighlightSymbol();
                    return VSConstants.S_OK;
                case MenuCmd.CmdId.ESC: // ESC
                case MenuCmd.CmdId.RemoveLastHighlighting: // cmdIdRemoveLastHighlighting
                    RemoveLastHighlighting();
                    Source.Service.Hint.Close();
                    if (nCmdId == (int)MenuCmd.CmdId.ESC) // ESC
                        break; // go trocess ESC
                    return VSConstants.S_OK;
                case MenuCmd.CmdId.SourceOutlinerWindow:
                    {
                        if (Source != null)
                            Source.ProjectInfo.ProjectNode.Package.OnSourceOutlinerWindowShow(null, null);
                    }
                    return VSConstants.S_OK;
            }

            Trace.Assert(txt == null, "Implement the menu!\r\nID: " + txt);

            _executingCommand = (VsCommands2K)nCmdId;
            try
            {
                if (guidCmdGroup == Microsoft.VisualStudio.Project.VsMenus.guidStandardCommandSet2K)
                {
                    if (_executingCommand == VsCommands2K.TAB)
                    {
                        int lineIndex;
                        int colIndex;
                        TextView.GetCaretPos(out lineIndex, out colIndex);

                        if (!Source.CompletionSet.IsDisplayed && this.Source.TryDoTableFormating(this, lineIndex + 1, colIndex + 1))
                            return VSConstants.S_OK;
                    }
                }

                var result = base.ExecCommand(ref guidCmdGroup, nCmdId, nCmdexecopt, pvaIn, pvaOut);
                return result;
            }
            finally { _executingCommand = 0; }
        }
예제 #14
0
        /// <include file='doc\ViewFilter.uex' path='docs/doc[@for="ViewFilter.QueryCommandStatus"]/*' />
        /// <summary>
        /// Override this method to intercept the IOleCommandTarget::QueryStatus call.
        /// </summary>
        /// <param name="guidCmdGroup"></param>
        /// <param name="cmd"></param>
        /// <param name="pCmdText">null if info not required by caller</param>
        /// <returns>Usually returns a combination of OLECMDF flags, for example
        /// OLECMDF_ENABLED | OLECMDF_SUPPORTED.
        /// Return E_FAIL if want to delegate to the next command target.
        /// </returns>
        protected virtual int QueryCommandStatus(ref Guid guidCmdGroup, uint nCmdId)
        {
            ExpansionProvider ep = GetExpansionProvider();

            if (ep != null && ep.InTemplateEditingMode)
            {
                int hr = 0;
                if (ep.HandleQueryStatus(ref guidCmdGroup, nCmdId, out hr))
                {
                    return(hr);
                }
            }
            if (guidCmdGroup == VsMenus.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 == VsMenus.guidStandardCommandSet2K)
            {
                VsCommands2K cmd = (VsCommands2K)nCmdId;

                switch (cmd)
                {
                case VsCommands2K.FORMATDOCUMENT:
                    if (this.CanReformat())
                    {
                        return((int)OLECMDF.OLECMDF_SUPPORTED | (int)OLECMDF.OLECMDF_ENABLED);
                    }
                    break;

                case VsCommands2K.FORMATSELECTION:
                    if (this.CanReformat())
                    {
                        return((int)OLECMDF.OLECMDF_SUPPORTED | (int)OLECMDF.OLECMDF_ENABLED);
                    }
                    break;

                case VsCommands2K.COMMENT_BLOCK:
                case VsCommands2K.UNCOMMENT_BLOCK:
                    if (this.commentSupported)
                    {
                        return((int)OLECMDF.OLECMDF_SUPPORTED | (int)OLECMDF.OLECMDF_ENABLED);
                    }
                    break;

                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;

                // Let the core editor handle this.  Stop outlining also removes user
                // defined hidden sections so it is handy to keep this enabled.
                //                    case VsCommands2K.OUTLN_STOP_HIDING_ALL:
                //                        int rc = (int)OLECMDF.OLECMDF_SUPPORTED;
                //                        if (this.source.OutliningEnabled) {
                //                            rc |= (int)OLECMDF.OLECMDF_ENABLED;
                //                        }
                //                        return rc;

                case VsCommands2K.OUTLN_START_AUTOHIDING:
                    if (!this.source.OutliningEnabled)
                    {
                        return((int)OLECMDF.OLECMDF_SUPPORTED | (int)OLECMDF.OLECMDF_ENABLED);
                    }
                    break;

                case VsCommands2K.AUTOCOMPLETE:
                    return((int)OLECMDF.OLECMDF_SUPPORTED | (int)OLECMDF.OLECMDF_ENABLED);
                }
            }
            else if (guidCmdGroup == typeof(LanguageServiceCommands).GUID)
            {
                switch ((LanguageServiceCommands)nCmdId)
                {
                case LanguageServiceCommands.RunTasks:
                    return((int)OLECMDF.OLECMDF_SUPPORTED | (int)OLECMDF.OLECMDF_ENABLED);
                }
            }

            return((int)NativeMethods.E_FAIL); // delegate to next command target.
        }
예제 #15
0
        private void TryHighlightBraces(IVsTextView textView, VsCommands2K command, int line, int idx, TokenInfo tokenInfo)
        {
            // Highlight brace to the left from the caret
            if ((tokenInfo.Trigger & TokenTriggers.MatchBraces) != 0 && Service.Preferences.EnableMatchBraces) {
                if ((command != VsCommands2K.BACKSPACE) &&
                        (/*(command == VsCommands2K.TYPECHAR) ||*/
                            Service.Preferences.EnableMatchBracesAtCaret)) {
                    //if (!this.LanguageService.IsParsing)
                    HighlightBraces(textView, line, idx);
                    return;
                }
            }

            return;
        }
예제 #16
0
        /// <include file='doc\Source.uex' path='docs/doc[@for="Source.OnCommand"]/*' />
        public virtual void OnCommand(IVsTextView textView, VsCommands2K command, char ch)
        {
            if (textView == null || this.service == null || !this.service.Preferences.EnableCodeSense)
                return;

            bool backward = (command == VsCommands2K.BACKSPACE || command == VsCommands2K.BACKTAB ||
                command == VsCommands2K.LEFT || command == VsCommands2K.LEFT_EXT);

            int line, idx;

            NativeMethods.ThrowOnFailure(textView.GetCaretPos(out line, out idx));

            TokenInfo info = GetTokenInfo(line, idx);
            TokenTriggers triggerClass = info.Trigger;

            if ((triggerClass & TokenTriggers.MemberSelect) != 0 && (command == VsCommands2K.TYPECHAR)) {
                ParseReason reason = ((triggerClass & TokenTriggers.MatchBraces) == TokenTriggers.MatchBraces) ? ParseReason.MemberSelectAndHighlightBraces : ParseReason.MemberSelect;
                this.Completion(textView, info, reason);
            } else if ((triggerClass & TokenTriggers.MatchBraces) != 0 && this.service.Preferences.EnableMatchBraces) {
                if ((command != VsCommands2K.BACKSPACE) && ((command == VsCommands2K.TYPECHAR) || this.service.Preferences.EnableMatchBracesAtCaret)) {
                    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 & TokenTriggers.MethodTip) != 0 && this.methodData.IsDisplayed) {
                if ((triggerClass & TokenTriggers.MethodTip) == TokenTriggers.ParameterNext) {
                    //this is an optimization
                    methodData.AdjustCurrentParameter((backward && idx > 0) ? -1 : +1);
                } else {
                    //this is the general case
                    this.MethodTip(textView, line, (backward && idx > 0) ? idx - 1 : idx, info);
                }
            } else if ((triggerClass & TokenTriggers.MethodTip) != 0 && (command == VsCommands2K.TYPECHAR) && this.service.Preferences.ParameterInformation) {
                //not displayed & trigger found & character typed & method info enabled
                this.MethodTip(textView, line, idx, info);
            } else if (methodData.IsDisplayed) {
                //displayed & complex command
                this.MethodTip(textView, line, idx, info);
            }
        }
예제 #17
0
        /// <include file='doc\ViewFilter.uex' path='docs/doc[@for="ViewFilter.HandlePreExec"]/*' />
        public virtual bool HandlePreExec(ref Guid guidCmdGroup, uint nCmdId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            this.wasCompletionActive = this.Source.IsCompletorActive;
            this.gotEnterKey         = false;

            if (guidCmdGroup == VsMenus.guidStandardCommandSet97)
            {
                VsCommands cmd = (VsCommands)nCmdId;
#if TRACE_EXEC
                if (cmd != VsCommands.SolutionCfg && cmd != VsCommands.SearchCombo)
                {
                    Trace.WriteLine(String.Format("ExecCommand: {0}", cmd.ToString()));
                }
#endif
                switch (cmd)
                {
                case VsCommands.GotoDefn:
                case VsCommands.GotoDecl:
                case VsCommands.GotoRef:
                    HandleGoto(cmd);
                    return(true);
                }
            }
            else if (guidCmdGroup == VsMenus.guidStandardCommandSet2K)
            {
                VsCommands2K cmd = (VsCommands2K)nCmdId;
                switch (cmd)
                {
                case VsCommands2K.FORMATDOCUMENT:
                    this.ReformatDocument();
                    return(true);

                case VsCommands2K.FORMATSELECTION:
                    this.ReformatSelection();
                    return(true);

                case VsCommands2K.COMMENT_BLOCK:
                    this.CommentSelection();
                    return(true);

                case VsCommands2K.UNCOMMENT_BLOCK:
                    this.UncommentSelection();
                    return(true);

                case VsCommands2K.COMPLETEWORD: {
                    int line, col;
                    NativeMethods.ThrowOnFailure(this.textView.GetCaretPos(out line, out col));
                    this.source.Completion(this.textView, this.source.GetTokenInfo(line, col), ParseReason.CompleteWord);
                    return(true);
                }

                case VsCommands2K.SHOWMEMBERLIST: {
                    int line, col;
                    NativeMethods.ThrowOnFailure(this.textView.GetCaretPos(out line, out col));
                    this.source.Completion(this.textView, this.source.GetTokenInfo(line, col), ParseReason.DisplayMemberList);
                    return(true);
                }

                case VsCommands2K.PARAMINFO: {
                    int line;
                    int col;
                    NativeMethods.ThrowOnFailure(this.textView.GetCaretPos(out line, out col));
                    this.source.MethodTip(this.textView, line, col, this.source.GetTokenInfo(line, col));
                    return(true);
                }

                case VsCommands2K.QUICKINFO: {
                    HandleQuickInfo();
                    return(true);
                }

                case VsCommands2K.SHOWCONTEXTMENU:
                    this.ShowContextMenu(VsMenus.IDM_VS_CTXT_CODEWIN, VsMenus.guidSHLMainMenu, this);
                    return(true);

                //                    case VsCommands2K.HANDLEIMEMESSAGE:
                //                        if (pvaOut != IntPtr.Zero) {
                //                            Marshal.GetNativeVariantForObject(false, pvaOut); //debug this make sure it's right ...
                //                        }
                //                        break;

                case VsCommands2K.OUTLN_STOP_HIDING_ALL:
                    this.source.OutliningEnabled = false;
                    break;

                case VsCommands2K.OUTLN_START_AUTOHIDING:
                    this.source.OutliningEnabled = true;
                    break;

                case VsCommands2K.AUTOCOMPLETE:
                    // See if completion set just completed.
                    OnAutoComplete();
                    return(true);
                }
            }
            else if (guidCmdGroup == typeof(LanguageServiceCommands).GUID)
            {
                switch ((LanguageServiceCommands)nCmdId)
                {
                case LanguageServiceCommands.RunTasks:
                    this.source.LanguageService.RunTasks();
                    return(true);
                }
            }
            return(false);
        }