Imports System
Imports Microsoft.VisualStudio.CommandBars
Imports Extensibility
Imports EnvDTE
Imports EnvDTE80
Public Class Connect
Implements IDTExtensibility2
<%BEGIN VSCommand%>Implements IDTCommandTarget<%END VSCommand%>
Dim _applicationObject As DTE2
Dim _addInInstance As AddIn
'''Implements the constructor for the Add-in object. Place your initialization code within this method.
Public Sub New()
End Sub
'''Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.
'''Root object of the host application.
'''Describes how the Add-in is being loaded.
'''Object representing this Add-in.
'''
Public Sub OnConnection(ByVal application As Object, ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, ByRef custom As Array) Implements IDTExtensibility2.OnConnection
_applicationObject = CType(application, DTE2)
_addInInstance = CType(addInInst, AddIn)
<%BEGIN VSCommand%>If connectMode = ext_ConnectMode.ext_cm_UISetup Then
Dim commands As Commands2 = CType(_applicationObject.Commands, Commands2)
Dim toolsMenuName As String
Try
'If you would like to move the command to a different menu, change the word "Tools" to the
' English version of the menu. This code will take the culture, append on the name of the menu
' then add the command to that menu. You can find a list of all the top-level menus in the file
' CommandBar.resx.
Dim resourceManager As System.Resources.ResourceManager = New System.Resources.ResourceManager("<%=SAFEOBJNAME%>.CommandBar", System.Reflection.Assembly.GetExecutingAssembly())
Dim cultureInfo As System.Globalization.CultureInfo = New System.Globalization.CultureInfo(_applicationObject.LocaleID)
toolsMenuName = resourceManager.GetString(String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools"))
Catch e As Exception
'We tried to find a localized version of the word Tools, but one was not found.
' Default to the en-US word, which may work for the current culture.
toolsMenuName = "Tools"
End Try
'Place the command on the tools menu.
'Find the MenuBar command bar, which is the top-level command bar holding all the main menu items:
Dim commandBars As CommandBars = CType(_applicationObject.CommandBars, CommandBars)
Dim menuBarCommandBar As CommandBar = commandBars.Item("MenuBar")
'Find the Tools command bar on the MenuBar command bar:
Dim toolsControl As CommandBarControl = menuBarCommandBar.Controls.Item(toolsMenuName)
Dim toolsPopup As CommandBarPopup = CType(toolsControl, CommandBarPopup)
Try
'Add a command to the Commands collection:
Dim command As Command = commands.AddNamedCommand2(_addInInstance, "<%=SAFEOBJNAME%>", "<%=SAFEOBJNAME%>", "Executes the command for <%=SAFEOBJNAME%>", True, 59, Nothing, CType(vsCommandStatus.vsCommandStatusSupported, Integer) + CType(vsCommandStatus.vsCommandStatusEnabled, Integer), vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton)
'Find the appropriate command bar on the MenuBar command bar:
command.AddControl(toolsPopup.CommandBar, 1)
Catch argumentException As System.ArgumentException
'If we are here, then the exception is probably because a command with that name
' already exists. If so there is no need to recreate the command and we can
' safely ignore the exception.
End Try
End If<%END VSCommand%>
End Sub
'''Implements the OnDisconnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being unloaded.
'''Describes how the Add-in is being unloaded.
'''Array of parameters that are host application specific.
'''
Public Sub OnDisconnection(ByVal disconnectMode As ext_DisconnectMode, ByRef custom As Array) Implements IDTExtensibility2.OnDisconnection
End Sub
'''Implements the OnAddInsUpdate method of the IDTExtensibility2 interface. Receives notification that the collection of Add-ins has changed.
'''Array of parameters that are host application specific.
'''
Public Sub OnAddInsUpdate(ByRef custom As Array) Implements IDTExtensibility2.OnAddInsUpdate
End Sub
'''Implements the OnStartupComplete method of the IDTExtensibility2 interface. Receives notification that the host application has completed loading.
'''Array of parameters that are host application specific.
'''
Public Sub OnStartupComplete(ByRef custom As Array) Implements IDTExtensibility2.OnStartupComplete
End Sub
'''Implements the OnBeginShutdown method of the IDTExtensibility2 interface. Receives notification that the host application is being unloaded.
'''Array of parameters that are host application specific.
'''
Public Sub OnBeginShutdown(ByRef custom As Array) Implements IDTExtensibility2.OnBeginShutdown
End Sub
<%BEGIN VSCommand%>
'''Implements the QueryStatus method of the IDTCommandTarget interface. This is called when the command's availability is updated
'''The name of the command to determine state for.
'''Text that is needed for the command.
'''The state of the command in the user interface.
'''Text requested by the neededText parameter.
'''
Public Sub QueryStatus(ByVal commandName As String, ByVal neededText As vsCommandStatusTextWanted, ByRef status As vsCommandStatus, ByRef commandText As Object) Implements IDTCommandTarget.QueryStatus
If neededText = vsCommandStatusTextWanted.vsCommandStatusTextWantedNone Then
If commandName = "<%=SAFEOBJNAME%>.Connect.<%=SAFEOBJNAME%>" Then
status = CType(vsCommandStatus.vsCommandStatusEnabled + vsCommandStatus.vsCommandStatusSupported, vsCommandStatus)
Else
status = vsCommandStatus.vsCommandStatusUnsupported
End If
End If
End Sub
'''Implements the Exec method of the IDTCommandTarget interface. This is called when the command is invoked.
'''The name of the command to execute.
'''Describes how the command should be run.
'''Parameters passed from the caller to the command handler.
'''Parameters passed from the command handler to the caller.
'''Informs the caller if the command was handled or not.
'''
Public Sub Exec(ByVal commandName As String, ByVal executeOption As vsCommandExecOption, ByRef varIn As Object, ByRef varOut As Object, ByRef handled As Boolean) Implements IDTCommandTarget.Exec
handled = False
If executeOption = vsCommandExecOption.vsCommandExecOptionDoDefault Then
If commandName = "<%=SAFEOBJNAME%>.Connect.<%=SAFEOBJNAME%>" Then
handled = True
Exit Sub
End If
End If
End Sub<%END VSCommand%>
End Class