代码之家  ›  专栏  ›  技术社区  ›  oneManArmin

Visual Studio扩展:向代码编辑器上下文菜单添加元素

  •  1
  • oneManArmin  · 技术社区  · 8 年前

    <Button guid="guidRandomCommandPackageCmdSet" id="RandomCommandId" priority="0x0100" type="Button">
        <Parent guid="guidSHLMainMenu" id="IDG_VS_TOOLS_EXT_TOOLS" />
        <Icon guid="exclamationIcon" id="exclamationIcon1" />
        <Strings>
          <ButtonText>Random Text</ButtonText>
        </Strings>
      </Button>
    

    <GuidSymbol name="guidRandomCommandPackageCmdSet" value="{47122772-c66f-48f3-b10b-dbbb66da120d}">
         .
         .
      <IDSymbol name="RandomCommandId" value="0x0100" />
    </GuidSymbol>
    

    我试图遵循类似的方式,所以我定义了一个新的 Button Buttons

     <Button guid="guidRandomCommandPackageCmdSet" id="ToDoList" priority="0x0100" type="Button">
        <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_CODEWIN"/>
        <Icon guid="exclamationIcon" id="exclamationIcon1" />
        <Strings>
          <ButtonText>Add TODO list</ButtonText>
        </Strings>
      </Button>with the ID symbol
    

    使用GuidSymbols中的ID registerd

      <IDSymbol name="ToDoList" value="0x106" />
    

    但当我运行项目时,该按钮不会显示在关联菜单中。我试着听从 VSIX: Adding a Menu Item to the Visual Studio Editor Context Menu 但这些建议似乎都不适合我。

    1 回复  |  直到 8 年前
        1
  •  2
  •   oneManArmin    8 年前

    Button 将父元素设置为适当的常量菜单元素字符串,如中所定义 GUIDs and IDs of Visual Studio Menus .

    ContextMenu 元素,但是,我需要在 Groups

    <Group guid="guidRandomCommandPackageCmdSet" id="MyMenuGroup" priority="0x0600">
        <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_CODEWIN" />
      </Group>
    

    上下文菜单 Parent . 然后,我创建了一个 CustomCommand 用它,我修改了这个 按钮 Group 父母亲 : `

    Button on Context Menu