Visual Studio Extension: How to track when a new method is edited?

Deadly 提交于 2019-12-11 13:10:49

问题


For my Visual Studio Extension, I'm trying to track what methods are selected by the user. To do that, I thought it would be a good idea, to observe the DropDownBar, and track all changes to this bar. So, I started to look for new documents beeing opened, get the IvDropDownBarManager object to get the DropDownBar object:

private void OnDocumentOpened(EnvDTE.Document document)
{
   IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
   IEnumWindowFrames ppenum; uiShell.GetDocumentWindowEnum(out ppenum);
   IVsWindowFrame[] frames = new IVsWindowFrame[1]; 
   uint numFrames; IVsWindowFrame m_frame = null; 
   while (ppenum.Next(1, frames, out numFrames) == VSConstants.S_OK && numFrames == 1)
   { 
      m_frame = frames[0] as IVsWindowFrame; 
      object title;
      m_frame.GetProperty((int)__VSFPROPID.VSFPROPID_Caption, out title);
      if ((title as String).ToLowerInvariant() == document.ActiveWindow.Caption.ToLowerInvariant())
         break;
    } 
    object docView;
    m_frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out docView); 
    IVsCodeWindow codeWindow = docView as IVsCodeWindow;
    IVsDropdownBarManager dropdown = (IVsDropdownBarManager)codeWindow;

    IVsDropdownBar bar;
    dropdown.GetDropdownBar(out bar);
}

However, there are a few issues:

1) While I'm able to get the IVsDropdownBarManager object, the IVsDropdownBar seems to always be null. Why is this the case?

2) Even when I would be able to get the IVsDropdownBar object, what should I do next? There isn't any place where I could add a listener.

3) Is this way too complicate and would there be an easier way to do the same thing?

来源:https://stackoverflow.com/questions/28323730/visual-studio-extension-how-to-track-when-a-new-method-is-edited

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!