Search code examples
visual-studio-2010contextmenumefvspackage

Extending the Visual Studio 2010 editor by adding a context menu item to manipulate selected text


I'd like to create an extension to Visual Studio that will allow someone to select any text in an editor, right-click to get a context menu, and then perform some action on the text by clicking on my custom menu item.

Let's say for example that my custom menu item is called "Email...". The new context menu for the editor might look something like this:

Breakpoint
Run to Cursor
Cut
Copy
Paste
Email...
Outlining

I'd also like to add a popup (adornment?) with options. In this case it could be things like To, Subject, and CC fields.

I think that some of this can be done with MEF using editor extensions, like the popup and the actual code for firing off an email. But it looks like I need a VSPackage to add the context menu item. From what I've read, I can bundle the MEF piece and the VSPackage together.

This is where I get stuck. I need an in-depth reference with details to implement both parts, but I also need information on how to integrate them. MSDN has me going around in circles.

Is there any good, solid example code or documentation (even books) that I can learn from?


Solution

  • I totally scrapped my idea of dealing with MEF, VSIX files, etc. Instead I went with a Visual Studio add-in which was much easier.

    I combined code from various resources like Adding Menu Items to context menus inside the Visual Studio .NET IDE and Visual Studio Add-in : Creating Context Menus which are somewhat old and needed cleaning up, but they worked fine.