为什么 Visual Studio 2008 忘记将我的加载项窗口窗格停靠在哪里?
我为 Visual Studio 2008 编写了一个简单的插件,可以打开一个可停靠的窗口窗格。
该加载项的性质意味着它理想情况下,它会停靠在您编辑源代码的位置旁边。 但有时,在某些安装中,它不会保持停靠状态。 你运行 VS,停靠我的窗格,关闭 VS,重新启动 VS,然后将其关闭 - 窗格再次浮动。 在某些机器上我每次都必须重新对接。
但在其他安装中,无论我把它放在哪里,它都会永远停留在停靠位置。 我最初认为这可能是 Vista 和 XP 之间的差异,但现在我有报告称它在 XP 上也出现问题。
从我读过的内容(以及它有时保持停靠状态的事实)来看,我的印象是 VS 应该负责为我保存停靠状态。 但它并没有这样做。 然而同一 VS 安装上的其他插件则没有这个问题。 所以我必须采取一些措施来改善这种情况。
我怀疑我的代码唯一相关的部分是这样的:
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) { }
}
(MSDN 文档建议应该在 OnConnection 中创建窗口,但如果我这样做,那么窗口大部分不会出现。)
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.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我在使用 TeamReview 时遇到了一些相同的对接问题 (http://www.codeplex.com/TeamReview )。 我无法说出为什么会发生这种情况,但我可以帮助您指出始终在 OnStartupComplete 中记录窗口的代码。 如果您希望将其放置在某个特定位置,则可以在创建 toolWin 之后、调用 Visible 属性之前将其链接到框架内。 您必须检查哪些常量适合 CreateLinkedWindowFrame 和 SetKind 方法的条件。 另外,您可能希望将窗口链接到 MainWindow 以外的其他内容,例如 SolutionExplorer
此示例类似于: http://www.codeplex.com/TeamReview/SourceControl/changeset/view/16102# 2008 -> 团队回顾-> 命令-> ShowReplayWindowCommand.cs -> ShowForm()
这是一个很好的 Microsoft 示例将输出窗口、命令行窗口和解决方案资源管理器链接在一起。 然后,它操纵这些链接窗口的宽度和高度,最后将它们全部从链接的窗口框架中取消停靠。
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
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.
我和作者有同样的问题。 我注意到 Visual Studio 2005 仅在使用调试的会话之后才“忘记”工具窗口位置。
接受的答案没有多大帮助,因为工具窗口总是停靠在底部。 我真的希望用户能够选择他们想要停靠的位置,并通过简单地停靠在他们喜欢的地方来保存他们的偏好。
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.
这对我有帮助。 我使用 Visual Studio 2005,但这也可能对您有帮助。
Here's what helped for me. I use Visual Studio 2005, but this might help you, too.
将工具窗口可见性设置为 false 效果非常好。 谢谢 JK。
为了回答 JK 关于调试后取消对接的问题,我想知道项目调试属性中的 devenv.exe /resetaddin 开关是否会导致这种情况发生。 它肯定会重置插件创建的所有其他内容。
想法:当您创建插件项目时,/resetaddin 开关会自动添加到调试配置中。 我通常在 /resetaddin 命令中在类名的字体上放置一个无效字符,例如“x”,这样当我们确实需要硬重置时,可以通过删除 x 轻松地重新启用它。 通常不需要每次调试时都重新设置!
Setting the toolwindow visibility to false works really well. thanks JK.
To answers JK's question about undocking after debug, I wonder if the devenv.exe /resetaddin switch in the projects debug properties causes that to happen. It certainly resets everything else the addin creates.
Idea: The /resetaddin switch is added automatically to the debug configuration when you create an addin project. I usual put an invalid char such as an 'x' up the font of the class name in the /resetaddin command, so that it can easily be re-enabled by removing the x when we do want a hard reset. There is usually no need for a reset every time we debug!