DTE2事件不火 [英] DTE2 events don't fire

查看:331
本文介绍了DTE2事件不火的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在试图开发我的第一个VS插件,我有在射击DTE2事件的问题。



基本上,DocumentOpened和LineChanged事件不火出于某种原因。什么重要组成部分,我错过了。



 命名空间TestAddin {
公共类连接:IDTExtensibility2的{
私人的AddIn _addInInstance;
私人DTE2 _applicationObject;

公共无效的OnConnection(对象应用程序,ext_ConnectMode connectMode,对象addInInst,楼盘阵列定制){
_applicationObject =(DTE 2)申请;
_addInInstance =(外接程序)addInInst;

_applicationObject.Events.DocumentEvents.DocumentOpened + = InitializeFoldingOnDocument;
_applicationObject.Events.TextEditorEvents.LineChanged + = UpdateFoldingOnDocument;
}

私人无效UpdateFoldingOnDocument(TextPoint起点,终点TextPoint,诠释提示){
RegionFolding(_applicationObject.ActiveDocument);
}

私人无效InitializeFoldingOnDocument(文档文件){
RegionFolding(文件);
}

私人无效RegionFolding(文档_document){
//执行折叠[...]
}

//其他成员IDTExtensibility2的[...]
}
}


解决方案

您需要保存DocumentEvents类。
我想他们会desposed或垃圾收集东西。



在我的情况。

 私人solutionEvents solutionEvents; 

公共无效的OnConnection(对象应用程序,ext_ConnectMode connectMode,对象addInInst,楼盘阵列定制)
{
Globals.DTE =(DTE 2)申请;
Globals.Addin =(外接程序)addInInst;

solutionEvents = Globals.DTE.Events.SolutionEvents;
solutionEvents.Opened + =新_dispSolutionEvents_OpenedEventHandler(SolutionEvents_Opened);
solutionEvents.BeforeClosing + =新_dispSolutionEvents_BeforeClosingEventHandler(SolutionEvents_BeforeClosing);
}


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 desposed 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);
}

这篇关于DTE2事件不火的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