Jon
Jon

Reputation: 5335

Visual Studio extension: How do I find which tool window is in the foreground in a tab link group?

In Visual Studio, you can group tool windows together and identify them by their tabs. For example, you might have the "Output", "Error List", and "Find Results 1" tool windows grouped together in a panel below your document. When you click on the "Output" tab, it comes to the foreground and grabs focus. If you click back to the document window, the "Output" tab is still on top (in the foreground).

How can I programmatically (in a VS extension) determine (1) which windows are in the same tab group, and (2) which window is in the foreground, when given one of the windows in a group?

Here's a code sample enumerating all windows:

    var dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));
    var windowOutput = dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput);
    foreach (EnvDTE.Window w in windowOutput.LinkedWindowFrame.Collection)
    {
        //gives every window, not just those grouped together
    }

Upvotes: 0

Views: 1220

Answers (1)

Cameron
Cameron

Reputation: 98746

You can find out when a tab is switched to by initially iterating through all the EnvDTE windows (Window/Window2), getting the corresponding IVsWindowFrames, and subscribing for frame notifications (IVsWindowFrameNotify) so that you get notified when a tab changes. But this still won't help with tab groups ("linked frames"), not to mention the headache of keeping your window frame listeners up to date (when tabs open/close, etc.).

The only reliable thing I can think of is to export the settings to XML (VS does this to preserve the layout from run to run), manipulate the XML, then later import it. I'm not sure how fast this would be though, but it's worth a try. You can search for Environment_WindowLayout in your .vssettings file to see an example of the XML. Actually doing an export/import of this info is tricky -- you can try your luck with the EnvDTE.Properties collection, and perhaps the IVsUIShellDocumentWindowMgr (example) would come in handy, but perhaps not.

Upvotes: 1

Related Questions