Multimobile Development: Building Applications for any Smartphone
Is it possible to add nested menu items?
Messages   Related Types
This message was discovered on microsoft.public.vsnet.vsip.


egdif
Can anyone verify whether it is possible to add nested menu items to the
Tools menu using an IDTExtensibility2 based add-in.

Eg. I would like to add the following menu structure to the IDE:

Tools
MenuLevel1
MenuLevel2a
MenuLevel2b

I'm using C# if any sample are available.

Thanks,

Ben

Reply to this message...
Vote that this is a GOOD answer...
 
Really good experience at the Apple Store
MonoDroid – looking *awesome*
 
    
Chetan N Parmar[MSFT]
Hi Ben,
Yes this is possible. Here is what you need to do. Make sure the
IDTCommandTarget interface is implemented by the addin object. This
interface allows you to create named commands. You must implement this
interface to handle new named commands. If you create a default addin this
interface is not implemented for you
The following code would show the menu structure as below
Tools
My Tools >>
Command1
Command2

public void OnConnection(object application, Extensibility.ext_ConnectMode
connectMode, object addInInst, ref System.Array custom)
{
    applicationObject = (_DTE)application;
    addInInstance = (AddIn)addInInst;
    object nullPar = Type.Missing;
    object []contextGUIDS = new object[] { };

    try
    {
    //Create a menu item under Tools menu
        Microsoft.Office.Core.CommandBarPopup popup =
(Microsoft.Office.Core.CommandBarPopup)applicationObject.CommandBars["Tools"
].Controls.Add

(Microsoft.Office.Core.MsoControlType.msoControlPopup, nullPar, nullPar, 2,
nullPar);
        popup.Caption = "My Tools";

        Microsoft.Office.Core.CommandBar pTemp = popup.CommandBar;
//Add commands and then add the commands to
the menu created above
        Command cmd1 = applicationObject.Commands.AddNamedCommand(addInInstance,
"CommandOne", "Command1", "My first Command", true, 59, ref contextGUIDS,
(int)

vsCommandStatus.vsCommandStatusSupported+(int)vsCommandStatus.vsCommandStatu
sEnabled);
        Command cmd2 = applicationObject.Commands.AddNamedCommand(addInInstance,
"CommandTwo", "Command2", "My first Command", true, 59, ref contextGUIDS,
(int)

vsCommandStatus.vsCommandStatusSupported+(int)vsCommandStatus.vsCommandStatu
sEnabled);
        cmd1.AddControl(pTemp,1);
        cmd2.AddControl(pTemp,2);
    }
    catch(Exception e)
    {
        Debug.WriteLine(e.Message);
    }
}

////IDTCommandTarget::QueryStatus
public void QueryStatus(string CmdName, EnvDTE.vsCommandStatusTextWanted
NeededText, ref EnvDTE.vsCommandStatus StatusOption, ref object CommandText)
{
    if(NeededText ==
EnvDTE.vsCommandStatusTextWanted.vsCommandStatusTextWantedNone)
    {
        if(CmdName == "CascadingMenuAddin.Connect.CommandOne" || CmdName ==
"CascadingMenuAddin.Connect.CommandTwo")
        {
            StatusOption =
(vsCommandStatus)vsCommandStatus.vsCommandStatusSupported|vsCommandStatus.vs
CommandStatusEnabled;
        }
    }
}

Thanks
Chetan N Parmar
VSCORE, MSFT

[This posting is provided AS IS with no warranties, and confers no rights.]

Reply to this message...
Vote that this is a GOOD answer...
 
First volume of Multimobile Development nearly ready to go to press
A mention on Developing for the iPhone and Android: The pros and cons
 
    
Ben Fidge
Thanks Chetan,

Your advice has been very helpfull.

Ben

"Chetan N Parmar[MSFT]" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
 
 
EnvDTE.vsCommandStatus
EnvDTE.vsCommandStatusTextWanted
Microsoft.Office.Core.CommandBar
Microsoft.Office.Core.CommandBarPopup
Microsoft.Office.Core.MsoControlType
System.Array
System.Diagnostics.Debug
System.Type




Ad
BootFX
Reliable and powerful .NET application framework.
iOS, Android and Windows Phone Development Training and Consultancy
Hosted by RackSRV Communications
 
Multimobile Development: Building Applications for any Smartphone
Copyright © AMX Software Ltd 2008-2010. Portions copyright © Matthew Baxter-Reynolds 2001-2010. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - 4.0.30129.1734