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

2

5

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?

Fasten answered 11/1, 2013 at 19:49 Comment(0)
F
8

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>
Fasten answered 14/1, 2013 at 10:15 Comment(1)
Thanks for that, the vsct and its documentation are a nightmare.Caricature
G
3

Matze's solution will show MenuController as text. If you want to show MenuController as icon, like undo or redo in VS toolbox, you can add a Button as anchor item for the MenuController:

  <Button guid="guidVsCmdSet" id="AnchorButton" priority="0x0100" type="Button">
    <Parent guid="guidVsCmdSet" id="VsSubMenuGroup" />
    <Icon guid="guidIcons" id="IconId" />
    <CommandFlag>NoShowOnMenuController</CommandFlag>  
    <!-- Become the permanent anchor item for the menu controller -->  
    <CommandFlag>FixMenuController</CommandFlag>
    <CommandFlag>Pict</CommandFlag>
    <Strings>
      <ButtonText>Button Text</ButtonText>
    </Strings>
  </Button>

The key is the NoShowMenuController and FixMenuController CommandFlag.

It took me hours to figure it out until I came across this page: https://learn.microsoft.com/en-us/visualstudio/extensibility/dynamically-adding-menu-items?view=vs-2017

Gorblimey answered 21/9, 2018 at 2:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.