locked
Custom Context Menu under Right Click Solution Explorer RRS feed

  • Question

  • Hi,

    I have achieved creating Context Menu on the right Click of Solution Explorer. I need to create Sub Menu Under like

     

    Solution Explorer Window

    ------------------------------------------

    Some Solution

        Some Project    Right Click on this Project

                                              |          Build              |

                                              |          ReBuild          |

                                              |          Clean             |

                                              |          Add       >      |

                                              |          My Button    > |   |  Option  1  |

                                                                                                       |  Option  2  |

                                                                                                       |  Option  3  |

                                                                                                       |  Option  4  |

     

    Is there any way to achieve this functionality on the right click of solution explorer.

     

    Please let me know with examples.

     

    Thanks,

    Mohid

     

    Wednesday, April 27, 2011 7:56 PM

Answers

  • You simply need to create a new Menu entry in your VSCT, add a new Group parented to that new Menu item.  Then parent the Menu to the group that your button is currently parented to (the one that makes it appear on the solution explorer context menu) and then parent your button to the new group that you parented to your new Menu.  I didn't have time to whip up a sample but you can tweak what you have with your Button element and get there I am sure.

    Ryan

    • Marked as answer by DotnetHungry Thursday, April 28, 2011 6:32 PM
    Wednesday, April 27, 2011 9:52 PM
  • Hi Ryan,

     

     I have achieved that TASK these the main steps to Do under VSCT file.

     

     <Menus>

          <Menu guid="guidContextMenu1CmdSet"

            id="TopLevelMenu" priority="0x700" type="Menu">

            <Parent guid="guidSHLMainMenu"

                    id="IDG_VS_CTXT_PROJECT_ADD" />

            <Strings>

              <ButtonText>Merrill Lynch</ButtonText>

              <CommandName>Merrill Lynch</CommandName>

            </Strings>

          </Menu>

     

        </Menus>

     

    Under groups

    <Groups>

     <Group guid="guidContextMenu1CmdSet" id="MyMenuGroup"

    priority="0x0600">

            <Parent guid="guidContextMenu1CmdSet" id="TopLevelMenu"/>

          </Group>

    </Groups>

     

    Under Buttons

    <Buttons>

      <Button guid="guidContextMenu1CmdSet" id="cmdidMyCommand" priority="0x0100" type="Button">

            <Parent guid="guidContextMenu1CmdSet" id="MyMenuGroup" />

            <Icon guid="guidImages" id="bmpPic1" />

            <Strings>

              <CommandName>cmdidMyCommand</CommandName>

              <ButtonText>My Command name</ButtonText>

            </Strings>

          </Button>

     

     

          <Button guid="guidContextMenu1CmdSet" id="cmdidMyCommand1" priority="0x0100" type="Button">

            <Parent guid="guidContextMenu1CmdSet" id="MyMenuGroup" />

            <Icon guid="guidImages" id="bmpPic2" />

            <Strings>

              <CommandName>cmdidMyCommand1</CommandName>

              <ButtonText>My Command name2</ButtonText>

            </Strings>

          </Button>

     

          <Button guid="guidContextMenu1CmdSet" id="cmdidMyCommand2" priority="0x0100" type="Button">

            <Parent guid="guidContextMenu1CmdSet" id="MyMenuGroup" />

            <Icon guid="guidImages" id="bmpPic3" />

            <Strings>

              <CommandName>cmdidMyCommand2</CommandName>

              <ButtonText>My Command name3</ButtonText>

            </Strings>

          </Button>   

        </Buttons>

     

    Under PackageCMDID.cs File

     

     public const uint cmdidMyCommand =        0x100;     

            public const uint cmdidMyCommand1 = 0x100;

            public const uint cmdidMyCommand2 = 0x100;

    Under Package.cs File
     CommandID menuCommandID = new CommandID(GuidList.guidContextMenu1CmdSet, (int)PkgCmdIDList.cmdidMyCommand);
                    MenuCommand menuItem = new MenuCommand(MenuItemCallback, menuCommandID );
                    mcs.AddCommand( menuItem );
                    CommandID menuCommandID1 = new CommandID(GuidList.guidContextMenu1CmdSet, (int)PkgCmdIDList.cmdidMyCommand1);
                    MenuCommand menuItem1 = new MenuCommand(MenuItemCallback, menuCommandID1);
                    mcs.AddCommand(menuItem1);
                    CommandID menuCommandID2 = new CommandID(GuidList.guidContextMenu1CmdSet, (int)PkgCmdIDList.cmdidMyCommand2);
                    MenuCommand menuItem2 = new MenuCommand(MenuItemCallback, menuCommandID2);
                    mcs.AddCommand(menuItem2);
    Now write the Events you need to add for the commands.
    Thanks,
    Mohid

    • Marked as answer by DotnetHungry Thursday, April 28, 2011 6:52 PM
    Thursday, April 28, 2011 6:36 PM

