VSX - 设置要停靠的 ToolWindowPanes 初始位置

发布于 2024-10-28 04:51:13 字数 557 浏览 2 评论 0原文

我正在创建一个公开工具窗口的 Visual Studio 包,并尝试确保在包首次加载时将其显示停靠在主 Visual Studio 窗口的左边缘。

[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'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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

依 靠 2024-11-04 04:51:13

支持将项目设置为 VsDockStyle.Tabbed,因此您可以挂接到 Toolbox 工具窗口。但我猜你已经想到了这一点,但它不适合你的情况。

虽然这不是一个很好的解决方案,但您可以尝试此解决方法。

  1. 使用所需的方向和窗口设置 ProvideToolWindow,但将样式设置为“浮动”,因为不支持“链接”(http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.vsdockstyle。 ASPX):

    [ProvideToolWindow(typeof(MyToolWindow),样式 = VsDockStyle.Float,方向 = ToolWindowOrientation.Left,窗口 = EnvDTE.Constants.vsWindowKindMainWindow)]
    
  2. 在运行时,如果发现工具窗口处于浮动状态,请将其停靠:

    /// <摘要>
    /// 如果指定的框架窗口当前处于浮动状态,则将其停靠。
    /// 
    /// <备注>;
    /// 在 VS2010 中工作,在 VS2008 中似乎不起作用。
    /// 
    ///  框架。
    私有静态无效DockWindowIfFloating(IVsWindowFrame框架)
    {
        // 获取当前工具窗口框架模式。
        对象当前帧模式;
        Frame.GetProperty((int)__VSFPROPID.VSFPROPID_FrameMode, out currentFrameMode);
    
        // 如果当前浮动,则切换到停靠模式。
        if ((VSFRAMEMODE)currentFrameMode == VSFRAMEMODE.VSFM_Float)
        {
            frame.SetProperty((int)__VSFPROPID.VSFPROPID_FrameMode, VSFRAMEMODE.VSFM_Dock);
        }
    }
    

正如我在备注中指出的 - 这似乎仅适用于 VS2010(不适用于 VS2008)。

希望它能有所帮助,尽管它很hacky。

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.

居里长安 2024-11-04 04:51:13

如果您希望它默认与其他窗口(如输出窗口、错误列表、查找结果等)停靠在底部,您可以这样做:

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

方向似乎没有什么区别,但它总是看起来出现在左侧。但对我来说已经足够近了。

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.

迷鸟归林 2024-11-04 04:51:13

我不知道这是否有效,但您可以尝试一下:

我在注册表中查找了线索,解决方案资源管理器工具窗口的停靠位置以及
发现 Window 参数包含“DocumentWell”,

因此您可以尝试以下操作:

[ProvideToolWindow(typeof(MyToolWindow), Orientation = ToolWindowOrientation.Right, Style=VsDockStyle.Tabbed, Window="DocumentWell")])]

或者

Window=EnvDTE.Constants.vsWindowKindMainWindow

希望这会有所帮助,

托马斯。

I don't know if this works, but you can give it a try:

I looked in the registry for a clue, to where the SolutionExplorer toolwindow is docked and
found that the Window parameter contains "DocumentWell"

So you can try this:

[ProvideToolWindow(typeof(MyToolWindow), Orientation = ToolWindowOrientation.Right, Style=VsDockStyle.Tabbed, Window="DocumentWell")])]

or

Window=EnvDTE.Constants.vsWindowKindMainWindow

Hope this helps,

Thomas.

疏忽 2024-11-04 04:51:13
// Replace EnvDTE.Constants.vsWindowKindSolutionExplorer with the GUID you need.
[ProvideToolWindow(typeof(IssuesWindow), Style = VsDockStyle.Tabbed, Window = EnvDTE.Constants.vsWindowKindSolutionExplorer)]

这在 Visual Studio 2015 上运行良好。在虚拟机上测试。

但是,有一个限制:工具窗口仅在 IDE 首次启动您的扩展时才会停靠。使用虚拟机进行测试很容易,因为您只需恢复以前的状态即可。我猜想写入了一些注册表值,并且 Visual Studio 下次会记住工具窗口的先前位置,而不是使用上面刚刚指定的默认值。

如果有人愿意,我想他们可以比较注册表的前后版本并找到这些设置值并在下次/按需手动重置它们。

// Replace EnvDTE.Constants.vsWindowKindSolutionExplorer with the GUID you need.
[ProvideToolWindow(typeof(IssuesWindow), Style = VsDockStyle.Tabbed, Window = EnvDTE.Constants.vsWindowKindSolutionExplorer)]

This works fine on Visual Studio 2015. Tested on a virtual machine.

However, there is a limitation: The tool window only gets docked for the very first time the IDE starts with your extension. It's easy to test with a virtual machine, as you just restore a previous state. I guess some registry value is written and Visual Studio rather remembers the previous position of your tool window next time rather than using the defaults you've just specified above.

If someone wants, I guess they could compare before/after versions of the registry and find these set values and reset them manually next time/on demand.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文