Why isn't my vspackage's context menu showing
Asked Answered
P

4

13

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 explaining how to do it. The problem is, I can't get it work....

Here are my declarations in the vsct file:

  <Button guid="guidDALGeneratorPkgCmdSet" id="cmdidDataFlow" priority="0x0100" type="Button">
    <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_CODEWIN"/>
    <CommandFlag>DynamicVisibility</CommandFlag>
    <Strings>
      <CommandName>cmdidDataFlow</CommandName>
      <ButtonText>Show data flow</ButtonText>
    </Strings>
  </Button>

and the symbols:

<GuidSymbol name="guidDALGeneratorPkgCmdSet" value="{d3269a87-a721-49a5-800b-0464fbdfd313}">

  <IDSymbol name="MyMenuGroup" value="0x1020" />
  <IDSymbol name="cmdidDALGenerator" value="0x0101" />
  <IDSymbol name="cmdidDataFlow" value="0x0102" />
</GuidSymbol>

and here is how I add my menu in my Package class:

CommandID dataFlowCID = new CommandID(GuidList.guidDALGeneratorPkgCmdSet, (int)PkgCmdIDList.cmdidDataFlow);
OleMenuCommand dataFlowMenu = new OleMenuCommand(showDataFlow, dataFlowCID);
dataFlowMenu.BeforeQueryStatus += new EventHandler(dataFlowMenu_BeforeQueryStatus);
mcs.AddCommand(dataFlowMenu);

What am I doing wrong here? I must miss something because nearly every sample (and SO answer on the subject) suggests to add a menu that way in a package.....

What I have tried:

  • make a group first then add my menu in that group: didn't work
  • check if I use the right GUID (with this trick)
  • use IDG_VS_MENU_CONTEXTMENUS instead of IDM_VS_CTXT_CODEWIN (after a look at this post: Using vsx how do you create a sub menu with commands?)
  • give the same parent as the menu that actually works to the second menu, still not showing....
  • a lot of unsuccessful googling about my problem...

Also as you can see I use the BeforeQueryStatus event, but it never gets fired...

Panettone answered 30/5, 2013 at 17:49 Comment(3)
Were you ever able to figure out the solution to your issue. I am facing the same problemFlung
I'm sorry no I didn't... It was a little part of a big project so I found out another way to accomplish what I needed. Did you try what @Marcel suggested?Panettone
Yes, It creates a Button on the context Menu not a Menu on the Context Menu. So it was not helpful. My requirement is to create a Menu on the context Menu.Flung
F
9

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>
Flung answered 12/5, 2015 at 18:35 Comment(0)
D
3

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.

Demers answered 13/3, 2015 at 7:3 Comment(1)
Thanks for your answer! There must have been something else I did wrong then, however I'm not working on this project right now, so I'll check the method sometime later.Panettone
T
0

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://mcmap.net/q/907383/-vsix-adding-a-menu-item-to-the-visual-studio-editor-context-menu

Teodoor answered 19/6, 2017 at 15:57 Comment(0)
B
0

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>
Bemba answered 9/8, 2019 at 9:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.