private int SyncedOperation(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            ITextCaret caret         = m_textView.Caret;
            var        tempTrackList = m_trackList;

            m_trackList = new List <ITrackingPoint>();

            SnapshotPoint snapPoint = tempTrackList[0].GetPoint(m_textView.TextSnapshot);
            int           result    = 0;

            m_dte.UndoContext.Open("Multi-point edit");

            for (int i = 0; i < tempTrackList.Count; i++)
            {
                snapPoint = tempTrackList[i].GetPoint(m_textView.TextSnapshot);
                caret.MoveTo(snapPoint);
                Debug.Print("Caret #" + i + " pos : " + caret.Position);
                result = NextTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
                AddSyncPoint(m_textView.Caret.Position);
            }

            m_dte.UndoContext.Close();

            RedrawScreen();
            return(result);
        }
        public override int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if ((pguidCmdGroup != VSConstants.VSStd2K && pguidCmdGroup != VSConstants.GUID_VSStandardCommandSet97) ||
                (pguidCmdGroup == VSConstants.VSStd2K && nCmdID != BACKSPACE && nCmdID != DELETE) ||
                (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97 && nCmdID != DELETE_LEGACY))
            {
                return(NextTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
            }

            if (            //ConvertTabsToSpaces
                TextView.Selection.IsEmpty &&
                !CaretIsWithinCodeRange &&
                !IsInAutomationFunction &&
                !DisplayHelper.IsCompletionActive &&
                !DisplayHelper.IsSignatureHelpActive
                )
            {
                var handled = false;

                if (pguidCmdGroup == VSConstants.VSStd2K)
                {
                    switch (nCmdID)
                    {
                    case BACKSPACE:
                        handled = HandleBackspaceKey();
                        break;

                    case DELETE:
                        handled = HandleDeleteKey();
                        break;
                    }
                }
                else if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97)
                {
                    switch (nCmdID)
                    {
                    case DELETE_LEGACY:
                        handled = HandleDeleteKey();
                        break;
                    }
                }

                if (handled)
                {
                    return(VSConstants.S_OK);
                }
            }

            return(NextTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
        public override int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (ConvertTabsToSpaces &&
                TextView.Selection.IsEmpty &&
                !CaretIsWithinCodeRange &&
                !IsInAutomationFunction &&
                !DisplayHelper.IsCompletionActive &&
                !DisplayHelper.IsSignatureHelpActive
                )
            {
                var handled = false;

                if (pguidCmdGroup == VSConstants.VSStd2K)
                {
                    switch ((VSConstants.VSStd2KCmdID)nCmdID)
                    {
                    case VSConstants.VSStd2KCmdID.BACKSPACE:
                        handled = HandleBackspaceKey();
                        break;

                    case VSConstants.VSStd2KCmdID.DELETE:
                        handled = HandleDeleteKey();
                        break;
                    }
                }
                else if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97)
                {
                    switch ((VSConstants.VSStd97CmdID)nCmdID)
                    {
                    case VSConstants.VSStd97CmdID.Delete:
                        handled = HandleDeleteKey();
                        break;
                    }
                }

                if (handled)
                {
                    return(VSConstants.S_OK);
                }
            }

            return(NextTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
Exemple #4
0
        int IOleCommandTarget.Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (nCmdID != (uint)VSConstants.VSStd2KCmdID.TYPECHAR && nCmdID != (uint)VSConstants.VSStd2KCmdID.BACKSPACE)
            {
                return(NextTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
            }

            pulse.IncrementExperience(_textView.TextBuffer.ContentType.DisplayName);

            if (_publisher == null)
            {
                _publisher = Task.Factory.StartNew(async() =>
                {
                    Thread.Sleep(10 * 1000); // Hopefully 10 seconds?

                    await pulse.Execute();
                    _publisher = null;
                });
            }

            return(NextTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            Debug.WriteLine(nCmdID);

            if (pguidCmdGroup == typeof(VSConstants.VSStd2KCmdID).GUID)
            {
                switch (nCmdID)
                {
                case ((uint)VSConstants.VSStd2KCmdID.TYPECHAR):
                case ((uint)VSConstants.VSStd2KCmdID.BACKSPACE):
                case ((uint)VSConstants.VSStd2KCmdID.DELETEWORDRIGHT):
                case ((uint)VSConstants.VSStd2KCmdID.DELETEWORDLEFT):
                case ((uint)VSConstants.VSStd2KCmdID.TAB):
                case ((uint)VSConstants.VSStd2KCmdID.LEFT):
                case ((uint)VSConstants.VSStd2KCmdID.RIGHT):
                case ((uint)VSConstants.VSStd2KCmdID.UP):
                case ((uint)VSConstants.VSStd2KCmdID.DOWN):
                case ((uint)VSConstants.VSStd2KCmdID.END):
                case ((uint)VSConstants.VSStd2KCmdID.HOME):
                case ((uint)VSConstants.VSStd2KCmdID.PAGEDN):
                case ((uint)VSConstants.VSStd2KCmdID.PAGEUP):
                case ((uint)VSConstants.VSStd2KCmdID.PASTE):
                case ((uint)VSConstants.VSStd2KCmdID.PASTEASHTML):
                case ((uint)VSConstants.VSStd2KCmdID.BOL):
                case ((uint)VSConstants.VSStd2KCmdID.EOL):
                case ((uint)VSConstants.VSStd2KCmdID.RETURN):
                case ((uint)VSConstants.VSStd2KCmdID.BACKTAB):
                case ((uint)VSConstants.VSStd2KCmdID.WORDPREV):
                case ((uint)VSConstants.VSStd2KCmdID.WORDNEXT):


                    if (m_trackList.Count > 0)
                    {
                        return(SyncedOperation(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
                    }
                    break;

                default:
                    break;
                }
            }
            else if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97)
            {
                switch (nCmdID)
                {
                case ((uint)VSConstants.VSStd97CmdID.Delete):
                case ((uint)VSConstants.VSStd97CmdID.Paste):
                    if (m_trackList.Count > 0)
                    {
                        return(SyncedOperation(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
                    }
                    break;

                default:
                    break;
                }
            }


            switch (nCmdID)
            {
            // When ESC is used, cancel the Multi Edit mode
            case ((uint)VSConstants.VSStd2KCmdID.CANCEL):
                ClearSyncPoints();
                RedrawScreen();
                break;

            default:
                break;
            }

            return(NextTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
        public override int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (ConvertTabsToSpaces &&
                TextView.Selection.IsEmpty &&
                pguidCmdGroup == VSConstants.VSStd2K &&
                !IsInAutomationFunction &&
                !DisplayHelper.IsCompletionActive &&
                !DisplayHelper.IsSignatureHelpActive
                )
            {
                switch (nCmdID)
                {
                case ARROW_LEFT:
                case ARROW_RIGHT:
                    if (CaretIsWithinCodeRange)
                    {
                        goto default;
                    }
                    break;

                case ARROW_UP:
                case ARROW_DOWN:
                    Caret.PositionChanged -= CaretOnPositionChanged;
                    if (!_savedCaretColumn.HasValue)
                    {
                        _savedCaretColumn = VirtualCaretColumn;
                    }
                    break;

                default:
                    _savedCaretColumn = null;
                    return(NextTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
                }

                switch (nCmdID)
                {
                case ARROW_LEFT:
                    Caret.MoveToPreviousCaretPosition();
                    if (CaretCharIsASpace)
                    {
                        MoveCaretToPreviousTabStop();
                        return(VSConstants.S_OK);
                    }
                    Caret.MoveToNextCaretPosition();
                    break;

                case ARROW_RIGHT:
                    if (CaretCharIsASpace)
                    {
                        Caret.MoveToNextCaretPosition();
                        MoveCaretToNextTabStop();
                        return(VSConstants.S_OK);
                    }
                    break;

                case ARROW_UP:
                    try
                    {
                        _snapshotLine = TextView.TextSnapshot.GetLineFromPosition(
                            Caret.Position.BufferPosition.Subtract(CaretColumn + 1));
                        MoveCaretToNearestVirtualTabStop();
                    }
                    catch (ArgumentOutOfRangeException)
                    {
                    }
                    Caret.PositionChanged += CaretOnPositionChanged;
                    return(VSConstants.S_OK);

                case ARROW_DOWN:
                    try
                    {
                        _snapshotLine = FindNextLine();
                        MoveCaretToNearestVirtualTabStop();
                    }
                    catch (ArgumentOutOfRangeException)
                    {
                    }
                    Caret.PositionChanged += CaretOnPositionChanged;
                    return(VSConstants.S_OK);
                }
            }

            return(NextTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
Exemple #7
0
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            Debug.WriteLine(nCmdID);

            if (pguidCmdGroup == typeof(VSConstants.VSStd2KCmdID).GUID)
            {
                switch (nCmdID)
                {
                case ((uint)VSConstants.VSStd2KCmdID.ECMD_LEFTCLICK):
                    if (Keyboard.Modifiers == ModifierKeys.Alt && m_textView.Selection.SelectedSpans.Count == 1)
                    {
                        if (m_trackList.Count == 0)
                        {
                            AddSyncPoint(lastCaretPosition);
                        }
                        AddSyncPoint(m_textView.Caret.Position);
                        RedrawScreen();
                    }
                    else if (m_trackList.Any())
                    {
                        ClearSyncPoints();
                        RedrawScreen();
                    }
                    lastCaretPosition = m_textView.Caret.Position;
                    break;

                case ((uint)VSConstants.VSStd2KCmdID.TYPECHAR):
                case ((uint)VSConstants.VSStd2KCmdID.BACKSPACE):
                case ((uint)VSConstants.VSStd2KCmdID.TAB):
                case ((uint)VSConstants.VSStd2KCmdID.LEFT):
                case ((uint)VSConstants.VSStd2KCmdID.RIGHT):
                case ((uint)VSConstants.VSStd2KCmdID.UP):
                case ((uint)VSConstants.VSStd2KCmdID.DOWN):
                case ((uint)VSConstants.VSStd2KCmdID.END):
                case ((uint)VSConstants.VSStd2KCmdID.HOME):
                case ((uint)VSConstants.VSStd2KCmdID.PAGEDN):
                case ((uint)VSConstants.VSStd2KCmdID.PAGEUP):
                case ((uint)VSConstants.VSStd2KCmdID.PASTE):
                case ((uint)VSConstants.VSStd2KCmdID.PASTEASHTML):
                case ((uint)VSConstants.VSStd2KCmdID.BOL):
                case ((uint)VSConstants.VSStd2KCmdID.EOL):
                case ((uint)VSConstants.VSStd2KCmdID.RETURN):
                case ((uint)VSConstants.VSStd2KCmdID.BACKTAB):



                    if (m_trackList.Count > 0)
                    {
                        return(SyncedOperation(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
                    }
                    break;

                default:
                    break;
                }
            }
            else if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97)
            {
                switch (nCmdID)
                {
                case ((uint)VSConstants.VSStd97CmdID.Delete):
                case ((uint)VSConstants.VSStd97CmdID.Paste):
                    if (m_trackList.Count > 0)
                    {
                        return(SyncedOperation(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
                    }
                    break;

                default:
                    break;
                }
            }


            switch (nCmdID)
            {
            // When ESC is used, cancel the Multi Edit mode
            case ((uint)VSConstants.VSStd2KCmdID.CANCEL):
                ClearSyncPoints();
                RedrawScreen();
                break;

            default:
                break;
            }

            return(NextTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
        public override int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if (nCmdID < ARROW_LEFT ||
                nCmdID > SHIFT_ARROW_DOWN ||
                (!TextView.Selection.IsEmpty && TextView.Selection.Mode == TextSelectionMode.Box) ||
                pguidCmdGroup != VSConstants.VSStd2K ||
                IsInAutomationFunction ||
                DisplayHelper.IsCompletionActive ||
                DisplayHelper.IsSignatureHelpActive)
            {
                _savedCaretColumn = null;
                return(NextTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
            }

            lock (_activeLock)
            {
                try
                {
                    _isActive = true;

                    switch (nCmdID)
                    {
                    case ARROW_LEFT:
                    case ARROW_RIGHT:
                    case SHIFT_ARROW_LEFT:
                    case SHIFT_ARROW_RIGHT:
                        if (CaretIsWithinCodeRange)
                        {
                            goto default;
                        }
                        break;

                    case ARROW_UP:
                    case ARROW_DOWN:
                    case SHIFT_ARROW_UP:
                    case SHIFT_ARROW_DOWN:
                        _allowClearSavedCaretColumn = false;
                        if (!_savedCaretColumn.HasValue)
                        {
                            _savedCaretColumn = VirtualCaretColumn;
                        }
                        break;

                    default:
                        _savedCaretColumn = null;
                        ThreadHelper.ThrowIfNotOnUIThread();
                        return(NextTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
                    }

                    var caretStartingPosition = Caret.Position.VirtualBufferPosition;
                    var selectionAnchorPoint  = TextView.Selection.IsEmpty ? caretStartingPosition : TextView.Selection.AnchorPoint;
                    switch (nCmdID)
                    {
                    case ARROW_LEFT:
                    case SHIFT_ARROW_LEFT:
                        Caret.MoveToPreviousCaretPosition();
                        if (CaretCharIsASpace)
                        {
                            MoveCaretToPreviousTabStop();
                            AdjustTextSelection(nCmdID, selectionAnchorPoint);
                            return(VSConstants.S_OK);
                        }
                        Caret.MoveToNextCaretPosition();
                        break;

                    case ARROW_RIGHT:
                    case SHIFT_ARROW_RIGHT:
                        if (CaretCharIsASpace)
                        {
                            Caret.MoveToNextCaretPosition();
                            MoveCaretToNextTabStop();
                            AdjustTextSelection(nCmdID, selectionAnchorPoint);
                            return(VSConstants.S_OK);
                        }
                        break;

                    case ARROW_UP:
                    case SHIFT_ARROW_UP:
                        try
                        {
                            _snapshotLine = TextView.TextSnapshot.GetLineFromPosition(
                                Caret.Position.BufferPosition.Subtract(CaretColumn + 1));
                            MoveCaretToNearestVirtualTabStop();
                        }
                        catch (ArgumentOutOfRangeException)
                        {
                        }
                        _allowClearSavedCaretColumn = true;
                        AdjustTextSelection(nCmdID, selectionAnchorPoint);
                        return(VSConstants.S_OK);

                    case ARROW_DOWN:
                    case SHIFT_ARROW_DOWN:
                        try
                        {
                            _snapshotLine = FindNextLine();
                            MoveCaretToNearestVirtualTabStop();
                        }
                        catch (ArgumentOutOfRangeException)
                        {
                        }
                        _allowClearSavedCaretColumn = true;
                        AdjustTextSelection(nCmdID, selectionAnchorPoint);
                        return(VSConstants.S_OK);
                    }

                    return(NextTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
                }
                finally
                {
                    _isActive = false;
                }
            }
        }
        private int SyncedOperation(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            int        result = 0;
            ITextCaret caret  = m_textView.Caret;

            if (!addedCurrentCaret)
            {
                AddSyncPoint(caret.Position);
                addedCurrentCaret = true;
            }

            var tempTrackList = m_trackList;

            m_trackList = new List <ITrackingPoint>();

            m_dte.UndoContext.Open("Select Next edit");

            bool deleteSelection = !m_textView.Selection.IsEmpty;

            string currentSelection = m_textView.Selection.SelectedSpans[m_textView.Selection.SelectedSpans.Count - 1].GetText();

            for (int i = 0; i < tempTrackList.Count; i++)
            {
                var trackingMode = tempTrackList[i].TrackingMode;
                var snapPoint    = tempTrackList[i].GetPoint(m_textView.TextSnapshot);
                caret.MoveTo(snapPoint);

                using (var edit = m_textView.TextSnapshot.TextBuffer.CreateEdit())
                {
                    bool applyEdit = false;
                    if (deleteSelection)
                    {
                        if (trackingMode == PointTrackingMode.Negative)
                        {
                            edit.Delete(caret.Position.BufferPosition.Position, currentSelection.Length);
                        }
                        else
                        {
                            edit.Delete(caret.Position.BufferPosition.Position - currentSelection.Length, currentSelection.Length);
                        }
                        applyEdit = true;
                    }

                    switch (nCmdID)
                    {
                    case (uint)VSConstants.VSStd2KCmdID.TYPECHAR:

                        var typedChar = (char)(ushort)Marshal.GetObjectForNativeVariant(pvaIn);
                        edit.Insert(tempTrackList[i].GetPosition(m_textView.TextSnapshot), typedChar.ToString());
                        applyEdit = true;
                        break;

                    case ((uint)VSConstants.VSStd97CmdID.Delete):
                        if (i < tempTrackList.Count - 1 && deleteSelection)
                        {
                            edit.Insert(tempTrackList[i].GetPosition(m_textView.TextSnapshot), "");
                        }
                        break;

                    case ((uint)VSConstants.VSStd97CmdID.Paste):
                        if (i < tempTrackList.Count - 1)
                        {
                            var pasteString = Clipboard.GetText();
                            edit.Insert(tempTrackList[i].GetPosition(m_textView.TextSnapshot), pasteString);
                            applyEdit = true;
                        }
                        break;
                    }

                    if (applyEdit)
                    {
                        edit.Apply();
                    }
                }


                switch (nCmdID)
                {
                case ((uint)VSConstants.VSStd2KCmdID.TYPECHAR):
                    break;

                case ((uint)VSConstants.VSStd97CmdID.Delete):
                    if (!deleteSelection)
                    {
                        result = NextTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
                    }
                    break;

                case ((uint)VSConstants.VSStd97CmdID.Paste):
                    if (i == tempTrackList.Count - 1)
                    {
                        result = NextTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
                    }
                    break;

                default:
                    result = NextTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
                    break;
                }


                AddSyncPoint(m_textView.Caret.Position);
            }

            m_dte.UndoContext.Close();

            RedrawScreen();
            return(result);
        }