All replies

  • It is easily done, what method are you using to create your button? VSCT or DTE?

    Ryan

    Wednesday, April 27, 2011 9:00 PM
  • Hi Ryan,

       Thanks for the reply, I'm using VSCT to create context menu for Solution Explorer.

    Thanks,

    Mohid

     

    Wednesday, April 27, 2011 9:37 PM
  • You simply need to create a new Menu entry in your VSCT, add a new Group parented to that new Menu item.  Then parent the Menu to the group that your button is currently parented to (the one that makes it appear on the solution explorer context menu) and then parent your button to the new group that you parented to your new Menu.  I didn't have time to whip up a sample but you can tweak what you have with your Button element and get there I am sure.

    Ryan

    • Marked as answer by DotnetHungry Thursday, April 28, 2011 6:32 PM
    Wednesday, April 27, 2011 9:52 PM
  • Hi Ryan,

     

     I have achieved that TASK these the main steps to Do under VSCT file.

     

     <Menus>

          <Menu guid="guidContextMenu1CmdSet"

            id="TopLevelMenu" priority="0x700" type="Menu">

            <Parent guid="guidSHLMainMenu"

                    id="IDG_VS_CTXT_PROJECT_ADD" />

            <Strings>

              <ButtonText>Merrill Lynch</ButtonText>

              <CommandName>Merrill Lynch</CommandName>

            </Strings>

          </Menu>

     

        </Menus>

     

    Under groups

    <Groups>

     <Group guid="guidContextMenu1CmdSet" id="MyMenuGroup"

    priority="0x0600">

            <Parent guid="guidContextMenu1CmdSet" id="TopLevelMenu"/>

          </Group>

    </Groups>

     

    Under Buttons

    <Buttons>

      <Button guid="guidContextMenu1CmdSet" id="cmdidMyCommand" priority="0x0100" type="Button">

            <Parent guid="guidContextMenu1CmdSet" id="MyMenuGroup" />

            <Icon guid="guidImages" id="bmpPic1" />

            <Strings>

              <CommandName>cmdidMyCommand</CommandName>

              <ButtonText>My Command name</ButtonText>

            </Strings>

          </Button>

     

     

          <Button guid="guidContextMenu1CmdSet" id="cmdidMyCommand1" priority="0x0100" type="Button">

            <Parent guid="guidContextMenu1CmdSet" id="MyMenuGroup" />

            <Icon guid="guidImages" id="bmpPic2" />

            <Strings>

              <CommandName>cmdidMyCommand1</CommandName>

              <ButtonText>My Command name2</ButtonText>

            </Strings>

          </Button>

     

          <Button guid="guidContextMenu1CmdSet" id="cmdidMyCommand2" priority="0x0100" type="Button">

            <Parent guid="guidContextMenu1CmdSet" id="MyMenuGroup" />

            <Icon guid="guidImages" id="bmpPic3" />

            <Strings>

              <CommandName>cmdidMyCommand2</CommandName>

              <ButtonText>My Command name3</ButtonText>

            </Strings>

          </Button>   

        </Buttons>

     

    Under PackageCMDID.cs File

     

     public const uint cmdidMyCommand =        0x100;     

            public const uint cmdidMyCommand1 = 0x100;

            public const uint cmdidMyCommand2 = 0x100;

    Under Package.cs File
     CommandID menuCommandID = new CommandID(GuidList.guidContextMenu1CmdSet, (int)PkgCmdIDList.cmdidMyCommand);
                    MenuCommand menuItem = new MenuCommand(MenuItemCallback, menuCommandID );
                    mcs.AddCommand( menuItem );
                    CommandID menuCommandID1 = new CommandID(GuidList.guidContextMenu1CmdSet, (int)PkgCmdIDList.cmdidMyCommand1);
                    MenuCommand menuItem1 = new MenuCommand(MenuItemCallback, menuCommandID1);
                    mcs.AddCommand(menuItem1);
                    CommandID menuCommandID2 = new CommandID(GuidList.guidContextMenu1CmdSet, (int)PkgCmdIDList.cmdidMyCommand2);
                    MenuCommand menuItem2 = new MenuCommand(MenuItemCallback, menuCommandID2);
                    mcs.AddCommand(menuItem2);
    Now write the Events you need to add for the commands.
    Thanks,
    Mohid

    • Marked as answer by DotnetHungry Thursday, April 28, 2011 6:52 PM
    Thursday, April 28, 2011 6:36 PM