
Chapter 13: Extending Visual Studio 2010 | 385 |
Reviewing OnConnection Generated Code
You know that the purpose of the OnConnection method is to help initialize the
Listing 13-2 The OnConnection method
C#:
public void OnConnection(
object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
_applicationObject = (DTE2)application; _addInInstance = (AddIn)addInInst; if(connectMode == ext_ConnectMode.ext_cm_UISetup)
{
object []contextGUIDS = new object[] { }; Commands2 commands =
(Commands2)_applicationObject.Commands; string toolsMenuName = "Tools";
Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((
Microsoft.VisualStudio.CommandBars.CommandBars) _applicationObject.CommandBars)["MenuBar"];
CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName];
CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl;
try
{
Command command = commands.AddNamedCommand2( _addInInstance, "KeystrokeFinder", "KeystrokeFinder",
"Executes the command for KeystrokeFinder", true, 59, ref contextGUIDS, (int)vsCommandStatus
.vsCommandStatusSupported+
(int)vsCommandStatus.vsCommandStatusEnabled,