在 Visual Studio 中创建新的顶级菜单

发布于 2024-10-04 01:52:45 字数 392 浏览 10 评论 0原文

我们有一个 VS 的插件,目前是从工具菜单启动的,该插件由一个 UI 组成,为用户提供了一些选项按钮,我现在想将其转换为提供相同功能的顶级菜单。

我已阅读教程,它帮助我添加了一个新的顶部-级别菜单,但无法真正理解所有步骤背后的逻辑。该指南并没有真正清楚每个步骤创建的内容或如何更改输出。
这些步骤创建的是一个新的顶级菜单,其下方有一个项目。我试图在菜单中创建一些层次结构(即顶级 -> 子类别 -> 命令),但对所有组/菜单/ID 结构有点迷失。 这些文件的结构有明确的解释吗?文档还是教程?如果有人有该主题的经验并且可以帮助解决问题,我将非常感激......

We have an add in for VS that currently is launched from the tools menu, the add-in consists of a a UI offering the user a few option buttons, which I now want to convert to a top-level menu that would offer the same functionality.

I've read this tutorial, which helped me add a new top-level menu, but couldn't really understand the logic behind all the steps. The guide doesn't really clear what each of the steps create or how can your change the output.
What the steps create is a new top-level menu with a single item underneath it. I'm trying to create some hierarchy in my menu (i.e. Top Level -> Sub category -> Commands) but got abit lost with all the groups/menus/IDs structure.
Is there any clear explanation for the structure of these files? A documentation or a tutorial? If anyone had experience in the subject and could help clear things up I would much appreciate it...

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

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

发布评论

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

