views:

180

answers:

1

I'm writing an addin for VS 2008 in C#.

And I want to know what kind of editor/designer "scope" is open (for example VS Editor/VB Editor"). Can I catch the event where the scope changes?

Thanks.

+1  A: 

I can not try it right now, so take with a grain of salt:

public class Connect : IDTExtensibility2, IDTCommandTarget
{
    public void OnConnection( object application, ext_ConnectMode connectMode, 
        object addInInst, ref Array custom )
    {
        _applicationObject = ( DTE2 ) application;
        _applicationObject.Events.SelectionEvents.OnChange += SelectionEvents_OnChange;
    }

    void SelectionEvents_OnChange()
    {
        vsWindowType type = _applicationObject.ActiveWindow.Type;
        // switch (type) { ... }
    }
}

EDIT: Maybe the Selection-Event is not what you need. I don't know if there is some other event you can hook. Anyways the line

vsWindowType type = _applicationObject.ActiveWindow.Type;

tells you the type of the currently active window.

EricSchaefer