namespace Ciper { using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Classification; using Microsoft.VisualStudio.Text.Editor; using System.Collections.Generic; using System.ComponentModel.Composition; using System.Linq; [Export(typeof(IWpfTextViewCreationListener)), TextViewRole(PredefinedTextViewRoles.Interactive)] public partial class WpfTextViewCreationListener : IWpfTextViewCreationListener { IWpfTextView view; IClassifier classifier; ITextSnapshot snapshot { get { return view.TextSnapshot; } } [Import] IViewClassifierAggregatorService classifierAggregator { get; set; } SnapshotSpan GetSnapshotSpan() { return new SnapshotSpan(snapshot, Span.FromBounds(0, snapshot.Length)); } IEnumerable<ClassificationSpan> GetClassificationSpans() { return classifier.GetClassificationSpans(GetSnapshotSpan()); } IEnumerable<ClassificationSpan> GetClassificationSpans(string type) { return GetClassificationSpans().Where(s => s.ClassificationType.IsOfType(type)); } public void TextViewCreated(IWpfTextView textView) { view = textView; classifier = classifierAggregator.GetClassifier(view); } } } namespace Ciper { using Microsoft.VisualStudio.Utilities; [ContentType("csharp")] partial class WpfTextViewCreationListener { } }
July 9, 2014
Simplest WpfTextViewCreationListener
Leave a Comment »
No comments yet.
Leave a comment