评论(3

强辩 2024-10-11 01:52:45

我还没有尝试过执行分层菜单项,但我在使用 Visual SDK .vcst 文件时遇到了类似的问题。这是一种痛苦。您可以做几件事。

  1. 将 VS 包编辑器安装到 Visual Studio 博客条目:http://blogs.msdn.com/b/visualstudio/archive/2010/09/08/introducing-the-vspackage-builder.aspx
  2. 下载源代码(开源以便您可以看看他们是如何做到的),以获取执行类似操作的加载项。示例是 AnkhSVN,它是 Visual Studio 的 Subversion 存储库插件。这是源代码: http://ankhsvn.open.collab.net/source/浏览/ankhsvn/

I haven't tried doing hierarchical menu items, but I have had similar problems with the Visual SDK .vcst file. It is a pain. A couple of things you can do.

  1. Install the VS Package Editor to Visual Studio Blog Entry for it: http://blogs.msdn.com/b/visualstudio/archive/2010/09/08/introducing-the-vspackage-builder.aspx
  2. Download source code (open source so you can see how they do it) for an add-in that does similar things. Example is AnkhSVN which is a Subversion Repository Add-in to Visual Studio. Here is the source code: http://ankhsvn.open.collab.net/source/browse/ankhsvn/
2024-10-11 01:52:45

我认为现在所说的“插件”是指 VS 包(使用 VS SDK)的扩展,因为“插件”是 VS 2013 及更低版本的较旧形式的扩展。 (如果您确实指的是“加载项”,请参阅我的示例 HOWTO:添加按钮,从加载项到 Visual Studio .NET 的命令栏和工具栏

包使用 .vsct 文件。要回答您的问题,请在此处查看我的示例的 .vsct 文件:

  • CommandTopMenu
  • CommandSubMenu

(要学习,请参阅其他内容的上下文菜单、工具栏等)。在 .vcst 文件中,他们使用“CommandPlacements”将项目的定义与其“位置”分开,并使用注释来解释 3 种项目之间的关系:

  1. 菜单(主菜单/顶部菜单/子菜单/上下文菜单)和工具栏。
  2. 组:组是其他组以及命令和子菜单的容器。
  3. 命令

记住规则:

  • 顶级菜单的父级始终是 VS 的主菜单,而不是组。
  • 子菜单的父级始终是组,而不是工具栏或任何类型的菜单。
  • 命令的父级始终是一个组,而不是直接的工具栏或任何类型的菜单(子菜单的规则相同)
  • 组的父级可以是菜单、工具栏、上下文菜单等,并且它可以也是另一个群体。
  • 菜单(任何类型)或工具栏可以由您的扩展(VS 的主菜单除外)或 VS 的现有菜单创建,由前缀“IDM_”标识。请参阅 Visual Studio 菜单的 GUID 和 IDVisual Studio 工具栏的 GUID 和 ID
  • 组可以是新组(由扩展创建),也可以是 Visual Studio 的现有组,由前缀“IDG_”标识。上面的链接中有一些内置的 Visual Studio 组,但要获得更详尽的列表,请安装 ExtensionTools 扩展 (Mads Kristensen),在 .vsct 文件中提供智能感知或检查其源代码 VsctBuiltInCache.cs 文件

I assume that nowadays by "add-in" you mean an extension that is a VS package (using the VS SDK) because an "add-in" was an older form of extension for VS 2013 and lower. (If you really mean an "add-in" then see my sample HOWTO: Adding buttons, commandbars and toolbars to Visual Studio .NET from an add-in)

Packages use .vsct files. To answer your question, see the .vsct files of my samples here:

  • CommandTopMenu
  • CommandSubMenu

(and to learn see also the other ones for context menus, toolbars, etc.). In the .vcst file they use "CommandPlacements" to separate the definition of an item from its "placement", and comments to explain the relationship between the 3 kinds of items:

  1. Menus (Main-menu/Top-menus/Sub-menus/Context menus) and Toolbars.
  2. Groups: a group is a container for other groups and also for commands and sub-menus.
  3. Commands

Remember the rules:

  • The parent of a top-menu is always the Main menu of VS, never a group
  • The parent of a sub-menu is always a group, never directly a toolbar or any kind of menu.
  • The parent of a command is always a group, never directly a toolbar or any kind of menu (same rule that for sub-menus)
  • The parent of a group can be a menu, a toolbar, a context menu, etc. and it can be also another group.
  • A menu (any kind) or toolbar can be either created by your extension (except the main menu of VS) or an existing one of VS, identified by prefix "IDM_". See GUIDs and IDs of Visual Studio menus and GUIDs and IDs of Visual Studio toolbars.
  • A group can be either new (created by your extension) or an existing group of Visual Studio, identified by prefix "IDG_". You have some built-in Visual Studio groups in the links above, but for a more exhaustive list install the ExtensionTools extension (Mads Kristensen) that provides intellisense in the .vsct file or check the source code of its VsctBuiltInCache.cs file.
波浪屿的海角声 2024-10-11 01:52:45

代码示例

<?xml version="1.0" encoding="utf-8"?>
<CommandTable xmlns="...">
  <!-- Extern section unchanged -->
  <Commands package="guidHowToPackagePkg">
    <Menus>
      <!-- New menu added -->
      <Menu guid="guidBasicVSCTSampleCmdSet" id="SubMenu" priority="0x200"
        type="Menu">
        <Parent guid="guidBasicVSCTSampleCmdSet" id="TopLevelMenuGroup" />
        <Strings>
          <ButtonText>Other Commands</ButtonText>
          <CommandName>Other Commands</CommandName>
        </Strings>
      </Menu>
    </Menus>
    <Groups>
      <!-- Group changed to SubMenuGroup and attached to SubMenu -->
      <Group guid="guidBasicVSCTSampleCmdSet" id="SubMenuGroup"
        priority="0x0600">
        <Parent guid="guidBasicVSCTSampleCmdSet" id="SubMenu"/>
      </Group>
    </Groups>

    <Buttons>
      <!-- We attached these two buttons to SubMenuGroup -->
      <Button guid="guidBasicVSCTSampleCmdSet" id="ThirdCommand" priority="0x0100"
        type="Button">
        <Parent guid="guidBasicVSCTSampleCmdSet" id="SubMenuGroup" />
        <Icon guid="guidImages" id="bmpPicX" />
        <Strings>
          <CommandName>ThirdCommand</CommandName>
          <ButtonText>Third Command</ButtonText>
        </Strings>
      </Button>
      <Button guid="guidBasicVSCTSampleCmdSet" id="FourthCommand"
        priority="0x0101" type="Button">
        <Parent guid="guidBasicVSCTSampleCmdSet" id="SubMenuGroup" />
        <Icon guid="guidImages" id="bmpPicArrows" />
        <Strings>
          <CommandName>FourthCommand</CommandName>
          <ButtonText>Fourth Command</ButtonText>
        </Strings>
      </Button>
    </Buttons>

  </Commands>

  <Symbols>
    <!-- We add a SubMenu and changed SubMenuGroup -->
    <GuidSymbol name="guidBasicVSCTSampleCmdSet" value="...">
      <IDSymbol name="SubMenu" value="0x0101" />
      <IDSymbol name="SubMenuGroup" value="0x0201" />
    </GuidSymbol>
  </Symbols>
</CommandTable>

这为您提供了以下顶级菜单:

在此处输入图像描述

这是有关该主题的完整章节。这几乎解释了(分层)菜单上需要了解的所有内容。

http://dotneteers.net/blogs/divedeeper/archive/2010/05/23/vs-2010-package-development-chapter-2-commands-menus-and-toolbars.aspx

Code example

<?xml version="1.0" encoding="utf-8"?>
<CommandTable xmlns="...">
  <!-- Extern section unchanged -->
  <Commands package="guidHowToPackagePkg">
    <Menus>
      <!-- New menu added -->
      <Menu guid="guidBasicVSCTSampleCmdSet" id="SubMenu" priority="0x200"
        type="Menu">
        <Parent guid="guidBasicVSCTSampleCmdSet" id="TopLevelMenuGroup" />
        <Strings>
          <ButtonText>Other Commands</ButtonText>
          <CommandName>Other Commands</CommandName>
        </Strings>
      </Menu>
    </Menus>
    <Groups>
      <!-- Group changed to SubMenuGroup and attached to SubMenu -->
      <Group guid="guidBasicVSCTSampleCmdSet" id="SubMenuGroup"
        priority="0x0600">
        <Parent guid="guidBasicVSCTSampleCmdSet" id="SubMenu"/>
      </Group>
    </Groups>

    <Buttons>
      <!-- We attached these two buttons to SubMenuGroup -->
      <Button guid="guidBasicVSCTSampleCmdSet" id="ThirdCommand" priority="0x0100"
        type="Button">
        <Parent guid="guidBasicVSCTSampleCmdSet" id="SubMenuGroup" />
        <Icon guid="guidImages" id="bmpPicX" />
        <Strings>
          <CommandName>ThirdCommand</CommandName>
          <ButtonText>Third Command</ButtonText>
        </Strings>
      </Button>
      <Button guid="guidBasicVSCTSampleCmdSet" id="FourthCommand"
        priority="0x0101" type="Button">
        <Parent guid="guidBasicVSCTSampleCmdSet" id="SubMenuGroup" />
        <Icon guid="guidImages" id="bmpPicArrows" />
        <Strings>
          <CommandName>FourthCommand</CommandName>
          <ButtonText>Fourth Command</ButtonText>
        </Strings>
      </Button>
    </Buttons>

  </Commands>

  <Symbols>
    <!-- We add a SubMenu and changed SubMenuGroup -->
    <GuidSymbol name="guidBasicVSCTSampleCmdSet" value="...">
      <IDSymbol name="SubMenu" value="0x0101" />
      <IDSymbol name="SubMenuGroup" value="0x0201" />
    </GuidSymbol>
  </Symbols>
</CommandTable>

This provides you with the following top-level menu:

enter image description here

Here's a full chapter on the topic. This pretty much explains everything there is to know on (hierarchical) menu's.

http://dotneteers.net/blogs/divedeeper/archive/2010/05/23/vs-2010-package-development-chapter-2-commands-menus-and-toolbars.aspx

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