编写 Visual Studio 2010 插件,想在代码编辑器中显示像 Resharper 这样的工具箱

发布于 2024-08-20 03:21:44 字数 600 浏览 10 评论 0 原文

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

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

我想知道:

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

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

  3. 如何检测是否选择了文本?

我暂时没有其他问题了。我是一名网络开发人员,因此编写 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 :

  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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夕嗳→ 2024-08-27 03:21:44

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

  1. SDK 附带的“编辑器文本装饰”模板是一个很好的起点。一旦你有了这个,看看我为一个假多用户打字演示编写的这个视觉管理器:AgentBadgeVisualManager.cs。这向您展示了如何将某种类型的装饰放置在文本附近(尽管不是直接在文本下方)。您还需要查看 ViewCreationListener.cs文件,其中包含用于视觉管理器的 AdornmentLayerDefinition (最重要的更改是项目模板中的默认值是 Order 属性,以确保您的装饰显示在任何文本之上)。
  2. 我对此一无所知,抱歉:(您会希望这是某种 WPF UIElement,但除此之外,这实际上取决于您。
  3. 来自 ITextView ,您将把它作为示例的一部分实现的 IWpfTextViewCreationListener 的一部分(它被传递给 AgentBadgeVisualManager),您可以订阅SelectionChanged

    view.Selection.SelectionChanged += (sender, args) => /* 调用方法来更新你的装饰 */;

    请注意,当选择为空并跟随插入符号时,该事件不会被触发,因此如果您想跟踪它,您还需要监听插入符号更改事件。但是,如果您只关心 a) 当选择内容非空时,或 b) 当选择内容在空和非空之间变化时,该事件就足够了。

有关可扩展性的更多一般信息,您可以查看我在 github 页面上编写的其他扩展,请阅读关于我如何在我的博客上编写它们,请查看VSX 示例页面,或编辑器Codeplex 上的示例页面

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文