Reputation: 716
I'm trying to add a new element to the Visual Studio 2017 Context Menu. I managed to add an element to the TOOLS menu with the following code:
<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>
which is registered in
<GuidSymbol name="guidRandomCommandPackageCmdSet" value="{47122772-c66f-48f3-b10b-dbbb66da120d}">
.
.
<IDSymbol name="RandomCommandId" value="0x0100" />
</GuidSymbol>
I tried to follow a similar fashion, so I defined a new Button
in 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
with the ID registerd in GuidSymbols
<IDSymbol name="ToDoList" value="0x106" />
But the button does not show up in the context menu, when I run the project. I tried to follow the suggestions of VSIX: Adding a Menu Item to the Visual Studio Editor Context Menu but none of the suggestions seems to work for me. I never tried to create a VS add-on before, so I welcome any suggestions. Is it possible that the method changed in VS 2017?
Upvotes: 1
Views: 1013
Reputation: 716
Eventually, I managed to get it working. It seems that while for MENU items that show up either as a separate menu or belonging to a menu like TOOLS, it is enough to have only a Button
with the parent set to the appropriate constant menu element string as defined at GUIDs and IDs of Visual Studio Menus.
For ContextMenu
elements, however, I needed to have an element in Groups
:
<Group guid="guidRandomCommandPackageCmdSet" id="MyMenuGroup" priority="0x0600">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_CODEWIN" />
</Group>
This has the ContextMenu
as its Parent
. Then, I created a CustomCommand
that auto-generates a Button
with it and I modified this Button
to have the Group
element as itsParent
:
`
Add TODO list
This is the result with the added button hovered over:
Upvotes: 4