Showing context menu for multi-selected custom nodes in the solution explorer RRS feed

  • Question

  • I have a VSPackage that I am trying to modify.  The package is using GraphProviderAttribute marked class to implement a custom Microsoft.VisualStudio.GraphModel.IGraphProvider.  Whenever the custom file type is expanded in Solution Explorer, the new GraphNode is created via IGraphContext.Graph.Nodes.GetOrCreate(..) method.  The node is subsequently inserted into the context via the call to IGraphContext.OutputNodes.Add().  The context menu command is created in .vsct file and handled in code whenever single custom node is selected.  The problem is that whenever multiple custom nodes are selected, the context menu does not show up at all.  I am not sure what is telling context menu that houses the custom command to show up.  Can someone point out what could be happening there?  The context menu command that works for single node selection is placed in the following:

    <CommandPlacement guid="guidCommandSet" id="Update" priority="0x0100">
                <Parent guid="guidSHLMainMenu" id="IDG_VS_CTXT_PROJWIN_FILECONTENTS_SCOPE" />

    So, the context menu command for single item selection shows up under 'Scope To This' menu command.

    Thank you,


    Monday, December 15, 2014 10:32 PM

All replies

  • Hi Alex,

    VS typically uses different context menu entries for single selection, multiple selection (in-project) and multiple selection (cross-project). See

    Common Context Menu Constants

    In your case the vsshlids.h file of the VS SDK provides the following ones, maybe one of them helps you:

    #define IDM_VS_CTXT_PROJWIN_FILECONTENTS            0x732  // Context menu for GraphNode items in the Solution Explorer
    #define IDM_VS_CSCD_PROJWIN_FILECONTENTS_SCOPELIST  0x733  // Flyout menu for changing the view to a different aspect
    #define IDG_VS_CTXT_PROJWIN_SCOPE                   0x734  // Group for containing view-scoping commands (Scope View To This, New View, Change View To)
    #define IDG_VS_CTXT_PROJWIN_SCOPELIST               0x735  // Group for containing the dynamic list of scopes the Solution Explorer can be changed to
    #define IDG_VS_CTXT_PROJWIN_FILECONTENTS_SCOPE      0x736  // Group specifically for the Item Contents context menu, containing the Scope View To This command
    #define IDG_VS_CTXT_PROJWIN_FILECONTENTS_NEWVIEW    0x737  // Group specifically for the Item Contents context menu, containing the New View command
    #define IDG_VS_TOOLBAR_PROJWIN_FILTERS              0x738  // Group containing common filters for the Solution Explorer (e.g. Opened, Pending Changes)
    #define IDM_VS_CTXT_PEEKRESULT                      0x739  // Context menu for results in Peek
    #define IDG_VS_CTXT_PEEKRESULTGROUP                 0x73A  // Contains commands that can run on peek results (Copy Full Path, Promote to Document, Open Containing Folder)

    * My new blog about VSX: http://www.visualstudioextensibility.com * Twitter: https://twitter.com/VSExtensibility * MZ-Tools productivity extension for Visual Studio: http://www.mztools.com.

    Tuesday, December 16, 2014 7:15 AM
  • Thanks for the quick reply.  I tried most of these without success.  The problem is there is no context menu for the multiply selected custom nodes at all.  I don't understand the mechanism of how they are being assigned.  Seems like the statement

    <Parent guid="guidSHLMainMenu" id="IDG_VS_CTXT_PROJWIN_FILECONTENTS_SCOPE"

    would add the new menu command to the existing IDG_VS_CTXT_PROJWIN_FILECONTENTS_SCOPE context menu. So the rules for displaying the additional command would also depend on the context of the existing menu that it was assigned to.  This is why I think I am not having success - because the context menu that I am assigning my command to does not show up for a given context (multiple custom nodes selected)   What if I want to add a brand new Context Menu?  Is there a way to do this?  I know how to create the top level menu menu - but this would not be available when right clicking on the item..



    Tuesday, December 16, 2014 5:52 PM
  • Hi Alex,

    The menu is typically displayed deep inside the project system's IVsUIHierarchy or IOleCommandTarget implementation. If you're seeing a menu with you right click with multiple items selected, you just need to determine the guid:id pair that uniquely identifies that particular menu. Then create a menu group parented to that context menu, that contains your menu items.

    If you are the implementer of the project system, you just need to find where you call IVsUIShell.ShowContextMenu, and swap in your own if that's what you want.

    However, if you already have a context menu, you can use the EnableVSIPLogging registry value to quickly identify the guid:id pair, needed to parent your own menu group to the context menu.


    Ed Dore

    • Marked as answer by Caillen Monday, December 22, 2014 4:26 PM
    • Unmarked as answer by Caillen Wednesday, May 13, 2015 2:32 AM
    Thursday, December 18, 2014 5:43 PM
  • Hi Ed,

    I am not seeing any menu when my multiple custom nodes are selected and right clicked.  So, does this mean the only option I have is to use IVsUIShell.ShowContextMenu?  But how do I even get the right click event when my nodes are clicked?



    Monday, January 5, 2015 8:38 PM