如何使用子级按钮创建解决方案右键单击顶级菜单?(视觉工作室扩展) [英] how to create a solution right click top-level menu with sub-level button?(visual studio extension)

查看:23
本文介绍了如何使用子级按钮创建解决方案右键单击顶级菜单?(视觉工作室扩展)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Visual Studio 版本: 2019

我正在关注 将菜单添加到visual studio菜单栏以创建菜单,它有效,菜单将显示在扩展菜单下.现在,我想将这些菜单移动到解决方案上下文菜单,所以我将 Menu>Parent>id 更改为 IDM_VS_CTXT_SOLNNODE.但它不起作用.

I'm follow adding a menu to the visual studio menu bar to create menus, it works, the menus will be display ubder Extensions menu. Now, I want to move these menus to solution context menu, so I changed Menu>Parent>id to IDM_VS_CTXT_SOLNNODE. But it doesn't working.

之前:

<?xml version="1.0" encoding="utf-8"?>
<CommandTable xmlns="http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <Extern href="stdidcmd.h"/>
  <Extern href="vsshlids.h"/>

  <Commands package="guidVSIXProject1Package">
    <Menus>
      <Menu guid="guidVSIXProject1PackageCmdSet" id="TopLevelMenu" priority="0x700" type="Menu">
        <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_SOLNNODE" />
        <Strings>
          <ButtonText>TestMenu</ButtonText>
          <CommandName>TestMenu</CommandName>
        </Strings>
      </Menu>
    </Menus>

    <Groups>
      <Group guid="guidVSIXProject1PackageCmdSet" id="MyMenuGroup" priority="0x0600">
        <Parent guid="guidVSIXProject1PackageCmdSet" id="TopLevelMenu"/>
      </Group>
    </Groups>

    <Buttons>
      <Button guid="guidVSIXProject1PackageCmdSet" id="TestCommandId" priority="0x0100" type="Button">
        <Parent guid="guidVSIXProject1PackageCmdSet" id="MyMenuGroup" />
        <Icon guid="guidImages" id="bmpPic1" />
        <Strings>
          <ButtonText>Invoke TestCommand</ButtonText>
        </Strings>
      </Button>
    </Buttons>

    <Bitmaps>
      <Bitmap guid="guidImages" href="Resources\TestCommand.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough"/>
    </Bitmaps>
  </Commands>

  <Symbols>
    <GuidSymbol name="guidVSIXProject1Package" value="{fdde7b56-2c13-4a0b-bb96-d0b1c712c674}" />

    <GuidSymbol name="guidVSIXProject1PackageCmdSet" value="{23dc4a5e-5843-45cb-8b8b-c4a11184d73e}">
      <IDSymbol name="MyMenuGroup" value="0x1020" />
      <IDSymbol name="TestCommandId" value="0x0100" />
      <IDSymbol name="TopLevelMenu" value="0x1021"/>
    </GuidSymbol>

    <GuidSymbol name="guidImages" value="{f1008c6c-6b78-4876-93d1-b84e9a83c010}" >
      <IDSymbol name="bmpPic1" value="1" />
      <IDSymbol name="bmpPic2" value="2" />
      <IDSymbol name="bmpPicSearch" value="3" />
      <IDSymbol name="bmpPicX" value="4" />
      <IDSymbol name="bmpPicArrows" value="5" />
      <IDSymbol name="bmpPicStrikethrough" value="6" />
    </GuidSymbol>
  </Symbols>
</CommandTable>

之后:

<?xml version="1.0" encoding="utf-8"?>
<CommandTable xmlns="http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <Extern href="stdidcmd.h"/>
  <Extern href="vsshlids.h"/>

  <Commands package="guidVSIXProject1Package">
    <Menus>
      <Menu guid="guidVSIXProject1PackageCmdSet" id="TopLevelMenu" priority="0x700" type="Menu">
        <Parent guid="guidSHLMainMenu" id="IDG_VS_MM_TOOLSADDINS" /> <!--only change this id-->
        <Strings>
          <ButtonText>TestMenu</ButtonText>
          <CommandName>TestMenu</CommandName>
        </Strings>
      </Menu>
    </Menus>
    <!--same with before-->
</CommandTable>

推荐答案

您应该将 设置为一组而不是一个菜单.

You should sets <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_SOLNNODE" /> in one group instead of one menu.

将其更改为:

<Groups>
  <Group guid="guidVSIXProject1PackageCmdSet" id="MyMenuGroup" priority="0x0600">
    <Parent guid="guidVSIXProject1PackageCmdSet" id="TopLevelMenu"/>
  </Group>
</Groups>

致:

<Groups>
  <Group guid="guidVSIXProject2PackageCmdSet" id="MyMenuGroup" priority="0x0600">
    <!--<Parent guid="guidVSIXProject2PackageCmdSet" id="TopLevelMenu"/>-->
    <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_SOLNNODE"/>
  </Group>
</Groups>

这会将您的菜单从Extensions top menu移动到解决方案上下文(右键单击解决方案).

This will move your menu from Extensions top menu to Solution context(right-click solution).

但这也意味着您无法再从顶部菜单中找到该命令,如果您想让该命令在顶部菜单和解决方案上下文中都可用,请考虑使用 CommandPlacements.

But this also means you can't find the command from top-menu any more, if you want to make the command available both in Top-menu and Solution context, please consider using CommandPlacements.

这篇关于如何使用子级按钮创建解决方案右键单击顶级菜单?(视觉工作室扩展)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