sdkvisual-studio-2012vsxvisual-studio-extensionsvsix

How to define a SplitDropDown or MenuButton for a toolbar in a *.vsct file?


I defined a toolbar for a tool window by following this walk-through description.

Adding new buttons to the toolbar, and connecting them to code within my package, is no problem and works fine (So I am not looking for information on how to add simple buttons). I saw that there are other button types, like SplitDropDown and MenuButton. Both would perfectly meet my requirements. But I couldn't find any information on how to define a sub-menu the correct way, and all my experiments failed.

This is my button definition:

<Button guid="guidVsCmdSet" id="cmdIdSplitDowndown" priority="0x106" type="SplitDropDown">
  <Parent guid="guidVsCmdSet" id="VsToolbarGroup" />
  <Icon guid="guidImages" id="bmpPic2" />
  <CommandFlag>IconAndText</CommandFlag>
  <Strings>
    <CommandName>cmdIdSplitDropdown</CommandName>
    <ButtonText>Goto Next</ButtonText>
  </Strings>
</Button>

I want to add a SplitDropDown button having some predefined/static sub-items. I guess that the visual appearance of the button would look like the "Navigate backward" button of Visual Studio. That's what I am trying to achieve.

Does anybody know what the definition of a SplitDropDown button, having a submenu, would look like?


Solution

  • It seems that the SplitDropDown and MenuButton types are no longer supported by the Visual Studio IDE (at least v11, but I haven´t tested it on earlier versions. Maybe I am wrong, but I couldn´t get these kind of buttons into my toolbar). Instead, a Menu of type Menu or MenuController can be used. The type Menu behaves like the deprecated MenuButton (even if it´s visual apperance is not exactly the same due to it´s smaller height of the button) and the type MenuController behaves like the deprecated SplitDropDown.

    So, in order to get a split drop-down I added the following Menu declaration to my VSCT file:

    <Menu guid="guidVsCmdSet" id="menuIdSubMenu" type="MenuController" priority="0x0001" toolbarPriorityInBand="0x0001">
        <Parent guid="guidVsCmdSet" id="VsToolbarGroup" />
        <CommandFlag>IconAndText</CommandFlag>
        <CommandFlag>NotInTBList</CommandFlag>
        <Strings>
            <ButtonText>My Button</ButtonText>
            <CommandName>My Button</CommandName>
        </Strings>
    </Menu>
    

    And created a new group for the drop-down commands; the group's parent is set to the menu.

    <Group guid="guidVsCmdSet" id="VsSubMenuGroup" priority="0x0001">
        <Parent guid="guidVsCmdSet" id="menuIdSubMenu" />
    </Group>
    

    Finally, I can add ordinary buttons to that group, which will appear as menu items.

    <Button guid="guidVsCmdSet" id="cmdIdSubMenuItem1" priority="0x0001" type="Button">
        <Parent guid="guidVsCmdSet" id="VsSubMenuGroup" />
        <CommandFlag>TextOnly</CommandFlag>
        <Strings>
            <CommandName>cmdIdSubMenuItem1</CommandName>
            <ButtonText>Members</ButtonText>
        </Strings>
    </Button>