How to add an additional button to the standard context menu that appears when you right-click next to the code?

For example, this functionality:

  • right click brings up the standard menu
  • in addition to the standard menu there is a new button
  • clicking on it triggers an action (for example, a message appears)
  • reformulate the title and the question itself so that it is clear that you just need to add a button in the menu that will be formatted. And not just to do something. - PashaPash
  • @PashaPash fixed. Only in this question I am interested in the introduction of my button in the standard menu (I was interested in formatting only today) - RussCoder
  • You are here completely copied the contents of an article in the description of the label. So do not. All the more strange is the text "about which we will talk a little lower." ru.stackoverflow.com/review/suggested-edits/49700 - Nick Volynkin
  • @NickVolynkin is good, I will not rule anymore. - RussCoder
  • @RussCoder: you can edit it, but process the text, there are also clear requirements for label descriptions. You can see for example android as an example. Here, too, because copied? ru.stackoverflow.com/review/suggested-edits/39400 - Nick Volynkin

1 answer 1

The answer is partially found.

You just need to create a standard project - Visual Stutio Package. Select Menu Command as the interface in the dialog box when creating (first option). Then open the .vsct file and change the parent of the group:

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

Exactly

 <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_CODEWIN"/> 

Binds a group (with a button) to the menu that appears when you right-click in the code. The id of this menu IDM_VS_CTXT_CODEWIN and the standard guid guidSHLMainMenu are important here. You can view other id and guid (better in VS - there with a description) https://msdn.microsoft.com/ru-ru/library/vstudio/microsoft.visualstudio.shell.vsmenus_members(v=vs.100).aspx# mainBody

You can write anything in the handler and it will work.

 private void MenuItemCallback(object sender, EventArgs e) { MessageBox.Show("Уже что-то заработало!!!"); }