Example #1
0
        public bool UpdateTip(IVerticalScrollBar margin, MouseEventArgs e, ToolTip tip)
        {
            if ((!_textView.IsClosed) && (_tagger != null) && _previewEnabled)
            {
                Point pt = e.GetPosition(this);
                if ((pt.X >= 0.0) && (pt.X <= this.Width))
                {
                    SnapshotPoint position = _scrollBar.GetBufferPositionOfYCoordinate(pt.Y);

                    IBlockTag deepestTag = null;
                    var       tags       = _tagger.GetTags(new SnapshotSpan(position, 0));
                    foreach (var tagSpan in tags)
                    {
                        if (tagSpan.Tag.Type != BlockType.Unknown)
                        {
                            if ((deepestTag == null) || (tagSpan.Tag.Level > deepestTag.Level))
                            {
                                deepestTag = tagSpan.Tag;
                            }
                        }
                    }

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

                        FrameworkElement context = deepestTag.Context(_coloring,
                                                                      _textView.FormattedLineSource.DefaultTextProperties);

                        context.Tag = deepestTag;

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

                        tip.Content = context;
                        tip.IsOpen  = true;

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

                        return(true);
                    }
                }
            }

            return(false);
        }
Example #2
0
        /// <summary>
        /// Constructor for the StructureMargin.
        /// </summary>
        /// <param name="textViewHost">The IWpfTextViewHost in which this margin will be displayed.</param>
        public StructureMargin(IWpfTextViewHost textViewHost, IVerticalScrollBar scrollBar, StructureMarginFactory factory)
        {
            // Validate
            if (textViewHost == null)
            {
                throw new ArgumentNullException("textViewHost");
            }

            _structureMarginElement = new StructureMarginElement(textViewHost.TextView, scrollBar, factory);
        }
Example #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();
        }