Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get notified when DTE.ActiveDocument changes

I am writing a Visual Studio 2008 extension. I want to be notified every time DTE.ActiveDocument changes, so I can update something in a custom panel which performs a similar feature to solution explorer. I have yet to find any event which occurs when this happens. Is there such an event?

Concretely, I'm looking for something like:

var dte = GetService(typeof(EnvDTE._DTE)) as EnvDTE.DTE;
dte.Events.DTEEvents.ActiveDocumentChanged += s => {
    // implies dte.ActiveDocument has changed value
}
like image 898
Neil Mitchell Avatar asked Apr 27 '12 15:04

Neil Mitchell


2 Answers

I belive you are looking for this event

_applicationObject.Events.WindowEvents.WindowActivated

check GotFocus.Document == null if you only interested in Document activation changes

Hope this helps

like image 64
Arsen Mkrtchyan Avatar answered Oct 23 '22 19:10

Arsen Mkrtchyan


You can also implement IVsRunningDocTableEvents, register yourself as a listener, and then the OnBeforeDocumentWindowShow method will be called before a document is switched to.

class RdtEvents : IVsRunningDocTableEvents
{
    RdtEvents()
    {
        var rdt = Package.GetGlobalService(typeof(SVsRunningDocumentTable));
        uint evtCookie;
        rdt.AdviseRunningDocTableEvents(this, out evtCookie);
    }

    // ...

    int IVsRunningDocTableEvents.OnBeforeDocumentWindowShow(uint docCookie, int fFirstShow, IVsWindowFrame pFrame)
    {
        // ...
    }
}
like image 1
Cameron Avatar answered Oct 23 '22 19:10

Cameron