Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't my vspackage's context menu showing

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...

like image 872
ppetrov Avatar asked May 30 '13 17:05

ppetrov


People also ask

Where is the context menu?

A context menu is a pop-up menu that provides shortcuts for actions the software developer anticipates the user might want to take. In a Windows environment, the context menu is accessed with a right mouse click.

Which actions displays the Windows context menu?

In Microsoft Windows, pressing the Application key or Shift+F10 opens a context menu for the region that has focus.


2 Answers

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>
like image 148
Stuart Smith Avatar answered Oct 22 '22 21:10

Stuart Smith


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.

like image 3
Marcel Avatar answered Oct 22 '22 23:10

Marcel