I'm trying to write an outliner for XML code in VS (an extension using their SDK from a VSIX template) and I would like to get an event-call whenever the user changes to a different codeview/document.
Then, I plan to check the document type, create and render an interactive outline if it is indeed an xml document.
How would I go about creating such a hooking and is it even necessary?
EDIT
I've attempted the following implementation, but I'm being told that object does not contain a definition for "GetGlobalService"
using System;
using System.Runtime.InteropServices;
using EnvDTE;
using Microsoft.VisualStudio.Shell;
[Guid("bc4c5e8f-a492-4a44-9e57-ec9ad945140e")]
public class OutlineWindow : ToolWindowPane
{
private DTE dte;
public OutlineWindow() : base(null)
{
this.Caption = "OutlineWindow";
this.Content = new OutlineWindowControl();
dte = Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
dte.Events.WindowEvents.WindowActivated += OnWindowActivated;
}
private void OnWindowActivated(Window gotFocus, Window lostFocus)
{
throw new NotImplementedException();
}
}
Thanks to @stuartd I managed to get this working! My problem was actually that I was putting it in the wrong class, the inheritance was messing it up.
public class OutlineManager
{
private DTE dte;
public OutlineManager()
{
dte = Package.GetGlobalService(typeof(DTE)) as DTE;
dte.Events.WindowEvents.WindowActivated += OnWindowActivated;
}
private void OnWindowActivated(Window gotFocus, Window lostFocus)
{
//This is run when a new "window"(panel) gains focus (not only the code window though)
}
}