Reputation: 4036
I'd like to build a VS add-in that extends Solution explorer context menu
I know how to add the VS add-in menu item using the IDM_VS_CTXT_ITEMNODE
or IDM_VS_CTXT_PROJNODE
like in the sample below
<Group guid="guidCmdSet" id="grpIdMenuProjectItem" priority="0x0700">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_ITEMNODE" />
</Group>
However menu I'd like to show should display complex context menu with subitems. I'd like to add the same menu item to both Project and Item context menus.
So I've tried
<Group guid="guidCmdSet" id="grpIdMenuProjectItem" priority="0x0700">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_ITEMNODE" />
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_PROJNODE"/>
</Group>
but id does not work.
The problem is that vsct
file declares parents for children so I can't just declare one child and link it to several parents.
How can I add the same menu to both Project and Item context menus ? I'd like to avoid copy pasting the grpIdMenuProjectItem
children it it is possible.
the whole source code sample can be found at github
Upvotes: 1
Views: 3293
Reputation: 4036
the solution is to use CommandPlacement
as Perry said
To duplicate the same group with submenu items I removed the parent element from the grpIdMenuProjectItem
group declaration
<Group guid="guidCmdSet" id="grpIdMenuProjectItem" priority="0x0700">
</Group>
and have added three command placements for item, project and folder parents
<CommandPlacements>
<CommandPlacement guid="guidCmdSet" id="grpIdMenuProjectItem" priority="0xF00">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_ITEMNODE" />
</CommandPlacement>
<CommandPlacement guid="guidCmdSet" id="grpIdMenuProjectItem" priority="0xF00">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_PROJNODE" />
</CommandPlacement>
<CommandPlacement guid="guidCmdSet" id="grpIdMenuProjectItem" priority="0xF00">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_FOLDERNODE" />
</CommandPlacement>
</CommandPlacements>
The CommandPlacements
node should be added after the Commands
node as documented.
Upvotes: 1
Reputation: 23868
Add SubMenu to VS solution explorer project and item node types
You can use CommandPlacements to make one button be used in several menus.
Solution
Usually, you can use this format to realize your needs:
<CommandPlacements>
<CommandPlacement guid="xxx(the same button guid)" id="xxx(the same button id)" priority="0xF00">
<Parent guid="xxx(the first group guid)" id="xxx(the first group id)"/>
</CommandPlacement>
<CommandPlacement guid="xxx(the same button guid)" id="xxx(the same button id)" priority="0xF00">
<Parent guid="xxx(the second group guid)" id="xxx(the second group id)"/>
</CommandPlacement>
..........
</CommandPlacements>
In your situation, for an example, I made your button Sample Menu Item 1
be used in both IDM_VS_CTXT_ITEMNODE
and IDM_VS_CTXT_PROJNODE
.
Since you have made Sample Menu Item 1
in the sub menu of QQQ Menu
under IDM_VS_CTXT_ITEMNODE
, you just need to define the button Sample Menu Item 1
in CommandPlacements like this:
<CommandPlacements>
<CommandPlacement guid="guidCmdSet" id="sampleMenuItem" priority="0xF00">
<Parent guid="guidVSIXProject1PackageCmdSet" id="MyMenuGroup"/>
</CommandPlacement>
</CommandPlacements>
Upvotes: 1