我想为 Visual Studio 2010 编写一个插件,但实际上我遇到了一些问题。我想做的事情似乎很简单,我希望在代码编辑器中选择文本时出现一个小工具箱,例如 Resharper(带有有助于重构的菜单的小笔)或如下所示:
http://www.axtools.com/products-vs2010-extensions.php?tab=selection-popup
我想知道:
-
是否有有助于启动的 Visual Studio 模板?我尝试使用“编辑器视口装饰”,但我不确定。
-
我应该从启动工具箱开始设计还是可以显示系统工具箱中的一些按钮?在链接中的 axtools 插件中,它是一个定制的工具箱或系统工具箱?
-
如何检测是否选择了文本?
我暂时没有其他问题了。我是一名网络开发人员,因此编写 Visual Studio 插件对我来说是一件新鲜事。
提前致谢。
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.
发布评论
评论(1)
我可以回答这个问题的两个部分:
AdornmentLayerDefinition
(最重要的更改是项目模板中的默认值是Order
属性,以确保您的装饰显示在任何文本之上)。UIElement
,但除此之外,这实际上取决于您。来自
ITextView
,您将把它作为示例的一部分实现的IWpfTextViewCreationListener
的一部分(它被传递给AgentBadgeVisualManager
),您可以订阅SelectionChangedview.Selection.SelectionChanged += (sender, args) => /* 调用方法来更新你的装饰 */;
请注意,当选择为空并跟随插入符号时,该事件不会被触发,因此如果您想跟踪它,您还需要监听插入符号更改事件。但是,如果您只关心 a) 当选择内容非空时,或 b) 当选择内容在空和非空之间变化时,该事件就足够了。
有关可扩展性的更多一般信息,您可以查看我在 github 页面上编写的其他扩展,请阅读关于我如何在我的博客上编写它们,请查看VSX 示例页面,或编辑器Codeplex 上的示例页面。
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 theOrder
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 theIWpfTextViewCreationListener
implemented as part of the sample (it is passed to theAgentBadgeVisualManager
), 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.