views:

253

answers:

2

I created a Visual Studio Add-in that adds additional commands (four of them) to the top of Code Window context menu. I'm using permanent UI approach. Depending on the cursor position within code only one of the commands would be visible and thus selectable. Other three would be hidden.

I set supported and enabled status within QueryStatus method that does the trick for the correct command and unsupported and invisible for the rest.

The problem
The first time add-in is installed all works well. I can only see a single command in the context menu. The rest are always hidden.
The second time I load VS IDE I detect the same commands and controls (so I don't recreate something that's already there), but now all of the commands (or better CommandBarControl/CommandBarButton controls) are visible. Instead of hiding 3 and showing only one I can see all four of them. The correct one is enabled and the rest of the pack is disabled/grayed out.

The question
How do I hide existing commands (or CommandBarButton controls) on the next IDE load? I tried setting button's Visible property to false but then even the correct control isn't displayed.

A: 

Have you tried having a single command, and changing the text of command depending on the cursor position? I'm not sure if this is possible, just a suggestion.

Juozas Kontvainis
A: 

Solution I used at the end was:

  1. Delete controls at IDE startup (or Add-in after startup if not enabled at IDE startup by default). Deleting commands also removes any controls
  2. Recreate commands and controls and their visibility will work as expected.
Robert Koritnik