locked
Context menus across multiple editor (file?) types RRS feed

  • Question

  • Hi there,

    I'm building an extension and I'm trying (without much luck) to add a context menu item. I have it working for .cs other code windows by putting the command into the IDM_VS_CTXT_CODEWIN group. However, this doesn't work for other file types like .css and .js. I see there are some other questions relating to a similar problem but I'm unable to see a clear solution; I'm not exactly sure what I'm doing regards working with menus and parents, so if someone could help me with this I'd be very grateful.

    I have downloaded the VSCT PowerToy and spent some time trying to find an appropriate parent GUID and ID pair, but whenever I try these in my project it either doesn't do anything, or tells me that the GUID doesn't exist.

    For example, to add my command to the CSS editor context menu I found this pair using VSCT: guidCssGrp and IDM_CTX_SOURCE. But using this in my .vsct file I get the error when building: Undefined 'Parent/@guid' attribute 'guidCssGrp' in a <Group> element

    What I'd really like is a blanket command which just adds my menu item to all editor context menus - does such a thing exist?

    Am I on the right track?

    Many thanks in advance for any help you can give!

    Wednesday, September 15, 2010 12:47 AM

Answers

  • Hi Steve,

     

    Thanks for your post.

    As far as I know, one group can be only specified one parent, that means the best way is to create multiple groups.

    Just as the following

    Groups

        <Groups>

          <Group guid="guidVSPackage1CmdSet" id="MyMenuGroup" priority="0x0600">

            <Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS"/>

          </Group>

          <Group guid="guidVSPackage1CmdSet" id="MyMenuGroupTest" priority="0x0601">

            <Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_FILE"/>

          </Group>

        </Groups>

    Here is the same button in different groups

          <Button guid="guidVSPackage1CmdSet" id="cmdidMyCommand" priority="0x0100" type="Button">

              <Parent guid="guidVSPackage1CmdSet" id="MyMenuGroup" />

            <Icon guid="guidImages" id="bmpPic1" />

            <Strings>

              <CommandName>cmdidMyCommand</CommandName>

              <ButtonText>My Command name</ButtonText>

            </Strings>

          </Button>

              <Button guid="guidVSPackage1CmdSet" id="cmdidMyCommand" priority="0x0100" type="Button">

            <Parent guid="guidVSPackage1CmdSet" id="MyMenuGroupTest" />

            <Icon guid="guidImages" id="bmpPic1" />

            <Strings>

              <CommandName>cmdidMyCommand</CommandName>

              <ButtonText>My Command name</ButtonText>

            </Strings>

          </Button>

    Symbol MyMenuGroupTest should be added here

          <GuidSymbol name="guidVSPackage1CmdSet" value="{0b2ce953-32f7-4186-a746-040a7c18abb5}">

          <IDSymbol name="MyMenuGroup" value="0x1020" />

          <IDSymbol name="MyMenuGroupTest" value="0x1021" />

          <IDSymbol name="cmdidMyCommand" value="0x0100" />

          <IDSymbol name="cmdidMyTool" value="0x0101" />

        </GuidSymbol>

    Hope this can help.

    Best Regards,

    Ziwei Chen

     

    • Marked as answer by Steve Hobbs Friday, September 17, 2010 7:27 AM
    Thursday, September 16, 2010 7:12 AM
  • Hi Steve,

    The easiest way to do this, is to to create a group, add/create your button command to the group, then use the commandplacements section of your .VSCT file to add the group containing your menu command(s) to the desired menus.

    Sincerely,


    Ed Dore
    Friday, September 17, 2010 12:59 AM

All replies

  • Hi Steve,

    There is no such blanket scenario. Some editors may use the same context menu, others may choose to display an entirely different one. The best thing I can recommend in this scenario is to identify each of the context menus you are interested in.

    The easiest way to do this is via the EnableVSIPLogging key described in the following blog. Just be sure to account for the appropriate version number according to the version of VS you're using.

       Using EnableVSIPLogging to identify menus and commands

    Sincerely,


    Ed Dore
    Wednesday, September 15, 2010 4:53 AM
  • Hi Ed,

    Thanks for the reply! I forgot to mention that I had enabled VSIP Logging and I can see the information. It's not the easiest method to use but it will have to do.

    This is going to sound really basic and fundamental, but within the .vsct file, how do I add my command to multiple menus? The basic template you get when you first create a package only adds to one menu - how would I modify the XML markup to place my command under several different context menus? I see I can't add multiple <Parent> elements under a group, so do I have to create multiple groups? Would you be able to give a quick example?

    Many thanks for your help so far!

    Steve

    Wednesday, September 15, 2010 8:47 AM
  • Hi Steve,

     

    Thanks for your post.

    As far as I know, one group can be only specified one parent, that means the best way is to create multiple groups.

    Just as the following

    Groups

        <Groups>

          <Group guid="guidVSPackage1CmdSet" id="MyMenuGroup" priority="0x0600">

            <Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS"/>

          </Group>

          <Group guid="guidVSPackage1CmdSet" id="MyMenuGroupTest" priority="0x0601">

            <Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_FILE"/>

          </Group>

        </Groups>

    Here is the same button in different groups

          <Button guid="guidVSPackage1CmdSet" id="cmdidMyCommand" priority="0x0100" type="Button">

              <Parent guid="guidVSPackage1CmdSet" id="MyMenuGroup" />

            <Icon guid="guidImages" id="bmpPic1" />

            <Strings>

              <CommandName>cmdidMyCommand</CommandName>

              <ButtonText>My Command name</ButtonText>

            </Strings>

          </Button>

              <Button guid="guidVSPackage1CmdSet" id="cmdidMyCommand" priority="0x0100" type="Button">

            <Parent guid="guidVSPackage1CmdSet" id="MyMenuGroupTest" />

            <Icon guid="guidImages" id="bmpPic1" />

            <Strings>

              <CommandName>cmdidMyCommand</CommandName>

              <ButtonText>My Command name</ButtonText>

            </Strings>

          </Button>

    Symbol MyMenuGroupTest should be added here

          <GuidSymbol name="guidVSPackage1CmdSet" value="{0b2ce953-32f7-4186-a746-040a7c18abb5}">

          <IDSymbol name="MyMenuGroup" value="0x1020" />

          <IDSymbol name="MyMenuGroupTest" value="0x1021" />

          <IDSymbol name="cmdidMyCommand" value="0x0100" />

          <IDSymbol name="cmdidMyTool" value="0x0101" />

        </GuidSymbol>

    Hope this can help.

    Best Regards,

    Ziwei Chen

     

    • Marked as answer by Steve Hobbs Friday, September 17, 2010 7:27 AM
    Thursday, September 16, 2010 7:12 AM
  • Hi Steve,

    The easiest way to do this, is to to create a group, add/create your button command to the group, then use the commandplacements section of your .VSCT file to add the group containing your menu command(s) to the desired menus.

    Sincerely,


    Ed Dore
    Friday, September 17, 2010 12:59 AM
  • That's just brilliant guys, thanks so much for your help!
    Friday, September 17, 2010 7:28 AM