-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathVsTextViewCreationListener.cs
41 lines (36 loc) · 1.49 KB
/
VsTextViewCreationListener.cs
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
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.TextManager.Interop;
using Microsoft.VisualStudio.Utilities;
using System.ComponentModel.Composition;
using System.Diagnostics;
namespace VSTextMacros
{
// This listener is loaded by MEF and adds a MacroCommandFilter to every new IVsTextView
[Export(typeof(IVsTextViewCreationListener)), TextViewRole(PredefinedTextViewRoles.Editable), ContentType("text")]
public class VsTextViewCreationListener : IVsTextViewCreationListener
{
[Import]
internal IVsEditorAdaptersFactoryService AdaptersFactory = null;
[Export]
[Name("CommentAdornmentLayer")]
[Order(After = PredefinedAdornmentLayers.Text)]
public AdornmentLayerDefinition commentLayerDefinition;
public void VsTextViewCreated(IVsTextView textView)
{
var wpfTextView = AdaptersFactory.GetWpfTextView(textView);
if (wpfTextView == null)
{
Debug.Fail("Unable to get IWpfTextView from IVsTextView");
return;
}
var adornmentManager = MacroAdornmentManager.Create(wpfTextView);
var filter = new MacroCommandFilter(adornmentManager);
IOleCommandTarget next;
if (ErrorHandler.Succeeded(textView.AddCommandFilter(filter, out next)))
filter.Next = next;
}
}
}