/// <summary>
        /// Raises the <see cref="AbstractMargin.MouseDown"/> event.
        /// </summary>
        /// <param name="eventArgs">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
        protected override void OnMouseDown(MouseEventArgs eventArgs)
        {
            Point mousepos     = eventArgs.Location;
            bool  showFolding  = TextArea.Document.TextEditorProperties.EnableFolding;
            int   physicalLine = ((mousepos.Y + TextArea.VirtualTop.Y) / TextArea.TextView.LineHeight);
            int   realline     = TextArea.Document.GetFirstLogicalLine(physicalLine);

            // focus the textarea if the user clicks on the line number view
            TextArea.Focus();

            if (!showFolding || realline < 0 || realline + 1 >= TextArea.Document.TotalNumberOfLines)
            {
                return;
            }

            List <Fold> folds = TextArea.Document.FoldingManager.GetFoldsWithStartAt(realline);

            foreach (Fold fold in folds)
            {
                fold.IsFolded = !fold.IsFolded;
            }

            TextArea.Document.FoldingManager.NotifyFoldingChanged(EventArgs.Empty);
            base.OnMouseDown(eventArgs);
        }
        protected void OnDragOver(object sender, DragEventArgs e)
        {
            if (!_textArea.Focused)
            {
                _textArea.Focus();
            }

            Point p = _textArea.PointToClient(new Point(e.X, e.Y));

            if (_textArea.TextView.DrawingPosition.Contains(p.X, p.Y))
            {
                TextLocation realmousepos = _textArea.TextView.GetLogicalPosition(p.X - _textArea.TextView.DrawingPosition.X, p.Y - _textArea.TextView.DrawingPosition.Y);
                int          lineNr       = Math.Min(_textArea.Document.TotalNumberOfLines - 1, Math.Max(0, realmousepos.Y));
                _textArea.Caret.Position = new TextLocation(realmousepos.X, lineNr);
                _textArea.SetDesiredColumn();
                if (e.Data.GetDataPresent(typeof(string)) && !_textArea.IsReadOnly(_textArea.Caret.Offset))
                {
                    e.Effect = GetDragDropEffect(e);
                }
                else
                {
                    e.Effect = DragDropEffects.None;
                }
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }
Пример #3
0
 /// <summary>
 /// Jumps to a given position in the document.
 /// </summary>
 /// <param name="line">The line.</param>
 /// <param name="column">The column.</param>
 public void JumpTo(int line, int column)
 {
     _textArea.Focus();
     _textArea.SelectionManager.ClearSelection();
     _textArea.Caret.Position = new TextLocation(column, line);
     _textArea.SetDesiredColumn();
     ScrollToCaret();
 }
        void OnMouseDown(object sender, MouseEventArgs e)
        {
            _textArea.MousePositionInternal = e.Location;
            Point mousepos = e.Location;

            if (_doDragDrop)
            {
                return;
            }

            if (_doubleClick)
            {
                _doubleClick = false;
                return;
            }

            if (_textArea.TextView.DrawingPosition.Contains(mousepos.X, mousepos.Y))
            {
                _gotMouseDown = true;
                _textArea.SelectionManager.SelectFrom.Where = WhereFrom.TextArea;
                _button = e.Button;

                // double-click
                if (_button == MouseButtons.Left && e.Clicks == 2)
                {
                    int deltaX = Math.Abs(_lastMouseDownPosition.X - e.X);
                    int deltaY = Math.Abs(_lastMouseDownPosition.Y - e.Y);
                    if (deltaX <= SystemInformation.DoubleClickSize.Width &&
                        deltaY <= SystemInformation.DoubleClickSize.Height)
                    {
                        DoubleClickSelectionExtend();
                        _lastMouseDownPosition = new Point(e.X, e.Y);

                        if (_textArea.SelectionManager.SelectFrom.Where == WhereFrom.Gutter)
                        {
                            if (!_minSelection.IsEmpty && !_maxSelection.IsEmpty && _textArea.SelectionManager.Selections.Count > 0)
                            {
                                _textArea.SelectionManager.Selections[0].StartPosition = _minSelection;
                                _textArea.SelectionManager.Selections[0].EndPosition   = _maxSelection;
                                _textArea.SelectionManager.SelectionStart = _minSelection;

                                _minSelection = TextLocation.Empty;
                                _maxSelection = TextLocation.Empty;
                            }
                        }
                        return;
                    }
                }
                _minSelection = TextLocation.Empty;
                _maxSelection = TextLocation.Empty;

                _lastMouseDownPosition = _mouseDownPosition = new Point(e.X, e.Y);

                if (_button == MouseButtons.Left)
                {
                    Fold marker = _textArea.TextView.GetFoldMarkerFromPosition(mousepos.X - _textArea.TextView.DrawingPosition.X,
                                                                               mousepos.Y - _textArea.TextView.DrawingPosition.Y);
                    if (marker != null && marker.IsFolded)
                    {
                        if (_textArea.SelectionManager.HasSomethingSelected)
                        {
                            _clickedOnSelectedText = true;
                        }

                        TextLocation startLocation = new TextLocation(marker.StartColumn, marker.StartLine);
                        TextLocation endLocation   = new TextLocation(marker.EndColumn, marker.EndLine);
                        _textArea.SelectionManager.SetSelection(new DefaultSelection(_textArea.TextView.Document, startLocation, endLocation));
                        _textArea.Caret.Position = startLocation;
                        _textArea.SetDesiredColumn();
                        _textArea.Focus();
                        return;
                    }

                    if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
                    {
                        ExtendSelectionToMouse();
                    }
                    else
                    {
                        TextLocation realmousepos = _textArea.TextView.GetLogicalPosition(mousepos.X - _textArea.TextView.DrawingPosition.X, mousepos.Y - _textArea.TextView.DrawingPosition.Y);
                        _clickedOnSelectedText = false;

                        int offset = _textArea.Document.PositionToOffset(realmousepos);

                        if (_textArea.SelectionManager.HasSomethingSelected &&
                            _textArea.SelectionManager.IsSelected(offset))
                        {
                            _clickedOnSelectedText = true;
                        }
                        else
                        {
                            _textArea.SelectionManager.ClearSelection();
                            if (mousepos.Y > 0 && mousepos.Y < _textArea.TextView.DrawingPosition.Height)
                            {
                                TextLocation pos = new TextLocation
                                {
                                    X = realmousepos.X,
                                    Y = Math.Min(_textArea.Document.TotalNumberOfLines - 1, realmousepos.Y),
                                };
                                _textArea.Caret.Position = pos;
                                _textArea.SetDesiredColumn();
                            }
                        }
                    }
                }
                else if (_button == MouseButtons.Right)
                {
                    // Rightclick sets the cursor to the click position unless
                    // the previous selection was clicked
                    TextLocation realmousepos = _textArea.TextView.GetLogicalPosition(mousepos.X - _textArea.TextView.DrawingPosition.X, mousepos.Y - _textArea.TextView.DrawingPosition.Y);
                    int          offset       = _textArea.Document.PositionToOffset(realmousepos);
                    if (!_textArea.SelectionManager.HasSomethingSelected ||
                        !_textArea.SelectionManager.IsSelected(offset))
                    {
                        _textArea.SelectionManager.ClearSelection();
                        if (mousepos.Y > 0 && mousepos.Y < _textArea.TextView.DrawingPosition.Height)
                        {
                            TextLocation pos = new TextLocation
                            {
                                X = realmousepos.X,
                                Y = Math.Min(_textArea.Document.TotalNumberOfLines - 1, realmousepos.Y),
                            };
                            _textArea.Caret.Position = pos;
                            _textArea.SetDesiredColumn();
                        }
                    }
                }
            }
            _textArea.Focus();
        }