none
Disabling Build menu item in add-in RRS feed

  • Question

  • I have a Visual Studio 2008 extensibility plugin.  Using the plugin's .vsct file, I've
    added a menu item to the Build menu.  I want that menu item to be disabled
    exactly when the Build <projectname> menu items are disabled.

    What's the best way to do this?  It would be great if I could get notification of
    when the other menu items are enabled and disabled. 

    -- Paul
    Thursday, June 4, 2009 7:35 AM

Answers

  • Hi Paul,

    I'm not sure whether the plugin you are working on is created from the Visual Studio Add-in project wizard.

    If so, I think the command you mentioned(Build <projectname>) is "Build.BuildSelection", we could get its status through: DTE.Commands.Item("Build.BuildSelection", 886) .IsAvailable, then we could hide or show our command in the method QueryStatus(), i.e.:

    public void QueryStatus(string commandName, vsCommandStatusTextWanted neededText, ref vsCommandStatus status, ref object commandText)
    {
        if(neededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone)
        {
            if(commandName == "AddinSample.Connect.AddinSample")
            {
                if (_applicationObject.Commands.Item("Build.BuildSelection", 886).IsAvailable)
                {
                    status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
                }
                return;
            }
        }
    }


    Please note, the add-in will need to be loaded when Visual Studio start up, you can specify it at: Tools | Add-in manager...

    If this is not your scenario, you could also use DTE.Commands.Item("Build.BuildSelection", 886) .IsAvailable to determine the menu item's showing.

    About the id "886", we could get it follow this link:
    Using EnableVSIPLogging to identify menus and commands with VS 2005 + SP1

    Sincerely,
    Wesley
    • Edited by Wesley Yao Monday, June 8, 2009 7:37 AM
    • Marked as answer by Wesley Yao Wednesday, June 10, 2009 3:47 AM
    Monday, June 8, 2009 7:19 AM

All replies

  • Hi Paul,

    I'm not sure whether the plugin you are working on is created from the Visual Studio Add-in project wizard.

    If so, I think the command you mentioned(Build <projectname>) is "Build.BuildSelection", we could get its status through: DTE.Commands.Item("Build.BuildSelection", 886) .IsAvailable, then we could hide or show our command in the method QueryStatus(), i.e.:

    public void QueryStatus(string commandName, vsCommandStatusTextWanted neededText, ref vsCommandStatus status, ref object commandText)
    {
        if(neededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone)
        {
            if(commandName == "AddinSample.Connect.AddinSample")
            {
                if (_applicationObject.Commands.Item("Build.BuildSelection", 886).IsAvailable)
                {
                    status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
                }
                return;
            }
        }
    }


    Please note, the add-in will need to be loaded when Visual Studio start up, you can specify it at: Tools | Add-in manager...

    If this is not your scenario, you could also use DTE.Commands.Item("Build.BuildSelection", 886) .IsAvailable to determine the menu item's showing.

    About the id "886", we could get it follow this link:
    Using EnableVSIPLogging to identify menus and commands with VS 2005 + SP1

    Sincerely,
    Wesley
    • Edited by Wesley Yao Monday, June 8, 2009 7:37 AM
    • Marked as answer by Wesley Yao Wednesday, June 10, 2009 3:47 AM
    Monday, June 8, 2009 7:19 AM
  • Spot on, works great!

    886, I should have known! :-)

    -- Paul
    Tuesday, June 9, 2009 2:12 AM