Why isn't my vspackage's context menu showing

后端 未结 4 411
天命终不由人
天命终不由人 2021-01-11 12:44

I already have a package that I created, and I\'d like to add a menu to the Code Window context menu.

After a little search I found several articles exp

相关标签:
4条回答
  • 2021-01-11 13:20

    For me, the mentioned constant worked. I started out with the standard template for a VSPackage in Visual Studio 2013, then changed the Parent id to IDM_VS_CTXT_CODEWIN.

    Here's what I have now:

    vsct:

      <Button guid="guidCopyForReviewVSPackageCmdSet" id="cmdidCopyForReview" priority="0x0100" type="Button">
        <Parent guid="guidCopyForReviewVSPackageCmdSet" id="MyMenuGroup" />
        <Icon guid="guidImages" id="bmpPicSearch" />
        <Strings>
          <ButtonText>Copy for review (foswiki)</ButtonText>
        </Strings>
      </Button>
    

    the symbols:

    <!-- This is the guid used to group the menu commands together -->
    <GuidSymbol name="guidCopyForReviewVSPackageCmdSet" value="{4ae6ff5a-6e7e-48bd-86b0-37fd9ab20629}">
    
      <IDSymbol name="MyMenuGroup" value="0x1020" />
      <IDSymbol name="cmdidCopyForReview" value="0x0100" />
    </GuidSymbol>
    
    
    <GuidSymbol name="guidImages" value="{3eb1aa0b-96aa-4364-a870-ca588a9491b5}" >
      <IDSymbol name="bmpPic1" value="1" />
      <IDSymbol name="bmpPic2" value="2" />
      <IDSymbol name="bmpPicSearch" value="3" />
      <IDSymbol name="bmpPicX" value="4" />
      <IDSymbol name="bmpPicArrows" value="5" />
      <IDSymbol name="bmpPicStrikethrough" value="6" />
    </GuidSymbol>
    

    Adding the menu item in the package class:

                // Create the command for the menu item.
                CommandID menuCommandID = new CommandID(GuidList.guidCopyForReviewVSPackageCmdSet, (int)PkgCmdIDList.cmdidCopyForReview);
                MenuCommand menuItem = new MenuCommand(MenuItemCallback, menuCommandID );
                mcs.AddCommand( menuItem );
    

    However, this only shows the menu in the "real" code window, not in the aspx/ascx editor for example.

    0 讨论(0)
  • 2021-01-11 13:20

    In my case the problem was that I added the resource file with the 110/112/400 entries manually. When you let the wizards generate everything, then the .resx file is added to the .csproj a bit differently:

    <EmbeddedResource Include="Properties\Resources.resx">
      <!-- Without this line the menu will not appear: -->
      <MergeWithCTO>true</MergeWithCTO>
    </EmbeddedResource>
    
    0 讨论(0)
  • 2021-01-11 13:27

    For the ASPX/ASCX editor use this code:

    Adding the Symbol for the context menu:

    <GuidSymbol name="ASPXContext" value="{D7E8C5E1-BDB8-11D0-9C88-0000F8040A53}">
      <IDSymbol name="menu" value="0x0035"/>
    </GuidSymbol>
    

    Adding the context menu:

    <Group guid="CmdSet" id="contextMenuGroup" priority="0x0100">
      <Parent guid="ASPXContext" id="menu" />
    </Group>
    

    More info at: https://stackoverflow.com/a/31769170/2235860

    0 讨论(0)
  • 2021-01-11 13:35

    A context menu must be added to a group that is on the context menu for it to be displayed ... The syntax for this took me a couple days of trial and error to determine.

    enter image description here

    I created a new VSPackage extension project then updated my VSTS file as follows to create the context menu shown above:

    <Commands package="guidVSPackage2Pkg">
        <Groups>
          <Group guid="guidVSPackage2CmdSet" id="MyMenuGroup" priority="0x0600">
            <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_CODEWIN"/>
          </Group>
    
         <Group guid="guidVSPackage2CmdSet" id="SubMenuGroup" priority="0x0602">
            <Parent guid="guidVSPackage2CmdSet" id="SubMenu" />
          </Group>
        </Groups>
    
        <Menus>
          <Menu guid="guidVSPackage2CmdSet" id="SubMenu" priority="0x0200" type="Menu">
            <Parent guid="guidVSPackage2CmdSet" id="MyMenuGroup" />
            <Strings>
              <ButtonText>Test Context Menu</ButtonText>
            </Strings>
          </Menu>
        </Menus>
    
        <Buttons>
          <Button guid="guidVSPackage2CmdSet" id="cmdidMyCommand" priority="0x0100" type="Button">
            <Parent guid="guidVSPackage2CmdSet" id="SubMenuGroup" />
            <Icon guid="guidImages" id="bmpPic1" />
            <Strings>
              <ButtonText>Context Menu Button</ButtonText>
            </Strings>
          </Button>
          </Buttons>
    
        <Bitmaps>
          <Bitmap guid="guidImages" href="Resources\Images.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows"/>
        </Bitmaps>
      </Commands>
      <Symbols>
        <!-- This is the package guid. -->
        <GuidSymbol name="guidVSPackage2Pkg" value="{1fde2aca-f1c8-4fbc-abd1-58861d8b9520}" />
    
        <!-- This is the guid used to group the menu commands together -->
        <GuidSymbol name="guidVSPackage2CmdSet" value="{9cfc9dda-a054-4ff2-8c85-e6d2bff04874}">
          <IDSymbol name="SubMenu" value="0x1001"/>
          <IDSymbol name="SubMenuGroup" value="0x1000"/>
          <IDSymbol name="MyMenuGroup" value="0x1020" />
          <IDSymbol name="cmdidMyCommand" value="0x0100" />
        </GuidSymbol>
    
        <GuidSymbol name="guidImages" value="{b77d6bb1-566b-4ecb-a99f-9f99325ffd65}" >
          <IDSymbol name="bmpPic1" value="1" />
          <IDSymbol name="bmpPic2" value="2" />
          <IDSymbol name="bmpPicSearch" value="3" />
          <IDSymbol name="bmpPicX" value="4" />
          <IDSymbol name="bmpPicArrows" value="5" />
          <IDSymbol name="bmpPicStrikethrough" value="6" />
        </GuidSymbol>
      </Symbols>
    
    0 讨论(0)
提交回复
热议问题