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

后端 未结 1 1806
野趣味
野趣味 2021-02-14 15:52

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 t

1条回答
  •  说谎
    说谎 (楼主)
    2021-02-14 16:40

    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.

    0 讨论(0)
提交回复
热议问题