Tuesday, March 13, 2007
Adding Refactor Context Menu in Visual Studio .Net Add-ins
When you are creating a new VS .Net Add-in, you can optionally add a command in the "Tools" Command Bar. But what if you want to add your add-in in another command bar? Well, I didn't find a nice way to do that. What I needed was to add the a Command in the Refactor Command Bar (Menu and Context Menu) so what I was looking is the following result:
What you need to do is to use the "MenuBar" (the same that creates the Add-In wizard for the "Tools" Command Bar) and the "Other Context Menus" (this is the one you need to add the menu in the context menu).
here it's the (simplified) code fragment:
CommandBar menuBarCommandBar = ((CommandBars)_applicationObject.CommandBars)["MenuBar"];
CommandBar otherContextMenu = ((CommandBars)_applicationObject.CommandBars)["Other Context Menus"];
CommandBarControl refactorControl = menuBarCommandBar.Controls["Refactor"];
CommandBarPopup refactorPopup = (CommandBarPopup)refactorControl;
CommandBarControl refactorContextControl = otherContextMenu.Controls["Refactor"];
CommandBarPopup refactorContextPopup = (CommandBarPopup)refactorContextControl;
What I did to discover the "Other Context Menus" CommandBar name?... well take a look at this article: HOWTO: Guessing the name of a command bar to add a custom menu entry in Visual Studio .NET add-ins
Labels: .Net, VS Extensibility
<< Home