I would like to write a plugin for Visual Studio 2010 but in fact I face some problems. What I want to do seems easy, I would like that a little toolbox appears when selecting the text in code editor like in Resharper (little pen with menu that helps in refactoring) or like here:
http://www.axtools.com/products-vs2010-extensions.php?tab=selection-popup
I would like to know :
Is there anu Visual Studio template that helps to start ? I try with "Editor Viewport Adornment" but I'm not sure of that.
Should I desing from start the toolbox or I can show some buttons from system toolbox ? In axtools plugin from the link it's a custom made toolbox or system one ?
How to detect that a text was selected?
I have no more questions for the moment. I'm rather web developer so writing a visual studio plugin it's a new thing for me.
Thanks in advance.
I can answer two parts of that question:
AdornmentLayerDefinition
for the visual manager (the most important thing to change, from the default you get with the project template, is the Order
attribute, to make sure your adornment is displayed on top of any text).UIElement
, but past that it is really up to you.From an ITextView
, which you'll have as a part of the IWpfTextViewCreationListener
implemented as part of the sample (it is passed to the AgentBadgeVisualManager
), you can subscribe to the SelectionChanged event like this:
view.Selection.SelectionChanged += (sender, args) => /* call methods to update your adornment here */;
Note that the event won't be fired when the selection is empty and follows the caret around, so if you want to track that, you'll also need to listen to caret changed events. However, if you just care about a) when the selection is non-empty, or b) when the selection is changing between empty and non-empty, that event will be enough.
For more general information about extensibility, you can check out the other extensions I've written on my github page, read about how I wrote them on my blog, check out the VSX samples page, or the editor samples page on codeplex.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With