Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Addin - 1. How to Add a context menu? 2. How to get caret position

I'm writing a (very) simple Visual Studio addin. Two things that would make it work nicer are:

  1. A context menu.

  2. Knowing the caret position in the current document (so I can inject text at that position).

Any ideas?

like image 624
Giovanni Galbo Avatar asked Feb 28 '23 22:02

Giovanni Galbo


1 Answers

To add a context menu to your addin, you create a CommandBarPopup from:

_applicationObject.CommandBars["Code Window"]

You can view a sample here.

The second part of your question is a little simpler, the current "selection" (or insertion point) is handled by:

(TextSelection)_applicationObject.ActiveDocument.Selection

"_applicationObject" is an instance the DTE Application object created by the add-in project wizard.

like image 169
Jim H. Avatar answered May 03 '23 05:05

Jim H.