10

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

http://www.axtools.com/products-vs2010-extensions.php?tab=selection-popup

我想知道 :

  1. 是否有有助于启动的 Visual Studio 模板?我尝试使用“编辑器视口装饰”,但我不确定。

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

  3. 如何检测文本被选中?

我暂时没有更多问题。我是一名网络开发人员,所以编写一个 Visual Studio 插件对我来说是新事物。

提前致谢。

4

1 回答 1

4

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

  1. SDK 附带的“编辑器文本装饰”模板是一个很好的起点。一旦你有了它,看看我为一个小假多用户打字演示写的这个可视化管理器:AgentBadgeVisualManager.cs。这向您展示了如何在文本附近(尽管不是直接在下方)放置某种类型的装饰。您还需要查看ViewCreationListener.cs文件,该文件具有AdornmentLayerDefinition可视化管理器的Order显示任何文本的顶部)。
  2. 我不知道这个,抱歉:(你会希望这是某种 WPF UIElement,但过去这真的取决于你。
  3. ITextView中,您将作为IWpfTextViewCreationListener示例的一部分实现(它被传递给AgentBadgeVisualManager),您可以像这样订阅SelectionChanged事件:

    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.

有关可扩展性的更多一般信息,您可以查看我在github 页面上编写的其他扩展,在我的博客上了解我是如何编写它们的,查看VSX 示例页面codeplex 上的编辑器示例页面

于 2010-02-06T23:01:07.067 回答