I wrote a simple add-in for Visual Studio 2008 that opens a dockable window pane.
You can download the source and a binary installer by clicking here.
The nature of the add-in means that it is ideally going to stay docked next to where you edit your source. But sometimes, on some installs, it won't stay docked. You run VS, you dock my pane, you shutdown VS, you restart VS, and dang it - the pane is floating again. On some machines I have to re-dock it every time.
But on other installs it stays docked wherever I put it forever. I originally thought it might be a difference between Vista and XP but now I have reports of it coming unstuck on XP as well.
From what I've read (and the fact that it sometimes stays docked) I get the impression that VS is supposed to take care of saving the docking state for me. But it isn't doing that. And yet other plugins on the same VS install don't have this problem. So there has to be something I can do to improve the situation.
I suspect the only relevant part of my code is this:
public class Connect : IDTExtensibility2
{
private static DTE2 _applicationObject;
private AddIn _addInInstance;
private static CodeModelEvents _codeModelEvents;
public static DTE2 VisualStudioApplication
{
get { return _applicationObject; }
}
public static CodeModelEvents CodeModelEvents
{
get { return _codeModelEvents; }
}
public static event EventHandler SourceChanged = delegate { };
public void OnConnection(object application,
ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
}
public void OnStartupComplete(ref Array custom)
{
try
{
Events2 events = (Events2)_applicationObject.Events;
_codeModelEvents = events.get_CodeModelEvents(null);
object objTemp = null;
Windows2 toolWins = (Windows2)_applicationObject.Windows;
Window toolWin = toolWins.CreateToolWindow2(
_addInInstance, GetType().Assembly.Location, "Ora.OraPane", "Ora",
"{DC8A399C-D9B3-40f9-90E2-EAA16F0FBF94}", ref objTemp);
toolWin.Visible = true;
}
catch (Exception ex)
{
MessageBox.Show("Exception: " + ex.Message);
}
}
public void OnBeginShutdown(ref Array custom) { }
public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom) { }
public void OnAddInsUpdate(ref Array custom) { }
}
(The MSDN docs suggest that the window should be created in OnConnection, but if I do that then the window mostly doesn't appear.)
I faced the some of the same docking issues with TeamReview (http://www.codeplex.com/TeamReview). I can't say why it happens but I can help point you to code that always docs your window in OnStartupComplete. If you have a particular location you want it to be in you can Link it to be inside a frame after creating your toolWin and before calling the Visible property. You'll have to check into which constants fit your condition for the CreateLinkedWindowFrame, and SetKind methods. Also, you may want to link your window to something other than MainWindow such as the SolutionExplorer
EnvDTE80.Window2 frame = toolWins.CreateLinkedWindowFrame(toolWin, toolWin, vsLinkedWindowType.vsLinkedWindowTypeTabbed);
frame.SetKind(EnvDTE.vsWindowType.vsWindowTypeToolWindow);
_applicationObject.MainWindow.LinkedWindows.Add(frame);
frame.Activate();
This sample is similar to: http://www.codeplex.com/TeamReview/SourceControl/changeset/view/16102# 2008 -> TeamReview -> Command -> ShowReplayWindowCommand.cs -> ShowForm()
Here's a good Microsoft example to link together the Output Window, the Command Window, and Solution Explorer. It then manipulates the width and height of these linked windows, and it finally undocks them all from the linked window frame.
I have the same problem as the author. I noticed that Visual Studio 2005 "forgets" tool window position only after sessions in which debugging was used.
The accepted answer doesn't help much because the tool window always gets docked to the bottom. I really want the users to be able choose where they want to dock and save their preference by simply docking where they like.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With