While trying to develop my first VS Addin, I am having issues in firing DTE2 events.
Basically, the DocumentOpened and LineChanged events don't fire for some reason. What important part did I miss?
namespace TestAddin {
public class Connect : IDTExtensibility2 {
private AddIn _addInInstance;
private DTE2 _applicationObject;
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) {
_applicationObject = (DTE2) application;
_addInInstance = (AddIn) addInInst;
_applicationObject.Events.DocumentEvents.DocumentOpened += InitializeFoldingOnDocument;
_applicationObject.Events.TextEditorEvents.LineChanged += UpdateFoldingOnDocument;
}
private void UpdateFoldingOnDocument(TextPoint startpoint, TextPoint endpoint, int hint) {
RegionFolding(_applicationObject.ActiveDocument);
}
private void InitializeFoldingOnDocument(Document document) {
RegionFolding(document);
}
private void RegionFolding(Document _document) {
// Do the folding [...]
}
// Other IDTExtensibility2 Members [...]
}
}
You need to save the DocumentEvents
class.
I think they will be disposed or garbage collected else.
In my case.
private SolutionEvents solutionEvents;
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
Globals.DTE = (DTE2)application;
Globals.Addin = (AddIn)addInInst;
solutionEvents = Globals.DTE.Events.SolutionEvents;
solutionEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(SolutionEvents_Opened);
solutionEvents.BeforeClosing += new _dispSolutionEvents_BeforeClosingEventHandler(SolutionEvents_BeforeClosing);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With