none
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

Answers

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.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/46233873-7384-443e-a754-ef5970a88958/visual-studio-extensibilty?forum=vsx

    Sincerely,


    Ed Dore

    Tuesday, October 6, 2015 10:14 PM
    Moderator
  • 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">
    		<Groups>
    			<Group guid="guidXmlSorterCmdSet" id="MyMenuGroup" priority="0x0600">
    				<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_CODEWIN" />
    			</Group>
    		</Groups>
    
    		<Buttons>
    			<Button guid="guidXmlSorterCmdSet" id="XmlSortCommandId" priority="0x0100" type="Button">
    				<Parent guid="guidXmlSorterCmdSet" id="MyMenuGroup"/>
    				<Strings>
    					<ButtonText>Sort Xml</ButtonText>
    				</Strings>
    			</Button>
    		</Buttons>
    	</Commands>
    	
    	<Symbols>
    		<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" />
    		</GuidSymbol>
    	</Symbols>
    </CommandTable>

    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