-
Notifications
You must be signed in to change notification settings - Fork 2
/
NSSelectionListener.cs
103 lines (89 loc) · 4.09 KB
/
NSSelectionListener.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using System.Diagnostics;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using ShellConstants = Microsoft.VisualStudio.Shell.Interop.Constants;
namespace NimStudio.NimStudio {
[CLSCompliant(false)]
public abstract class SelectionListener: IVsSelectionEvents, IDisposable {
private uint eventsCookie;
private IVsMonitorSelection monSel;
private ServiceProvider serviceProvider;
private bool isDisposed;
private static volatile object Mutex = new object();
protected SelectionListener(ServiceProvider serviceProviderParameter) {
if (serviceProviderParameter == null) {
throw new ArgumentNullException("serviceProviderParameter");
}
this.serviceProvider = serviceProviderParameter;
this.monSel = this.serviceProvider.GetService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection;
if (this.monSel == null) {
throw new InvalidOperationException();
}
}
protected uint EventsCookie {
get {
return this.eventsCookie;
}
}
protected IVsMonitorSelection SelectionMonitor {
get {
return this.monSel;
}
}
protected ServiceProvider ServiceProvider {
get {
return this.serviceProvider;
}
}
public virtual int OnCmdUIContextChanged(uint dwCmdUICookie, int fActive) {
return VSConstants.E_NOTIMPL;
}
public virtual int OnElementValueChanged(uint elementid, object varValueOld, object varValueNew) {
int hr = VSConstants.S_OK;
if (elementid == VSConstants.DocumentFrame) {
IVsWindowFrame pWindowFrame = varValueOld as IVsWindowFrame;
if (pWindowFrame != null) {
object document;
hr = pWindowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_pszMkDocument, out document); // get doc name
if (ErrorHandler.Succeeded(hr)) {
//uint itemid;
//IVsHierarchy hier = projMgr as IVsHierarchy;
//hr = hier.ParseCanonicalName((string)document, out itemid);
//PythonFileNode node = projMgr.NodeFromItemId(itemid) as PythonFileNode;
//if (null != node) {
// node.RunGenerator();
//}
}
}
}
return hr;
}
public virtual int OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew) {
return VSConstants.E_NOTIMPL;
}
public void Dispose() {
this.Dispose(true);
GC.SuppressFinalize(this);
}
public void Init() {
if (this.SelectionMonitor != null) {
ErrorHandler.ThrowOnFailure(this.SelectionMonitor.AdviseSelectionEvents(this, out this.eventsCookie));
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1806:DoNotIgnoreMethodResults", MessageId = "Microsoft.VisualStudio.Shell.Interop.IVsMonitorSelection.UnadviseSelectionEvents(System.UInt32)")]
protected virtual void Dispose(bool disposing) {
if (!this.isDisposed) {
lock (Mutex) {
if (disposing && this.eventsCookie != (uint)ShellConstants.VSCOOKIE_NIL && this.SelectionMonitor != null) {
this.SelectionMonitor.UnadviseSelectionEvents((uint)this.eventsCookie);
this.eventsCookie = (uint)ShellConstants.VSCOOKIE_NIL;
}
this.isDisposed = true;
}
}
}
}
}