EnvDTE.AddNameCommand will not make command available
-
Thursday, April 26, 2012 7:37 PM
This is a VB 10 addin
I can create two popup commands for the "Code Window".
Everything works fine, but when I add the third command
it is returning IsAvailable = false
Dim ocmd As Command
ocmd = m_dte.Commands.AddNamedCommand(AddInInstance:=m_addIn, Name:=m_NAME_AddFunctionDescription_WithTask, ButtonText:="Create Method Header", Tooltip:="Create Method Header", MSOButton:=True, Bitmap:=59)
ocmd = m_dte.Commands.AddNamedCommand(AddInInstance:=m_addIn, Name:=m_NAME_CreateDefaultRegions, ButtonText:="CreateDefaultRegions", Tooltip:="CreateDefaultRegions", MSOButton:=True, Bitmap:=59)
ocmd = m_dte.Commands.AddNamedCommand(AddInInstance:=m_addIn, Name:=m_NAME_InsertUifUtilities2008NameSpaces, ButtonText:="Insert", Tooltip:="Insert", MSOButton:=True, Bitmap:=59)If I change the order, change their names, makes no difference.
I can only get the first two to show up in "Code Window"
I tried setting the vsCommandDisabledFlagsValue to 3,16 does not work
Thanks
All Replies
-
Friday, April 27, 2012 3:20 PMModerator
Do you have a complete repro? The above snippet leaves out info, like what the various m_NAME_XXX things are defined as, what you mean by 'I tried setting the vsCommandDisabledFlagsValue to 3,16' (What is 3,16?)
Ryan
-
Friday, April 27, 2012 3:56 PM
Here it is:
As I said before, I can two popups to show in test project code window
but not a 3rd on
The 3 and 16 were arguments that I was passing to AddNamedCommand for the parameter vsCommandDisableFlagsValue
I did this because in the CreateCommands method, the third addnamedCommand was returning a Command object that is always has a value of IsAvailable = false. The first 2 have IsAvailable = true. That is why I think the third popup will not show
Thanks very much in advance for looking at this
Imports System
Imports Microsoft.VisualStudio.CommandBars
Imports Extensibility
Imports EnvDTE
Imports EnvDTE80Public Class Connect
Implements IDTExtensibility2
Implements IDTCommandTarget
Public Sub New()End Sub
Private Const m_NAME_AddFunctionDescription_WithTask As String = "greghelper_AddFunctionDescription_WithTask"
Private Const m_NAME_CreateDefaultRegions As String = "greghelper_CreateDefaultRegions"
Private Const m_NAME_InsertUifUtilities2008NameSpaces As String = "greghelper_Insert"Private m_dte As EnvDTE.DTE
Private m_addIn As EnvDTE.AddInPrivate m_commandBarPopup As CommandBarPopup
Private m_commandBarControl_AddFunctionDescription_WithTask As CommandBarControl
Private m_commandBarControl_CreateDefaultRegions As CommandBarControl
Private m_commandBarControl_InsertUifUtilities2008NameSpaces As CommandBarControlPrivate Sub CreateCommands()
' ======================================================================
' Sub CreateCommands -
' ----------------------------------------------------------------------
' Arguments:
'
' Returns: Private
'
' TaskItem Method Name Programmer Date Reason
' CodeChange - FirstAddIn Sub CreateCommands [0] ouhilsheimer 4/26/2012 Initial Coding
' ======================================================================
Dim ocmd As Command
ocmd = m_dte.Commands.AddNamedCommand(AddInInstance:=m_addIn, Name:=m_NAME_AddFunctionDescription_WithTask, ButtonText:="Create Method Header", Tooltip:="Create Method Header", MSOButton:=True, Bitmap:=59)
ocmd = m_dte.Commands.AddNamedCommand(AddInInstance:=m_addIn, Name:=m_NAME_CreateDefaultRegions, ButtonText:="CreateDefaultRegions", Tooltip:="CreateDefaultRegions", MSOButton:=True, Bitmap:=59)
ocmd = m_dte.Commands.AddNamedCommand(AddInInstance:=m_addIn, Name:=m_NAME_InsertUifUtilities2008NameSpaces, ButtonText:="Insert", Tooltip:="Insert", MSOButton:=True, Bitmap:=59)
End SubPrivate Sub InitializeAddIn()
' ======================================================================
' Sub InitializeAddIn -
' ----------------------------------------------------------------------
' Arguments:
'
' Returns: Private
'
' TaskItem Method Name Programmer Date Reason
' CodeChange - FirstAddIn Sub InitializeAddIn [0] ouhilsheimer 4/26/2012 Initial Coding
' ======================================================================Dim myCommandBarControl As CommandBarControl
Dim codeWindowCommandBar As CommandBar
Dim ocmd_AddFunctionDescription_WithTask As Command
Dim ocmd_CreateDefaultRegions As Command
Dim ocmd_InsertUifUtilities2008NameSpaces As Command
Dim commandBars As CommandBars' Retrieve commands created in the ext_cm_UISetup phase of the OnConnection method
ocmd_AddFunctionDescription_WithTask = m_dte.Commands.Item(m_addIn.ProgID & "." & m_NAME_AddFunctionDescription_WithTask)
ocmd_CreateDefaultRegions = m_dte.Commands.Item(m_addIn.ProgID & "." & m_NAME_CreateDefaultRegions)
ocmd_InsertUifUtilities2008NameSpaces = m_dte.Commands.Item(m_addIn.ProgID & "." & m_NAME_InsertUifUtilities2008NameSpaces)
ocmd_InsertUifUtilities2008NameSpaces = m_dte.Commands.Item(m_addIn.ProgID & "." & m_NAME_InsertUifUtilities2008NameSpaces)' Retrieve the context menu of code windows
commandBars = CType(m_dte.CommandBars, CommandBars)
'SEE VisualStudio10-CommandBars.txt in this project for a list of all CommandBars
codeWindowCommandBar = commandBars.Item("Code Window")' Add a popup command bar
myCommandBarControl = codeWindowCommandBar.Controls.Add( _
MsoControlType.msoControlPopup, System.Type.Missing, _
System.Type.Missing, System.Type.Missing, System.Type.Missing)m_commandBarPopup = DirectCast(myCommandBarControl, CommandBarPopup)
' Change its caption
m_commandBarPopup.Caption = "Gregs Add-In Helpers"' Add controls to the popup command bar
m_commandBarControl_AddFunctionDescription_WithTask = CType(ocmd_AddFunctionDescription_WithTask.AddControl(m_commandBarPopup.CommandBar), CommandBarControl)
m_commandBarControl_CreateDefaultRegions = CType(ocmd_CreateDefaultRegions.AddControl(m_commandBarPopup.CommandBar), CommandBarControl)
m_commandBarControl_InsertUifUtilities2008NameSpaces = CType(ocmd_InsertUifUtilities2008NameSpaces.AddControl(m_commandBarPopup.CommandBar), CommandBarControl)
m_commandBarControl_InsertUifUtilities2008NameSpaces.Enabled = True
End SubPublic Sub OnConnection(ByVal application As Object, ByVal connectMode As Extensibility.ext_ConnectMode, _
ByVal addInInst As Object, ByRef custom As System.Array) _
Implements Extensibility.IDTExtensibility2.OnConnection
' ======================================================================
' Sub OnConnection -
' ----------------------------------------------------------------------
' Arguments:
' ByVal application As Object
' ByVal connectMode As Extensibility.ext_ConnectMode
' ByVal addInInst As Object
' ByRef custom As System.Array
'
' Returns: Public
'
' TaskItem Method Name Programmer Date Reason
' CodeChange - FirstAddIn Sub OnConnection [0] ouhilsheimer 4/26/2012 Initial Coding
' ======================================================================Try
m_dte = CType(application, EnvDTE.DTE)
m_addIn = CType(addInInst, EnvDTE.AddIn)Select Case connectMode
Case ext_ConnectMode.ext_cm_UISetup
' Create commands in the UI Setup phase. This phase is called only once when the add-in is deployed.
CreateCommands()Case ext_ConnectMode.ext_cm_Startup
' Do nothing yet, wait until the IDE is fully initialized (OnStartupComplete will be called)
Case ext_ConnectMode.ext_cm_AfterStartup
'InitializeAddIn()
End Select
Catch objException As Exception
MessageBox.Show(objException.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End TryEnd Sub
Public Sub OnStartupComplete(ByRef custom As System.Array) _
Implements Extensibility.IDTExtensibility2.OnStartupComplete
InitializeAddIn()End Sub
Public Sub Exec(ByVal CmdName As String, ByVal ExecuteOption As EnvDTE.vsCommandExecOption, _
ByRef VariantIn As Object, ByRef VariantOut As Object, ByRef handled As Boolean) _
Implements EnvDTE.IDTCommandTarget.Exec
' ======================================================================
' Sub Exec -
' ----------------------------------------------------------------------
' Arguments:
' ByVal CmdName As String
' ByVal ExecuteOption As EnvDTE.vsCommandExecOption
' ByRef VariantIn As Object
' ByRef VariantOut As Object
' ByRef handled As Boolean
'
' Returns: Public
'
' TaskItem Method Name Programmer Date Reason
' CodeChange - FirstAddIn Sub Exec [0] ouhilsheimer 4/26/2012 Initial Coding
' ======================================================================
MsgBox(CmdName)
Select Case CmdNameCase m_addIn.ProgID & "." & m_NAME_AddFunctionDescription_WithTask
Case m_addIn.ProgID & "." & m_NAME_CreateDefaultRegions
Case m_addIn.ProgID & "." & m_NAME_InsertUifUtilities2008NameSpaces
End SelectEnd Sub
Public Sub OnConnection(ByVal application As Object, ByVal connectMode As Extensibility.ext_ConnectMode, _
ByVal addInInst As Object, ByRef custom As System.Array) _
Implements Extensibility.IDTExtensibility2.OnConnection
' ======================================================================
' Sub OnConnection -
' ----------------------------------------------------------------------
' Arguments:
' ByVal application As Object
' ByVal connectMode As Extensibility.ext_ConnectMode
' ByVal addInInst As Object
' ByRef custom As System.Array
'
' Returns: Public
'
' TaskItem Method Name Programmer Date Reason
' CodeChange - FirstAddIn Sub OnConnection [0] ouhilsheimer 4/26/2012 Initial Coding
' ======================================================================Try
m_dte = CType(application, EnvDTE.DTE)
m_addIn = CType(addInInst, EnvDTE.AddIn)Select Case connectMode
Case ext_ConnectMode.ext_cm_UISetup
' Create commands in the UI Setup phase. This phase is called only once when the add-in is deployed.
CreateCommands()Case ext_ConnectMode.ext_cm_Startup
' Do nothing yet, wait until the IDE is fully initialized (OnStartupComplete will be called)
Case ext_ConnectMode.ext_cm_AfterStartup
'InitializeAddIn()
End Select
Catch objException As Exception
MessageBox.Show(objException.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End TryEnd Sub
Public Sub OnStartupComplete(ByRef custom As System.Array) _
Implements Extensibility.IDTExtensibility2.OnStartupComplete
InitializeAddIn()End Sub
Public Sub OnDisconnection(ByVal RemoveMode As Extensibility.ext_DisconnectMode, ByRef custom As System.Array) _
Implements Extensibility.IDTExtensibility2.OnDisconnectionTry
If Not (m_commandBarPopup Is Nothing) Then
m_commandBarPopup.Delete()
End IfCatch objException As Exception
MessageBox.Show(objException.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End TryEnd Sub
Public Sub OnBeginShutdown(ByRef custom As System.Array) _
Implements Extensibility.IDTExtensibility2.OnBeginShutdownEnd Sub
Public Sub OnAddInsUpdate(ByRef custom As System.Array) _
Implements Extensibility.IDTExtensibility2.OnAddInsUpdateEnd Sub
Public Sub QueryStatus(ByVal CmdName As String, _
ByVal NeededText As EnvDTE.vsCommandStatusTextWanted, _
ByRef StatusOption As EnvDTE.vsCommandStatus, ByRef CommandText As Object) _
Implements EnvDTE.IDTCommandTarget.QueryStatusSelect Case CmdName
Case m_addIn.ProgID & "." & m_NAME_AddFunctionDescription_WithTask
StatusOption = vsCommandStatus.vsCommandStatusSupported Or _
vsCommandStatus.vsCommandStatusEnabledCase m_addIn.ProgID & "." & m_NAME_CreateDefaultRegions
StatusOption = vsCommandStatus.vsCommandStatusSupported Or _
vsCommandStatus.vsCommandStatusEnabledEnd Select
End Sub
End Class
-
Friday, April 27, 2012 6:07 PMModerator
Is it InsertUifUtilities2008NameSpaces that is not showing up? Your QueryStatus method does not handle that command, you need a case for that command and you need to set it to supported and enabled.
Ryan
- Marked As Answer by Ryan MoldenMicrosoft Employee, Moderator Sunday, April 29, 2012 4:21 PM
-
Friday, April 27, 2012 7:59 PM
Well I certainly was asleep not seeing that
Thanks a lot
-
Friday, April 27, 2012 10:10 PMModerator
So that fixed it up? I haven't looked at the code under a debugger, just noticed that as I was scrolling through looking for common oversights before digging in under a debugger.
Ryan
-
Sunday, April 29, 2012 2:41 PM
sure did
thanks much

