Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)

like image 637
Patrick from NDepend team Avatar asked Feb 24 '15 13:02

Patrick from NDepend team


People also ask

How do I adjust Solution Explorer on right side?

Choose Tools > Options > Environment > Tabs and Windows from the menu bar. Then, from the Set tab layout control, choose either Top, Left, or Right from the drop-down list.

How do I configure Solution Explorer in Visual Studio?

By default, the Solution Explorer tool window appears as a pane in the upper-right side of the Visual Studio integrated development environment (IDE). If you don't see the Solution Explorer tool window, you can open it from the Visual Studio menu bar by using View > Solution Explorer, or by pressing Ctrl+Alt+L.

How do I use Solution Explorer in Visual Studio code?

You can open any solution, project, folder or file in Visual Studio Code by simply right-clicking it in Solution Explorer and select Open in Visual Studio Code.


1 Answers

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!

like image 153
Carlos Quintero Avatar answered Oct 19 '22 09:10

Carlos Quintero