Visual Studio Addin - дочерние элементы меню не отображаются - PullRequest
0 голосов
/ 08 декабря 2010

Успешно создали элемент верхнего меню, пытается создать первый дочерний элемент, но он не появляется, и не выдается исключение ...

void IDTExtensibility2.OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
    _ApplicationObject = (DTE2)application;
    _AddInInstance = (AddIn)addInInst;

    if (connectMode == ext_ConnectMode.ext_cm_Startup)
    {
        object[] contextGUIDS = new object[] { };
        Commands2 commands = (Commands2)_ApplicationObject.Commands;
        CommandBars commandBars = (CommandBars)_ApplicationObject.CommandBars;
        CommandBar cbMainMenu = commandBars["MenuBar"];

        try
        {
            // ROOT MENU
            CommandBarPopup cbpProjectManagement = (CommandBarPopup)cbMainMenu.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, cbMainMenu.Controls.Count, true);
            cbpProjectManagement.Caption = "ROOTMENU";

            // SUB ITEM
            Command cmdCompiledAssemblies = _ApplicationObject.DTE.Commands.AddNamedCommand(_AddInInstance, "VSPM_CA", "CA", 
                String.Empty, true, 0, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled);

            CommandBarControl cbcCompiledAssemblies = (CommandBarControl)cmdCompiledAssemblies.AddControl(cbpProjectManagement.CommandBar, 1);
        }
        catch (Exception ex)
        {
            System.Windows.Forms.MessageBox.Show(ex.ToString());
        }
    }
}

Ответы [ 2 ]

1 голос
/ 15 декабря 2010

Полная документация о том, как создавать всевозможные меню и панели инструментов здесь ..

http://www.mztools.com/articles/2005/mz2005003.aspx

0 голосов
/ 13 марта 2016

Я знаю, что эта тема действительно старая, но у меня возникла та же проблема, и я наконец нашел решение:

В QueryStatusMethod вы должны проверить свою команду (которую вы создали выше) и вернуть действительный статус,например:

    public void QueryStatus(string commandName, vsCommandStatusTextWanted neededText, ref vsCommandStatus status, ref object commandText)
    {
        if(neededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone)
        {
            if (commandName == "MetatoolVSAddin.Connect.AddInAboutButton")
            {
                status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported|vsCommandStatus.vsCommandStatusEnabled;
                return;
            }
        }
    }
...