Writing Visual Studio 2010 Plugin, would like to show a toolbox like Resharper in code editor

三世轮回 提交于 2019-12-04 18:21:18

问题


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 :

  1. Is there anu Visual Studio template that helps to start ? I try with "Editor Viewport Adornment" but I'm not sure of that.

  2. 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 ?

  3. 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.


回答1:


I can answer two parts of that question:

  1. The "Editor Text Adornment" template that ships with the SDK is a good place to start. Once you have that, take a look at this visual manager I wrote for a little fake-multiple-users-typing demo: AgentBadgeVisualManager.cs. That shows you how to place some type of adornment near (though not directly underneath) text. You'll also want to take a look at the ViewCreationListener.cs file, which has the 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).
  2. I have no idea for this one, sorry :( You'll want this to be some kind of WPF UIElement, but past that it is really up to you.
  3. 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.



来源:https://stackoverflow.com/questions/2213103/writing-visual-studio-2010-plugin-would-like-to-show-a-toolbox-like-resharper-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!