Simple example of the highlighted text context menu RRS feed

  • Question

  • I'm not a regular at Visual Studio extensions and am having trouble finding the class\interface names that I need to extend. What I want to do is have a menu item appear in the context menu when code has been selected and the user right clicks. Then when they click on the menu item I add, the extension will do a transformation on the text.

    Would anyone know of a super simple sample that already does similar?

    Saturday, October 3, 2015 12:04 AM


All replies

  • See the Block comment sample command for Visual Commander:

    EnvDTE.TextSelection ts = DTE.ActiveDocument.Selection as EnvDTE.TextSelection;
    ts.Text = "/* " + ts.Text + " */";

    You can add this command to a context menu.

    Sergey Vlasov | Vlasov Studio | Visual Studio add-ins, extensions and tools

    Saturday, October 3, 2015 8:54 AM
  • Also, my previous post from last week details most of what you're looking to do here.


    Ed Dore

    Tuesday, October 6, 2015 10:14 PM
  • I've looked at the post, and I swear I have everything lined up the same. But now menu command is appearing.

    Here's the contents of the vsct, any ideas?

    <!--This is the file that defines the IDs for all the commands exposed by VisualStudio. -->
    	<Extern href="stdidcmd.h" />
    	<!--This header contains the command ids for the menus provided by the shell. -->
    	<Extern href="vsshlids.h" />
    	<Commands package="guidXmlSorterPkg">
    			<Group guid="guidXmlSorterCmdSet" id="MyMenuGroup" priority="0x0600">
    				<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_CODEWIN" />
    			<Button guid="guidXmlSorterCmdSet" id="XmlSortCommandId" priority="0x0100" type="Button">
    				<Parent guid="guidXmlSorterCmdSet" id="MyMenuGroup"/>
    					<ButtonText>Sort Xml</ButtonText>
    		<GuidSymbol name="guidXmlSorterPkg" value="{62e2a72b-df40-4222-9b2d-8160743d1564}" />
    		<GuidSymbol name="guidXmlSorterCmdSet" value="{D1004DFE-C278-4A65-AE08-7AF70B0D5587}">
    			<IDSymbol name="MyMenuGroup" value="0x1020" />
    			<IDSymbol name="XmlSortCommandId" value="0x0100" />

    Thursday, October 15, 2015 4:11 PM
  • I figured out the issue (somewhat). I created the project as a Visual Studio Extension project. Which is very bare bones. But if I create the project as a VSPackage project, it auto creates a lot of what's needed.
    Friday, October 16, 2015 4:08 PM