Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding SubMenu to Visual Studio Project Item Node

How can I add a menu and sub menu items when right click on a file item visual studio solution explorer?

I have one menu and three sub menu items which will be displayed when I right click on a file in solution explorer like the below picture.

I tried using .vsct buttons but it will display on context menu and Iam unable to add sub menus

enter image description here

like image 874
Biju Thomas Avatar asked Nov 02 '13 11:11

Biju Thomas


1 Answers

Authoring VSCT files is somewhat tricky; what you´ll need is a combination of a menu and buttons. First of all you need to reference the IDM_VS_CTXT_ITEMNODE group in your VSCT file.

<Group guid="guidCmdSet" id="grpIdMenuProjectItem" priority="0x0800">
    <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_ITEMNODE" />
</Group>

Than you create a new menu and add it to that group...

  <Menu guid="guidCmdSet" id="sampleMenu" type="Menu" priority="0x1000">
    <Parent guid="guidCmdSet" id="grpIdMenuProjectItem" />
    <CommandFlag>IconAndText</CommandFlag>
    <Strings>
      <ButtonText>Sample Menu</ButtonText>
      <CommandName>Sample Menu</CommandName>
    </Strings>
  </Menu>

For the submenu items another group is required, which will be added to the menu...

<Group guid="guidCmdSet" id="sampleMenuGroup" priority="0x1000">
    <Parent guid="guidCmdSet" id="sampleMenu"/>
</Group>

At least you define your submenu items using buttons and add them to the submenu group...

<Button guid="guidCmdSet" id="sampleMenuItem" priority="0x1000" type="Button">
    <Parent guid="guidCmdSet" id="sampleMenuGroup"/>
    <CommandFlag>TextOnly</CommandFlag>
    <Strings>
        <ButtonText>Sample Menu Item 1</ButtonText>
        <CommandName>sampleMenuItem1</CommandName>
    </Strings>
</Button>

Don´t forget to define all symbols, otherwise the resource won´t compile.

<IDSymbol name="grpIdMenuProjectItem" value="0x1020"/>
<IDSymbol name="sampleMenu" value="0x1021"/>
<IDSymbol name="sampleMenuGroup" value="0x1022"/>
<IDSymbol name="sampleMenuItem" value="0x1023"/>

And this is what you get...

enter image description here

like image 166
Matze Avatar answered Oct 08 '22 00:10

Matze