コード例 #1
0
        public override void PreprocessMouseMove(MouseEventArgs e)
        {
            ITextViewLineCollection textViewLines = _view.TextViewLines;

            if (textViewLines != null)
            {
                Point position = e.GetPosition(this._view.VisualElement);
                position.X += this._view.ViewportLeft;
                position.Y += this._view.ViewportTop;
                ITextViewLine textViewLineContainingYCoordinate = textViewLines.GetTextViewLineContainingYCoordinate(position.Y);
                if (textViewLineContainingYCoordinate != null)
                {
                    MousePosition = textViewLineContainingYCoordinate.Start.Position;
                }
            }

            base.PreprocessMouseMove(e);
        }
コード例 #2
0
        public static bool TryGetClosestTextViewLine(this ITextView textView, double yCoordinate, out ITextViewLine closestLine)
        {
            if (textView == null)
            {
                throw new ArgumentNullException(nameof(textView));
            }

            if (textView.IsClosed || textView.InLayout)
            {
                closestLine = null;
                return(false);
            }

            ITextViewLine textLine = null;

            ITextViewLineCollection textLines = textView.TextViewLines;

            if (textLines != null && textLines.Count > 0)
            {
                textLine = textLines.GetTextViewLineContainingYCoordinate(yCoordinate);

                if (textLine == null)
                {
                    if (yCoordinate <= textLines.FirstVisibleLine.Bottom)
                    {
                        textLine = textLines.FirstVisibleLine;
                    }
                    else if (yCoordinate >= textLines.LastVisibleLine.Top)
                    {
                        textLine = textLines.LastVisibleLine;
                    }
                }

                closestLine = textLine;
                return(true);
            }

            closestLine = null;
            return(false);
        }
コード例 #3
0
        public override void PreprocessMouseMove(System.Windows.Input.MouseEventArgs e)
        {
            ITextViewLineCollection textLines = _view.TextViewLines;

            if ((textLines != null) && (_visibleBlocks.Count > 0))
            {
                ITextViewLine firstVisible = textLines.FirstVisibleLine;

                Point pt = e.GetPosition(_view.VisualElement);
                pt.X += _view.ViewportLeft;
                pt.Y += _view.ViewportTop;

                //Horrible hack for peek: prevent the tip from showing if the y coordinate is in the space below the bottom of a line's text
                //(which is where the peek adornment would be displayed).
                var line = textLines.GetTextViewLineContainingYCoordinate(pt.Y);
                if ((line != null) && (pt.Y <= line.TextBottom + 1.0))
                {
                    int screenTop = (firstVisible.VisibilityState == VisibilityState.FullyVisible)
                                    ? firstVisible.Start
                                    : firstVisible.EndIncludingLineBreak;

                    foreach (VisibleBlock block in _visibleBlocks)
                    {
                        if ((Math.Abs(pt.X - block.x) < 4.0) &&
                            (pt.Y >= block.yTop) && (pt.Y <= block.yBottom))
                        {
                            SnapshotPoint?statementStart = _view.BufferGraph.MapUpToSnapshot(block.tag.StatementStart, PointTrackingMode.Positive, PositionAffinity.Successor, _view.TextSnapshot);
                            if (statementStart.HasValue && (statementStart.Value < screenTop))
                            {
                                if (_tipWindow == null)
                                {
                                    _tipWindow = new ToolTip();

                                    _tipWindow.ClipToBounds = true;

                                    _tipWindow.Placement                  = PlacementMode.Top;
                                    _tipWindow.PlacementTarget            = _view.VisualElement;
                                    _tipWindow.HorizontalAlignment        = HorizontalAlignment.Left;
                                    _tipWindow.HorizontalContentAlignment = HorizontalAlignment.Left;

                                    _tipWindow.VerticalAlignment        = VerticalAlignment.Top;
                                    _tipWindow.VerticalContentAlignment = VerticalAlignment.Top;
                                }

                                _tipWindow.PlacementRectangle = new Rect(block.x, 0.0, 0.0, 0.0);

                                if (_tipWindow.IsOpen)
                                {
                                    var existingContext = _tipWindow.Content as FrameworkElement;
                                    if ((existingContext != null) && (existingContext.Tag == block.tag))
                                    {
                                        // No changes from the last time we opened the tip.
                                        return;
                                    }
                                }

                                FrameworkElement context = block.tag.Context(_coloring,
                                                                             _view.FormattedLineSource.DefaultTextProperties);
                                context.Tag = block.tag;

                                //The width of the view is in zoomed coordinates so factor the zoom factor into the tip window width computation.
                                double zoom = _view.ZoomLevel / 100.0;
                                _tipWindow.MaxWidth  = Math.Max(100.0, _view.ViewportWidth * zoom * 0.5);
                                _tipWindow.MinHeight = _tipWindow.MaxHeight = context.Height + 12.0;

                                var rd = _formatMap.GetProperties("TextView Background");
                                if (rd.Contains(EditorFormatDefinition.BackgroundBrushId))
                                {
                                    _tipWindow.Background = rd[EditorFormatDefinition.BackgroundBrushId] as Brush;
                                }

                                _tipWindow.Content = context;
                                _tipWindow.IsOpen  = true;

                                StructureMarginElement.LogTipOpened("VS/PPT-Structure/AdornmentTipOpened", context);

                                return;
                            }
                        }
                    }
                }
            }

            this.CloseTip();
        }