Tom Seddon
Tom Seddon

Reputation: 2748

Can one assign keyboard shortcuts to Visual Studio 2012 extensibility package commands that use DynamicItemStart?

I've got a VS2012 extensibility package that adds commands to a menu using the DynamicItemStart command flag, as described on MSDN. These commands work a bit like the inbuilt External Tools facility, so the exact set is configured by the addin user, rather than being defined by me. A DynamicItemStart command seems most suitable for this.

As per the example, I add a bunch of items, hide them, and then control the visibility using the BeforeQueryStatus callback. This all appears to be working: the menu items appear exactly as I'd expect, and you can invoke them by clicking them with the mouse. My package also has one fixed command, and that works too.

My non-dynamic command also appears in the commands list in Tools|Options, Keyboard section, so you can make a keyboard shortcut for it. (You can also invoke it from the Immediate window, which appears to use the same list.) But my dynamic commands don't appear! I was expecting them to turn up as some kind of auto-generated list, like Tools.ExternalCommand.

Are DynamicItemStart commands just not invokable in this way?

Upvotes: 0

Views: 246

Answers (1)

Tom Seddon
Tom Seddon

Reputation: 2748

In case the other person with this problem finds this question...

DynamicItemStart commands don't appear to have names, as far as I can figure out. The docs say they're for MRU or window lists, so maybe nobody thought anybody would need to name them.

So, for my purposes, I just created 100 placeholder commands (Command00 ... Command99), setting the DynamicVisibility and TextChanges command flags for each. (I now have a 1,237-line VSCT file.)

Then at runtime I use the BeforeQueryStatus callback to hide the unused items, show the used items, and set their (user-assigned) captions for the menu. And my UI is careful to show which command corresponds to each assigned action, and keep the mapping intact, so the user knows which of the 100 command names to use when assigning a keyboard shortcuts for each of their actions.

This is hardly ideal, and a bit of an annoying limitation in Visual Studio. But it looks like it's going to work adequately.

Upvotes: 1

Related Questions