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
|
|
|
| |
|
| |
| |
| 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.]
|
|
|
| |
|
| |
| | |
|
|
|
|
|