locked
Menu in Visual Studio Extension RRS feed

  • Question

  • I have written a visual studio extension and want my menu structure to show up if a certain file type is highlighted in Solution Explorer.  Right now the menu and its sub-menus shows up on the top toollbar.  I have read through several articles and can't seem to figure this out.  Any help or guidance would be appreciated.  Menu structure outlined below:

        <Menus>
          <Menu guid="guidDBCompareCmdSet" id="TopLevelMenu" priority="0x100"
            type="Menu">
            <Parent guid="guidSHLMainMenu" id="IDG_VS_MM_BUILDDEBUGRUN" />
            <Strings>
              <ButtonText>SEKO Scripting</ButtonText>
              <CommandName>Seko Scripting</CommandName>
            </Strings>
          </Menu>

          <!-- New menu added -->
          <Menu guid="guidDBCompareCmdSet" id="RebuildSubMenu" priority="0x200"
            type="Menu">
            <Parent guid="guidDBCompareCmdSet" id="TopLevelMenuGroup" />
            <Strings>
              <ButtonText>RebuildScript</ButtonText>
              <CommandName>Rebuild Script</CommandName>
            </Strings>
          </Menu>

          <Menu guid="guidDBCompareCmdSet" id="SSMSSubMenu" priority="0x200"
            type="Menu">
            <Parent guid="guidDBCompareCmdSet" id="TopLevelMenuGroup" />
            <Strings>
              <ButtonText>OpenInSSMS</ButtonText>
              <CommandName>Open in SSMS</CommandName>
            </Strings>
          </Menu>


        </Menus>

        <Groups>
          <Group guid="guidDBCompareCmdSet" id="TopLevelMenuGroup"
            priority="0x0600">
            <Parent guid="guidDBCompareCmdSet" id="TopLevelMenu"/>
          </Group>
          
          <Group guid="guidDBCompareCmdSet" id="RebuildSubMenuGroup"
            priority="0x0600">
            <Parent guid="guidDBCompareCmdSet" id="RebuildSubMenu"/>
          </Group>

          <Group guid="guidDBCompareCmdSet" id="SSMSSubMenuGroup"
            priority="0x0600">
            <Parent guid="guidDBCompareCmdSet" id="SSMSSubMenu"/>
          </Group>

        </Groups>

        <Buttons>

          <Button guid="guidDBCompareCmdSet" id="cmdidCompareEnv" priority="0x0100"
            type="Button">
            <Parent guid="guidDBCompareCmdSet" id="TopLevelMenuGroup" />
            <Strings>
              <CommandName>cmdidCompareEnv</CommandName>
              <ButtonText>Compare Environments</ButtonText>
            </Strings>
          </Button>

          <Button guid="guidDBCompareCmdSet" id="cmdRebuildFromDevCommand" priority="0x0102"
            type="Button">
            <Parent guid="guidDBCompareCmdSet" id="RebuildSubMenuGroup" />
            <Strings>
              <CommandName>cmdRebuildFromDevCommand</CommandName>
              <ButtonText>Rebuild from DEV</ButtonText>
            </Strings>
          </Button>
          <Button guid="guidDBCompareCmdSet" id="cmdRebuildFromQACommand"
            priority="0x0102" type="Button">
            <Parent guid="guidDBCompareCmdSet" id="RebuildSubMenuGroup" />
            <Strings>
              <CommandName>cmdRebuildFromQACommand</CommandName>
              <ButtonText>Rebuild from QA</ButtonText>
            </Strings>
          </Button>
          <Button guid="guidDBCompareCmdSet" id="cmdRebuildFromStageCommand"
            priority="0x0102" type="Button">
            <Parent guid="guidDBCompareCmdSet" id="RebuildSubMenuGroup" />
            <Strings>
              <CommandName>cmdRebuildFromStageCommand</CommandName>
              <ButtonText>Rebuild from STAGE</ButtonText>
            </Strings>
          </Button>
          <Button guid="guidDBCompareCmdSet" id="cmdRebuildFromProdCommand"
            priority="0x0102" type="Button">
            <Parent guid="guidDBCompareCmdSet" id="RebuildSubMenuGroup" />
            <Strings>
              <CommandName>cmdRebuildFromProdCommand</CommandName>
              <ButtonText>Rebuild from PROD</ButtonText>
            </Strings>
          </Button>

          <Button guid="guidDBCompareCmdSet" id="cmdOpeninSSMSCommandDev" priority="0x0202"
            type="Button">
            <Parent guid="guidDBCompareCmdSet" id="SSMSSubMenuGroup" />
            <Strings>
              <CommandName>cmdOpeninSSMSCommandDev</CommandName>
              <ButtonText>Open in SSMS (DEV)</ButtonText>
            </Strings>
          </Button>

          <Button guid="guidDBCompareCmdSet" id="cmdOpeninSSMSCommandQa" priority="0x0202"
            type="Button">
            <Parent guid="guidDBCompareCmdSet" id="SSMSSubMenuGroup" />
            <Strings>
              <CommandName>cmdOpeninSSMSCommandQa</CommandName>
              <ButtonText>Open in SSMS (QA)</ButtonText>
            </Strings>
          </Button>

          <Button guid="guidDBCompareCmdSet" id="cmdOpeninSSMSCommandStage" priority="0x0202"
            type="Button">
            <Parent guid="guidDBCompareCmdSet" id="SSMSSubMenuGroup" />
            <Strings>
              <CommandName>cmdOpeninSSMSCommandStage</CommandName>
              <ButtonText>Open in SSMS (STAGE)</ButtonText>
            </Strings>
          </Button>

          <Button guid="guidDBCompareCmdSet" id="cmdOpeninSSMSCommandProd" priority="0x0202"
            type="Button">
            <Parent guid="guidDBCompareCmdSet" id="SSMSSubMenuGroup" />
            <Strings>
              <CommandName>cmdOpeninSSMSCommandProd</CommandName>
              <ButtonText>Open in SSMS (PROD)</ButtonText>
            </Strings>
          </Button>

          <!--<Button guid="guidDBCompareCmdSet" id="cmdTenthCommand" priority="0x0202"
            type="Button">
            <Parent guid="guidDBCompareCmdSet" id="SSMSSubMenuGroup" />
            <Strings>
              <CommandName>cmdTenthCommand</CommandName>
              <ButtonText>Tenth Command</ButtonText>
            </Strings>
          </Button>-->

          <Button guid="guidDBCompareCmdSet" id="cmdCleanDirCommand"
            priority="0x0301" type="Button">
            <Parent guid="guidDBCompareCmdSet" id="TopLevelMenuGroup" />
            <Strings>
              <CommandName>cmdCleanDirCommand</CommandName>
              <ButtonText>Clean Compare Dir</ButtonText>
            </Strings>
          </Button>

          <Button guid="guidDBCompareCmdSet" id="cmdCloseWindowCommand"
            priority="0x0301" type="Button">
            <Parent guid="guidDBCompareCmdSet" id="TopLevelMenuGroup" />
            <Strings>
              <CommandName>cmdCloseWindowCommand</CommandName>
              <ButtonText>Close Comparison Windows</ButtonText>
            </Strings>
          </Button>
        </Buttons>
      </Commands>

      <Symbols>
        <!-- This is the package guid. -->
        <GuidSymbol name="guidDBComparePkg"
          value="{bdccf387-aed3-4bab-8b2e-b05a8bbf9fa5}" />

        <!-- This is the command set guid. -->
        <GuidSymbol name="guidDBCompareCmdSet"
          value="{014af398-ca12-4fe9-bc7c-7b56e6836ae6}" >
          
          <IDSymbol name="TopLevelMenu" value="0x0100" />
          <IDSymbol name="TopLevelMenuGroup" value="0x0200" />
          <IDSymbol name="RebuildSubMenuGroup" value="0x0201" />
          <IDSymbol name="SSMSSubMenuGroup" value="0x0202" />
          <IDSymbol name="cmdidCompareEnv" value="0x0300" />
          <IDSymbol name="cmdCleanDirCommand" value="0x0301" />
          <IDSymbol name="cmdRebuildFromDevCommand" value="0x0302" />
          <IDSymbol name="cmdRebuildFromQACommand" value="0x0303" />
          <IDSymbol name="cmdRebuildFromStageCommand" value="0x0304" />
          <IDSymbol name="cmdRebuildFromProdCommand" value="0x0305" />
          <IDSymbol name="cmdOpeninSSMSCommandDev" value="0x0306" />
          <IDSymbol name="cmdOpeninSSMSCommandQa" value="0x0307" />
          <IDSymbol name="cmdOpeninSSMSCommandStage" value="0x0308" />
          <IDSymbol name="cmdOpeninSSMSCommandProd" value="0x0309" />
          <IDSymbol name="cmdCloseWindowCommand" value="0x0310" />
        </GuidSymbol>

        <!-- These are the sub-menus. -->
        <GuidSymbol name="guidDBCompareCmdSet"
          value="{8D7B9CB3-3591-47f9-B104-B7EB173E0F03}" >
          <IDSymbol name="RebuildSubMenu" value="0x0101" />
        </GuidSymbol>

        <GuidSymbol name="guidDBCompareCmdSet"
          value="{8D7B9CB3-3591-47f9-B104-B7EB173E0F03}" >
          <IDSymbol name="SSMSSubMenu" value="0x02101" />
        </GuidSymbol>


    Friday, January 9, 2015 4:00 PM

