コード例 #1
0
        private static int RouteExec(Func <CommandTargetParameters, RoutedCommand, bool> canExecuteFunc, Action <CommandTargetParameters, RoutedCommand> executeFunc, ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            RoutedCommand command = InheritanceMarginPackage.Instance.FindCommand(pguidCmdGroup, nCmdID);

            if (command == null)
            {
                return((int)OleConstants.MSOCMDERR_E_UNKNOWNGROUP);
            }

            CommandTargetParameters @params = CommandTargetParameters.CreateInstance(nCmdID);

            @params.InArgs = (pvaIn == IntPtr.Zero) ? null : Marshal.GetObjectForNativeVariant(pvaIn);
            if (canExecuteFunc(@params, command))
            {
                try
                {
                    executeFunc(@params, command);
                    return(VSConstants.S_OK);
                }
                catch (COMException exception)
                {
                    return(exception.ErrorCode);
                }
            }

            return((int)OleConstants.MSOCMDERR_E_NOTSUPPORTED);
        }
コード例 #2
0
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (pguidCmdGroup == VSConstants.VSStd2K)
            {
                switch ((VSConstants.VSStd2KCmdID)nCmdID)
                {
                case VSConstants.VSStd2KCmdID.TYPECHAR:
                    var ch = (char)(ushort)Marshal.GetObjectForNativeVariant(pvaIn);
                    if (_curSession != null && !_curSession.IsDismissed)
                    {
                        if (_curSession.SelectedCompletionSet.SelectionStatus.IsSelected &&
                            IsCompletionChar(ch))
                        {
                            _curSession.Commit();
                        }
                    }
                    switch (ch)
                    {
                    case '<':
                        if (_curSession != null)
                        {
                            _curSession.Dismiss();
                        }
                        int res = _oldTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
                        if (ErrorHandler.Succeeded(res))
                        {
                            _curSession = CompletionBroker.TriggerCompletion(_textView);
                            if (_curSession != null)
                            {
                                _curSession.Dismissed += CurSessionDismissedOrCommitted;
                                _curSession.Committed += CurSessionDismissedOrCommitted;
                            }
                        }
                        return(res);
                    }
                    break;

                case VSConstants.VSStd2KCmdID.RETURN:
                case VSConstants.VSStd2KCmdID.TAB:
                    if (_curSession != null && !_curSession.IsDismissed)
                    {
                        _curSession.Commit();
                        return(VSConstants.S_OK);
                    }
                    break;
                }
            }

            return(_oldTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
コード例 #3
0
        public virtual bool PreprocessCommand(ref Guid commandGroup, uint commandId, OLECMDEXECOPT executionOptions, IntPtr pvaIn, IntPtr pvaOut)
        {
            _isProcessingCommand = true;
            if (!IsCompletionActive)
            {
                return(false);
            }

            if (commandGroup == VsMenus.guidStandardCommandSet97)
            {
                if (commandId == (uint)VsCommands.Delete)
                {
                    return(false);
                }
            }
            else if (commandGroup == VsMenus.guidStandardCommandSet2K)
            {
                switch ((VsCommands2K)commandId)
                {
                case VsCommands2K.WORDPREV:
                case VsCommands2K.WORDPREV_EXT:
                case VsCommands2K.WORDNEXT:
                case VsCommands2K.WORDNEXT_EXT:
                case VsCommands2K.CANCEL:
                case VsCommands2K.BACKSPACE:
                case VsCommands2K.DELETE:
                case VsCommands2K.LEFT:
                case VsCommands2K.LEFT_EXT:
                case VsCommands2K.RIGHT:
                case VsCommands2K.RIGHT_EXT:
                case VsCommands2K.UP:
                case VsCommands2K.UP_EXT:
                case VsCommands2K.DOWN:
                case VsCommands2K.DOWN_EXT:
                case VsCommands2K.BOL:
                case VsCommands2K.BOL_EXT:
                case VsCommands2K.FIRSTCHAR:
                case VsCommands2K.FIRSTCHAR_EXT:
                case VsCommands2K.EOL:
                case VsCommands2K.EOL_EXT:
                case VsCommands2K.PAGEUP:
                case VsCommands2K.PAGEUP_EXT:
                case VsCommands2K.PAGEDN:
                case VsCommands2K.PAGEDN_EXT:
                case VsCommands2K.TOPLINE:
                case VsCommands2K.TOPLINE_EXT:
                case VsCommands2K.BOTTOMLINE:
                case VsCommands2K.BOTTOMLINE_EXT:
                case VsCommands2K.LEFT_EXT_COL:
                case VsCommands2K.RIGHT_EXT_COL:
                case IntellisenseCommandFilter.ECMD_INCREASEFILTER:
                case VsCommands2K.ECMD_DECREASEFILTER:
                case VsCommands2K.ECMD_LEFTCLICK:
                    return(false);

                case (VsCommands2K)95:
                case VsCommands2K.BACKTAB:
                case VsCommands2K.HOME:
                case VsCommands2K.HOME_EXT:
                case VsCommands2K.END:
                case VsCommands2K.END_EXT:
                case VsCommands2K.LASTCHAR:
                case VsCommands2K.LASTCHAR_EXT:
                    break;

                case VsCommands2K.TYPECHAR:
                    char c = Convert.ToChar(Marshal.GetObjectForNativeVariant(pvaIn));
                    if (IsCommitChar(c))
                    {
                        if (CompletionSession.SelectedCompletionSet.SelectionStatus.Completion == null)
                        {
                            DismissCompletion();
                        }
                        else
                        {
                            CompletionInfo.CommitChar = c;
                            return(CommitCompletion());
                        }
                    }

                    return(false);

                case VsCommands2K.RETURN:
                    CompletionInfo.CommitChar = '\n';
                    return(CommitCompletion());

                case VsCommands2K.TAB:
                case VsCommands2K.OPENLINEABOVE:
                    var selectionStatus = CompletionSession.SelectedCompletionSet.SelectionStatus;
                    CompletionSession.SelectedCompletionSet.SelectionStatus = new CompletionSelectionStatus(selectionStatus.Completion, true, selectionStatus.IsUnique);
                    CompletionInfo.CommitChar = (VsCommands2K)commandId == VsCommands2K.TAB ? (char?)'\t' : null;
                    return(CommitCompletion());

                case VsCommands2K.ToggleConsumeFirstCompletionMode:
                    return(false);
                }
            }

            return(false);
        }
コード例 #4
0
        protected override void HandlePostExec(ref Guid commandGroup, uint commandId, uint executionOptions, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (commandGroup == VsMenus.guidStandardCommandSet2K)
            {
                switch ((VSConstants.VSStd2KCmdID)commandId)
                {
                case VSConstants.VSStd2KCmdID.TYPECHAR:
                    //case VSConstants.VSStd2KCmdID.BACKSPACE:
                    //case VSConstants.VSStd2KCmdID.TAB:
                    //case VSConstants.VSStd2KCmdID.BACKTAB:
                    //case VSConstants.VSStd2KCmdID.DELETE:
                    char typedChar = Convert.ToChar(Marshal.GetObjectForNativeVariant(pvaIn));
                    switch (typedChar)
                    {
                    /* currently only implemented for $ references */
                    //case '@':
                    //case ':':
                    case '$':
                        //case '.':
                        SnapshotPoint currentPosition = TextView.Caret.Position.BufferPosition;
                        TextExtent    wordExtent      = TextStructureNavigator.GetExtentOfWord(currentPosition);
                        SnapshotSpan  wordSpan        = wordExtent.Span;
                        if (wordExtent.Span.Start >= currentPosition)
                        {
                            wordExtent = TextStructureNavigator.GetExtentOfWord(currentPosition - 1);
                            wordSpan   = wordExtent.Span;
                        }

                        if (wordSpan.End == currentPosition && wordSpan.Length <= 2)
                        {
                            string wordText = wordSpan.GetText();
                            switch (wordText)
                            {
                            case "@":
                            case "$":
                            {
                                ITrackingPoint triggerPoint = currentPosition.Snapshot.CreateTrackingPoint(currentPosition, PointTrackingMode.Positive);
                                base.Controller.TriggerCompletion(triggerPoint, CompletionInfoType.AutoListMemberInfo, IntellisenseInvocationType.IdentifierChar);
                            }
                            break;

                            case ".":
                            case "::":
                            {
                                ITrackingPoint triggerPoint = currentPosition.Snapshot.CreateTrackingPoint(currentPosition, PointTrackingMode.Positive);
                                base.Controller.TriggerCompletion(triggerPoint, CompletionInfoType.AutoListMemberInfo, IntellisenseInvocationType.ShowMemberList);
                            }
                            break;

                            default:
                                break;
                            }
                        }

                        break;

                    default:
                        break;
                    }
                    break;

                default:
                    break;
                }
            }

            base.HandlePostExec(ref commandGroup, commandId, executionOptions, pvaIn, pvaOut);
        }