In VS Solution Explorer, how to extend right click menus on source files sub code elements (class/method/field)
Asked Answered
A

1

11

I am developing a Visual Studio Extension (VSIX).

I need to add custom right-click menus on Solution Explorer right click of class/methods/fields items, that can be found under source file items:

enter image description here

In the .vsct file I already extend the Solution Explorer project/folder/source file/reference right click menus this way:

<CommandPlacement guid="guidNDepend_PackageCmdSet" id="grpSolutionExplorer" priority="0x100">
  <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_ITEMNODE" />
</CommandPlacement>
<CommandPlacement guid="guidNDepend_PackageCmdSet" id="grpSolutionExplorer" priority="0x100">
  <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_PROJNODE" />
</CommandPlacement>
<CommandPlacement guid="guidNDepend_PackageCmdSet" id="grpSolutionExplorer" priority="0x100">
  <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_FOLDERNODE" />
</CommandPlacement>
<CommandPlacement guid="guidNDepend_PackageCmdSet" id="grpSolutionExplorer" priority="0x100">
  <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_REFERENCE" />
</CommandPlacement>    

I tried all other values I have found without success:

IDM_VS_CTXT_CODEWIN
IDM_VS_CTXT_XPROJ_MULTIITEM
IDM_VS_CTXT_XPROJ_PROJITEM
IDM_VS_CTXT_NOCOMMANDS
IDM_VS_CTXT_REFERENCEROOT

Thanks for your help.

(Notice that I already have tricky code to resolve the right-clicked code element, invoked from IVsSelectionEvents.OnSelectionChanged(), just before QueryStatus() handlers are fired)

Analogous answered 24/2, 2015 at 13:16 Comment(0)
P
11

See:

Using EnableVSIPLogging to identify menus and commands with VS 2005 + SP1

and:

How to find Command GUID:ID pairs


Thanks Carlos, I made this work :) So let's explain a bit. First as explained in the blog post I setup the regkey:

[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\General]
"EnableVSIPLogging"=dword:00000001

Then re-starded VS2013, hold Ctrl+SHIFT and right click a file-content class in the SlnExplorer Window. I got this:

enter image description here

The Guid is the guidSHLMainMenu one, but I needed to get the command ID from the value 1842 (0x0732 in hexadecimal). I googled a bit and found this answer. I had VS2013 SDK installed. I looked for where was located the header file vsshlids.h. It was in:

C:\Program Files (x86)\Microsoft Visual Studio 12.0\VSSDK\VisualStudioIntegration\Common\Inc

In this directory I did a search on any text file that contains 732. And I found

#define IDM_VS_CTXT_PROJWIN_FILECONTENTS            0x732  // Context menu for GraphNode items in the Solution Explorer

in

C:\Program Files (x86)\Microsoft Visual Studio 12.0\VSSDK\VisualStudioIntegration\Common\Inc\vsshlids.h

Hence the name I was looking for is IDM_VS_CTXT_PROJWIN_FILECONTENTS and indeed with this value it works like a charm; Thanks Carlos!

Placable answered 24/2, 2015 at 14:21 Comment(1)
Both links are invalid by now (but it's not your fault). :) But thanks for your help. For VS2017 I needed to additionally in regedit, I've selected HKEY_USERS, File > Load Hive, selected file: "C:\Users\user\AppData\Local\Microsoft\VisualStudio\15.0_effa0b41Exp\privateregistry.bin" typed as vs2017_exp, and selected registry branch: HKEY_USERS\vs2017_exp\Software\Microsoft\VisualStudio\15.0_effa0b41Exp\General Otherwise works identically.Luminosity

© 2022 - 2024 — McMap. All rights reserved.