Visual Studio Addin - Добавление команды в файл-> новое меню - PullRequest
0 голосов
/ 17 марта 2009

У меня есть пункт меню в меню Инструменты, но он должен перейти в меню Файл-> Новое, однако даже изменение «Инструменты» на «Файл» в предварительно сгенерированном коде Visual Studio не дает ожидаемого результата !!!

Ответы [ 3 ]

1 голос
/ 17 марта 2009

Следующий код (не пуленепробиваемый!) Отлично работает для меня в методе Addin OnConnection:

_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);
    }
}
1 голос
/ 17 марта 2009

Вы пытались запустить devenv.exe / resetaddin Your.AddIn.Name в командной строке (например, devenv.exe / resetaddin MyAddin1.Connect)?

1 голос
/ 17 марта 2009

Вам также необходимо изменить код списка событий. Проверьте автоматически сгенерированный сегмент кода в верхней части кода.

...