编写Visual Studio 2010插件,想在代码编辑器中显示像Resharper这样的工具箱 [英] Writing Visual Studio 2010 Plugin, would like to show a toolbox like Resharper in code editor

查看:127
本文介绍了编写Visual Studio 2010插件,想在代码编辑器中显示像Resharper这样的工具箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为Visual Studio 2010写一个插件,但实际上我遇到了一些问题.我想做的事情似乎很简单,我希望在代码编辑器中选择文本时会出现一个小工具箱,如Resharper(带有帮助重构菜单的小笔)或类似以下代码:

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

我想知道:

  1. 是否有可以帮助启动的Visual Studio模板?我尝试使用编辑器视口装饰",但不确定.

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

我应该从启动工具箱开始设计,还是可以从系统工具箱中显示一些按钮?在链接中的axtools插件中,它是一个定制的工具箱或系统工具箱?

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?

我暂时没有其他问题了.我是网络开发人员,所以编写Visual Studio插件对我来说是新事物.

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.

谢谢.

推荐答案

我可以回答该问题的两个部分:

I can answer two parts of that question:

  1. SDK附带的编辑器文本修饰"模板是一个不错的起点.了解这些内容后,请看一下我为虚假的多用户键入演示而编写的视觉管理器: ViewCreationListener.cs 文件,该文件具有可视管理器的AdornmentLayerDefinition(最重要的更改是Order属性,这是从项目模板的默认值更改的最重要的东西,以确保装饰物显示在顶部任何文本).
  2. 对此我一无所知,对不起:(您可能希望将其作为某种WPF UIElement,但是过去确实取决于您.
  3. ITextView中(作为示例的一部分实现的IWpfTextViewCreationListener的一部分)(传递给AgentBadgeVisualManager),您可以订阅 SelectionChanged 事件像这样:

  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 */;

请注意,该事件将不会被当选择为空,并围绕如下插入符号,因此,如果你想跟踪被炒了,你还需要听插入记号改变事件.但是,如果只关心一个)当选择非空,或者b)当选择为空和非空间变化的,该事件将是足够的.

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.

有关可扩展性的更多常规信息,您可以查看我在 github页面上写的其他扩展,了解我如何写它们在我的博客上,请查看

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.

这篇关于编写Visual Studio 2010插件,想在代码编辑器中显示像Resharper这样的工具箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