1

I need to assign a shortcut key to a dynamic menu item in a VS 2015 extension. The vsct file is as follows:

<?xml version="1.0" encoding="utf-8"?>
<CommandTable xmlns="http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <Extern href="stdidcmd.h"/>
    <Extern href="vsshlids.h"/>

    <Commands package="guidPackage">

        <Groups>
            <Group guid="guidMenu" id="MyMenuGroup" priority="0x0600">
                <Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS"/>
            </Group>
            <Group guid="guidSubMenu" id="MyMenuSubgroup" priority="0x0100">
                <Parent guid="guidMenu" id="SubMenu"/>
            </Group>
        </Groups>

        <Menus>
            <Menu guid="guidMenu" id="SubMenu" priority="0x0100" type="Menu">
                <Parent guid="guidMenu" id="MyMenuGroup"/>
                <Strings>
                    <ButtonText>Minimal commands</ButtonText>
                    <CommandName>MinimalCommands</CommandName>
                </Strings>
            </Menu>
        </Menus>

        <Buttons>
            <Button guid="guidSubMenu" id="idTest" priority="0x0100" type="Button">
                <Parent guid="guidSubMenu" id="MyMenuSubgroup" />
                <CommandFlag>DynamicItemStart</CommandFlag>
                <Strings>
                    <ButtonText>Invoke Minimal Test</ButtonText>
                    <CommandName>MinimalTest</CommandName>
                </Strings>
            </Button>
        </Buttons>

    </Commands>

    <Symbols>
        <GuidSymbol name="guidPackage" value="{3e88287b-7b79-403d-ae8d-3329af218869}" />
        <GuidSymbol name="guidMenu" value="{c1388361-6429-452c-8ba0-580d292ef0ca}">
            <IDSymbol name="MyMenuGroup" value="0x1020" />
            <IDSymbol name="SubMenu" value="0x200"/>
        </GuidSymbol>
        <GuidSymbol name="guidSubMenu" value="{09E1B0D1-E466-4263-9D00-2EDCBDD954B2}">
            <IDSymbol name="idTest" value="0x0100" />
            <IDSymbol name="MyMenuSubgroup" value="0x1021"/>
        </GuidSymbol>
    </Symbols>
</CommandTable>

I have code that adds "Dynamic Command 1" and "Dynamic Command 2" in place of the "Minimal Test" command you see in the .vsct file. The menu displays correctly:

Tools

Minimal Commands >

Dynamic Command 1
Dynamic Command 2

Clicking on the menu invokes the handler. So far so good.

Now for the problem: I can't see the two dynamic commands in the Tools.Options.Keyboard list. Based on the unanswered question at Can one assign keyboard shortcuts to Visual Studio 2012 extensibility package commands that use DynamicItemStart?, it appears that the problem derives from having menu items that overlay a DynamicItemStart. My example is more complicated because it uses a different GUID for the dynamic command submenu. [My real app has a command filter derived from IOleCommandTarget. It hangs just before QueryStatus if the DynamicItemStart item is in the same GUID group as the fixed commands.] But I don't think the multiple GUIDs are contributing to the problem.

Community
  • 1
  • 1
Walter Oney
  • 163
  • 5

1 Answers1

0

Following the lead of the cited post, I defined a few placeholder buttons, none of which has the DynamicItemStart attribute but each of which does have the DefaultInvisible, DynamicVisibility, and TextChanges attributes. In my QueryStatus handler, I use an OLETEXTCMD class (found on this site) to change the name from Placeholderxxx to something more useful. The menu displays as I was hoping it would. The only glitch, also noticed in the cited post, is that the keyboard shortcut list uses the Placeholderxxx names. Because of this imperfection, I don't plan to release my extension (a macro processor that I need to make VS 2015 useful) to the wild.

I sure do wish there were a better solution to the problem of defining dynamic menu items.

Walter Oney
  • 163
  • 5