public
Description: A sample VS2010 extension that hilights the current line in the text editor
Homepage:
Clone URL: git://github.com/tomasr/LineAdornments.git
LineAdornments / AdornmentFactory.cs
100644 52 lines (46 sloc) 1.97 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Utilities;
using Microsoft.VisualStudio.Text.Classification;
using System.Windows.Media;
 
namespace Winterdom.VisualStudio.Extensions.Text {
 
   static class CurrentLineClassificationDefinition {
[Export(typeof(ClassificationTypeDefinition))]
[Name(LineHighlight.NAME)]
      internal static ClassificationTypeDefinition CurrentLineClassificationType = null;
   }
[Export(typeof(EditorFormatDefinition))]
[ClassificationType(ClassificationTypeNames = LineHighlight.NAME)]
[Name(LineHighlight.NAME)]
[DisplayName("Current Line")]
[UserVisible(true)]
[Order(Before = Priority.Default)]
   sealed class CurrentLineFormat : ClassificationFormatDefinition {
      public CurrentLineFormat() {
         this.BackgroundColor = Colors.Teal;
         this.ForegroundColor = Colors.DarkCyan;
         this.BackgroundOpacity = 0.3;
      }
   }
 
[Export(typeof(IWpfTextViewCreationListener))]
[ContentType("text")]
[TextViewRole(PredefinedTextViewRoles.Document)]
   internal sealed class EditorAdornmentFactory : IWpfTextViewCreationListener {
[Import]
      public IClassificationTypeRegistryService ClassificationRegistry = null;
[Import]
      public IClassificationFormatMapService FormatMapService = null;
 
[Export(typeof(AdornmentLayerDefinition))]
[Name(LineHighlight.NAME)]
[Order(Before = "Selection")]
[TextViewRole(PredefinedTextViewRoles.Document)]
      public AdornmentLayerDefinition editorAdornmentLayer = null;
 
      public void TextViewCreated(IWpfTextView textView) {
         IClassificationType classification =
            ClassificationRegistry.GetClassificationType(LineHighlight.NAME);
         IClassificationFormatMap map =
            FormatMapService.GetClassificationFormatMap(textView);
         new LineHighlight(textView, map, classification);
      }
   }
}