VSPackage: change text of toolbar button / tooltip at runtime

I am developing a Visual Studio extension as an add-on for VS2008 / 2010. The new version should now be made as a VSIX package only for VS2010 (as well as .NET 4 nevertheless), and I had problems with (quite simple, I would think) user interface control.

The extension mainly consists of a toolbar with several buttons that launch various actions, forms, etc., and several that are used only as labels for displaying status information. The "label" buttons themselves show very short and concise information, and the hints provide more detailed information.

While I did not think the whole add-in was very elegant, doing such things was quite simple (although my approach may have been a little amateurish). When adding commands to the toolbar, I would "save" the "shortcut" buttons in certain local variables, which allowed me to later set the font and tooltip text.

In VSPackage, the equivalent of Microsoft.VisualStudio.CommandBars.CommandBarButton is represented by OleMenuCommand. Finding the label command with MenuCommandService is not a problem, but you need to modify it if necessary.

To find out how to do this, I have a toolbar with two buttons in a group. btnAction is very simple; just an icon and a handler for changing text on another button, without CommandFlags. btnLabel looks like this: .vsct:

<Button guid="guidVSPackageBuilderTutorialCommandSet" id="btnLabel" priority="0x0100"> <CommandFlag>DefaultDisabled</CommandFlag> <CommandFlag>DontCache</CommandFlag> <CommandFlag>NoCustomize</CommandFlag> <CommandFlag>TextChanges</CommandFlag> <CommandFlag>TextOnly</CommandFlag> <Strings> <CommandName>cmdidbtnLabel</CommandName> <ButtonText>btnLabel</ButtonText> <MenuText>btnLabel</MenuText> <ToolTipText>Tooltip btnLabel</ToolTipText> </Strings> </Button> 

The first problem is that when I use TextChanges , the ToolTipText line is ignored, and ButtonText is also used for the tooltip.

The action button handler code is as follows:

 private int iClickCount = 0; protected override void btnActionExecuteHandler(object sender, EventArgs e) { var svc = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; CommandID idBtnLabel = new CommandID(GuidList.guidVSPackageBuilderTutorialCmdSet, (int)PkgCmdIDList.btnLabel); var cmd = svc.FindCommand(idBtnLabel) as OleMenuCommand; cmd.Text = "Clicked " + (++iClickCount) + " times"; } 

This changes the btnLabel header, as expected, but since there is no way to explicitly indicate a tooltip (the OleMenuCommand object has a Text property, unlike the CommandBarButton, which has both Caption and TooltipText), the tooltip is always set to the same line as and signature. From what I understand, this is because with FindCommand () I actually do not get the user interface button, but only the basic command that does not care about the hints.

What is even more confusing is what happens when I use TextChangesButton CommandFlag instead of TextChanges . Now the button will correctly display the tooltip text defined in .vsct, but neither the title nor the tooltip will change when another button is clicked - although when I check the Text property of the btnLabel property, it is configured to what I expect ("Click x times "). Is TextChangesButton a type of "untie" command and button properties? If so, this is pretty much what I want (I don't care about the command, since nothing needs to be done, btnLabel will always be disabled), but how can I access the button and its specific row properties?

I looked through the various IV and SVs interfaces, but could not find anything suitable, and the documentation (and the help of IntelliSense) does not seem very extensive.

+4
source share
1 answer

To answer this myself - according to someone from the VS team, the new extensibility framework does not offer ways to access these properties of controls in such detail. For what I want to achieve, I will have to go through the old way to take control of the DTE object, find my toolbar and my controls and just process them as CommandBarButtons, as in my add-in.

+1
source

All Articles