Answers

All replies

  • Hi mmlachak,

    This thread has provided some code samples to do this, please take a look at it:

    How to get right click context menu on certain file types in Visual Studio Addin

    Or use BeforeQueryStatus event of the command to show or hide the menus you want:

    How to disable and enable menu commands in VSPackage?


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Caillen Tuesday, January 20, 2015 1:55 AM
    Tuesday, January 13, 2015 6:38 AM
  • Thank you so much for the guidance.  I now have my context menus working and able to hide/show them based on a context item selection file type.  Based on this I now have another question. I need to be able to get access to multiple selected items from the context and the Project and solution they belong to.  This is code from an old 2008 addin.

    SelectedItems sis = _applicationObject.SelectedItems;

    Project projSelected = (Project)((Object[])_applicationObject.ActiveSolutionProjects)[0];

    string sCatalogName = projSelected.Name;

    Solution sln = _applicationObject.Solution;

    I need to be able to duplicate this is my package, is this possible?  How do I get access to the _application object? Any help or guidance would be appreciated.

    Tuesday, January 27, 2015 3:44 PM
  • Please in the future open a different thread for a different question.

    About your new question see:

    HOWTO: Get an EnvDTE.DTE instance from a Visual Studio package
    http://www.visualstudioextensibility.com/articles/packages/


    * My new blog about VSX: http://www.visualstudioextensibility.com * Twitter: https://twitter.com/VSExtensibility * MZ-Tools productivity extension for Visual Studio: http://www.mztools.com.

    Tuesday, January 27, 2015 6:04 PM