SixPairs

March 31, 2012

Simple Colorizer for Visual Studio Editor

Filed under: VS Editor — Tags: — Ceyhun Ciper @ 16:48

Here is probably the simplest colorizer code:

namespace Ciper
{
	[Export(typeof(IClassifierProvider)), ContentType("text")]
	internal class CProvider : IClassifierProvider
	{
		[Import]
		IClassificationTypeRegistryService ctrs = null;
 
		[Export, Name("ciper.text"), BaseDefinition("text")]
		internal static ClassificationTypeDefinition CTD;
 
		[Export(typeof(EditorFormatDefinition)), Name("ciper.text.format"), ClassificationType(ClassificationTypeNames = "ciper.text")]
		internal class CFD : ClassificationFormatDefinition
		{
			public CFD()
			{
				ForegroundColor = System.Windows.Media.Colors.DarkMagenta;
			}
		}
 
		public IClassifier GetClassifier(ITextBuffer buffer)
		{
			return new C(ctrs.GetClassificationType("ciper.text"));
		}
	}
 
	class C : IClassifier
	{
		IClassificationType ct;
		public C(IClassificationType ct)
		{
			this.ct = ct;
		}
		public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
		{
			return new[] { new ClassificationSpan(span, ct) };
		}
 
		public event EventHandler<ClassificationChangedEventArgs> ClassificationChanged;
	}
}

 

This will paint everything that is not yet classified in magenta.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.