public void SetSnapshotAndUpdate(ITextSnapshot snapshot, IList <ITextViewLine> newOrReformattedLines, IList <ITextViewLine> translatedLines)
        {
            if (_glyphs.Count > 0)
            {
                // Go through all the existing visuals and invalidate or transform as appropriate.
                Dictionary <UIElement, GlyphData> newVisuals = new Dictionary <UIElement, GlyphData>(_glyphs.Count);

                foreach (var glyph in _glyphs)
                {
                    GlyphData data = glyph.Value;

                    if (!data.VisualSpan.HasValue)
                    {
                        newVisuals[glyph.Key] = data;
                    }
                    else
                    {
                        data.SetSnapshot(snapshot);

                        SnapshotSpan span = data.VisualSpan.Value;

                        if ((!_margin.TextView.TextViewLines.IntersectsBufferSpan(span)) ||
                            (GetStartingLine(newOrReformattedLines, span, returnLastLine: false) != null))
                        {
                            //Either visual is no longer visible or it crosses a line
                            //that was reformatted.

                            _canvas.Children.Remove(data.Element);
                        }
                        else
                        {
                            newVisuals[data.Element] = data;
                            ITextViewLine line = GetStartingLine(translatedLines, span, returnLastLine: true);
                            if (line != null)
                            {
                                data.SetTop(line.Top - _margin.TextView.ViewportTop);
                            }
                        }
                    }
                }

                _glyphs = newVisuals;
            }
        }
        public void AddGlyph(string text, SnapshotSpan span)
        {
            IWpfTextViewLineCollection lines = _margin.TextView.TextViewLines;

            bool visible = _margin.TextView.TextViewLines.IntersectsBufferSpan(span);

            if (visible)
            {
                ITextViewLine line = GetStartingLine(lines, span, returnLastLine: true);
                if (line != null)
                {
                    UIElement element = CreatePromptElement(text);

                    element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                    double leftPlacement = (17.0 - element.DesiredSize.Width) / 2;
                    Canvas.SetLeft(element, leftPlacement);
                    GlyphData data = new GlyphData(span, element);
                    data.SetTop(line.TextTop - _margin.TextView.ViewportTop);

                    _glyphs[element] = data;
                    _canvas.Children.Add(element);
                }
            }
        }
Пример #3
0
        public void AddGlyph(string text, SnapshotSpan span)
        {
            IWpfTextViewLineCollection lines = _margin.TextView.TextViewLines;

            bool visible = _margin.TextView.TextViewLines.IntersectsBufferSpan(span);
            if (visible) {
                ITextViewLine line = GetStartingLine(lines, span, returnLastLine: true);
                if (line != null) {
                    UIElement element = CreatePromptElement(text);

                    element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                    double leftPlacement = (17.0 - element.DesiredSize.Width) / 2;
                    Canvas.SetLeft(element, leftPlacement);
                    GlyphData data = new GlyphData(span, element);
                    data.SetTop(line.TextTop - _margin.TextView.ViewportTop);

                    _glyphs[element] = data;
                    _canvas.Children.Add(element);
                }
            }
        }