SixPairs

July 10, 2014

Simplest Margin Glyph

Filed under: VS Editor — Ceyhun Ciper @ 05:59
namespace Microsoft.VisualStudio.Text.Editor
{
  using Microsoft.VisualStudio.Text.Formatting;
  using Microsoft.VisualStudio.Text.Tagging;
  using Microsoft.VisualStudio.Utilities;
  using System;
  using System.Collections.Generic;
  using System.ComponentModel.Composition;
  using System.Linq;
  using System.Windows;
  using System.Windows.Media;
  using System.Windows.Shapes;
 
  [Export(typeof(IGlyphFactoryProvider))]
  [Name("AGlyph")]
  [Order(After = "VsTextMarker")]
  [ContentType("code")]
  [TagType(typeof(ATag))]
  internal sealed class AGlyphFactory : IGlyphFactoryProviderIGlyphFactory
  {
    public IGlyphFactory GetGlyphFactory(IWpfTextView view, IWpfTextViewMargin margin)
    {
      return this;
    }
 
    public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
    {
      if (tag == null || !(tag is ATag)) return null;
      return new Ellipse { Fill = Brushes.Blue, Height = 16, Width = 16 };
    }
  }
 
  internal class ATag : IGlyphTag { }
 
  [Export(typeof(ITaggerProvider))]
  [ContentType("code")]
  [TagType(typeof(ATag))]
  class ATagger : ITaggerProviderITagger<ATag>
  {
    public ITagger<T> CreateTagger<T>(ITextBuffer buffer) where T : ITag
    {
      return this as ITagger<T>;
    }
 
    IEnumerable<ITagSpan<ATag>> ITagger<ATag>.GetTags(NormalizedSnapshotSpanCollection spans)
    {
      return
        from span in spans
        where span.GetText().Contains("a")
        select new TagSpan<ATag>(span, new ATag());
    }
 
    public event EventHandler<SnapshotSpanEventArgs> TagsChanged;
  }
}

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.