Tom J Nowell
Tom J Nowell

Reputation: 9981

Visual Studio Addin - Adding a Command to the file->new menu

I have a menu item in the Tools menu, but it needs to go in the file->new menu, however even changing "Tools" to "File" in the pre-generated visual studio code does not give the expected result!!!?

Upvotes: 0

Views: 1046

Answers (3)

Dustin Campbell
Dustin Campbell

Reputation: 9855

The following code (not bulletproof'd!) works fine for me in Addin OnConnection method:

_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
if (connectMode == ext_ConnectMode.ext_cm_UISetup)
{
    object[] contextGUIDS = new object[] { };
    Commands2 commands = (Commands2)_applicationObject.Commands;

    CommandBars commandBars = (CommandBars)_applicationObject.CommandBars;
    CommandBar menuBarCommandBar = commandBars["MenuBar"];

    CommandBarPopup filePopup = menuBarCommandBar.Controls["File"] as CommandBarPopup;
    CommandBarPopup newPopup = filePopup.CommandBar.Controls["New"] as CommandBarPopup;

    Command command = commands.AddNamedCommand2(_addInInstance, "MyAddin1", "MyAddin1", 
        "Executes the command for MyAddin1", true, 59, ref contextGUIDS, 
        (int)(vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled),
        (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

    if (command != null && newPopup != null)
    {
        command.AddControl(newPopup.CommandBar, 1);
    }
}

Upvotes: 1

Dustin Campbell
Dustin Campbell

Reputation: 9855

Have you tried running devenv.exe /resetaddin Your.AddIn.Name at the command line (e.g. devenv.exe /resetaddin MyAddin1.Connect)?

Upvotes: 1

Chathuranga Chandrasekara
Chathuranga Chandrasekara

Reputation: 20906

You need to change the eventlistner code as well. Check the auto generated code segment at the top part of the code.

Upvotes: 1

Related Questions