Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSX - Set a ToolWindowPanes initial position to be docked

Tags:

.net

docking

vsx

I'm creating a Visual Studio package that exposes a tool window and I'm trying to make sure that it is displayed docked to the left edge of the main Visual Studio window when the package first loads.

[ProvideToolWindow(typeof(MyToolWindow), Orientation = ToolWindowOrientation.Left, 
    Style=VsDockStyle.Linked, Window=EnvDTE.Constants.vsWindowKindLinkedWindowFrame)])]
[ProvideToolWindowVisibility(typeof(MyToolWindow), VSConstants.UICONTEXT.NoSolution_string)]
public class MyPackage : Package
{
    ...

I've tried many variations of the above, but the best I've managed to achieve is having the window docked to the bottom - and even then it keeps on re-docking every time the package is re-loaded rather than persisting the user window position.

How can I specify that my window pane be initially shown docked to the left of the main window?

like image 362
Justin Avatar asked Mar 30 '11 11:03

Justin


2 Answers

Setting up items as VsDockStyle.Tabbed is supported, so you could hook onto the Toolbox tool window. But I'm guessing you already thought of that and it doesn't fit your situation.

Although not a pretty solution, you could try this workaround.

  1. Setup the ProvideToolWindow with the Orientation and Window you want, but set the Style to Float since Linked is not supported (http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.vsdockstyle.aspx):

    [ProvideToolWindow(typeof(MyToolWindow), Style = VsDockStyle.Float, Orientation = ToolWindowOrientation.Left, Window = EnvDTE.Constants.vsWindowKindMainWindow)]
    
  2. At run time, dock the tool window if you find it in a floating state:

    /// <summary>
    /// Docks the specified frame window if it is currently floating.
    /// </summary>
    /// <remarks>
    /// Works in VS2010, does not appear to work in VS2008.
    /// </remarks>
    /// <param name="frame">The frame.</param>
    private static void DockWindowIfFloating(IVsWindowFrame frame)
    {
        // Get the current tool window frame mode.
        object currentFrameMode;
        frame.GetProperty((int)__VSFPROPID.VSFPROPID_FrameMode, out currentFrameMode);
    
        // If currently floating, switch to dock mode.
        if ((VSFRAMEMODE)currentFrameMode == VSFRAMEMODE.VSFM_Float)
        {
            frame.SetProperty((int)__VSFPROPID.VSFPROPID_FrameMode, VSFRAMEMODE.VSFM_Dock);
        }
    }
    

As I noted in the remarks - this only seems to work for VS2010 (not VS2008).

Hope it helps, hacky as it is.

like image 169
Steve Cadwallader Avatar answered Dec 08 '22 12:12

Steve Cadwallader


If you want it docked at the bottom by default with the other windows like the Output Window, Error List, Find Results, etc. you can do it like this:

[ProvideToolWindow(typeof(ThePane),
                   Orientation=ToolWindowOrientation.Right,
                   Window=EnvDTE.Constants.vsWindowKindOutput,
                   Style=VsDockStyle.Tabbed)]

The orientation doesn't seem to make a difference, though, it always seems to appear on the left. But close enough for me.

like image 22
Cameron Avatar answered Dec 08 '22 11:12

Cameron