Eclipse插件开发:如何向编辑器添加功能

发布于 2024-10-20 21:34:04 字数 606 浏览 7 评论 0 原文

最近几天我一直在尝试扩展默认编辑器(java、xml,所有这些)的功能,

我想做的是在每个编辑器的侧面添加一个带有文本的大标尺。

例子: 默认编辑器页面如下所示:

|-----------|
|source     |
|code       |
|           |
|-----------|

但我希望它像这样,

|------|----|
|source|    |
|code  |line|
|      |text|
|------|----|

我也无法使用视图,因为标尺中的文本对应于某一行并且必须与源代码一起滚动。

我尝试通过实现 IEditorActionDelegate 来做到这一点 因为我不想要一个新的编辑器,而是要添加功能,但我找不到任何解决方案。


想要提及的是,为了将我的解决方案付诸实践,我扩展了 AbstractContributedRulerColumn

public class MyRuler extends AbstractContributedRulerColumn {
 ....
}

I have been trying there last days to extend the default editor (java, xml, all of them) functionality,

what I want to do is add a big ruler with text on the side of every editor.

example:
a default editor page looks like this:

|-----------|
|source     |
|code       |
|           |
|-----------|

but i want it to be like this

|------|----|
|source|    |
|code  |line|
|      |text|
|------|----|

also i can't use a view because the text in my ruler corresponds to a certain line and has to scroll along with the source code.

I have tried to do this by implementing IEditorActionDelegate
since I don't want a new editor, but to add functionality, but I could not find any solutions.


Wanted to mention that for putting my solution in practice i extended AbstractContributedRulerColumn

public class MyRuler extends AbstractContributedRulerColumn {
 ....
}

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

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

发布评论

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

评论(3

‖放下 2024-10-27 21:34:04

Arne的回答给出了一些很好的建议,但我仍然花了一段时间才弄清楚如何编写一个添加列的插件编辑器旁边的文本。

发布了一个示例,该示例仅显示带有“x”的行号每行之后。我一路上发现的一些有用的资源是:

Arne's answer gave some good suggestions, but it still took me a while to figure out how to write a plugin that adds a column of text next to the editor.

I published a sample that just displays line numbers with an "x" after each line. Some useful resources I found along the way were:

心奴独伤 2024-10-27 21:34:04

我认为您正在寻找扩展点org.eclipse.ui.workbench.texteditor.rulerColumns。在文本编辑器中显示行号的组件是使用这一点添加的,因此也应该可以添加其他信息。

API 文档中的示例:

<extension
  point="org.eclipse.ui.workbench.texteditor.rulerColumns">
  <column
    id="org.eclipse.ui.editors.columns.linenumbers"
    name="Line Numbers"
    class="org.eclipse.ui.internal.texteditor.LineNumberColumn"
    enabled="false"
    global="true"
    includeInMenu="false">
    <placement
       gravity="0.9">
       <after id="org.eclipse.ui.editors.columns.annotations"/>
    </placement>
    <targetClass
       class="org.eclipse.ui.texteditor.AbstractDecoratedTextEditor">
    </targetClass>
  </column>
</extension>

I think you are after the extension point org.eclipse.ui.workbench.texteditor.rulerColumns. The component that displays the line numbers in text editors is added using this point, so it should be possible to add other information, too.

Example from the API doc:

<extension
  point="org.eclipse.ui.workbench.texteditor.rulerColumns">
  <column
    id="org.eclipse.ui.editors.columns.linenumbers"
    name="Line Numbers"
    class="org.eclipse.ui.internal.texteditor.LineNumberColumn"
    enabled="false"
    global="true"
    includeInMenu="false">
    <placement
       gravity="0.9">
       <after id="org.eclipse.ui.editors.columns.annotations"/>
    </placement>
    <targetClass
       class="org.eclipse.ui.texteditor.AbstractDecoratedTextEditor">
    </targetClass>
  </column>
</extension>
离去的眼神 2024-10-27 21:34:04

使用标尺列扩展点一段时间后,我了解了 org.python.pydev.pydev_pyedit_listener 扩展点,它允许您拦截 PyEdit 创建事件并围绕它包装其他控件。在 SWT 小部件参考 中进行一些挖掘,让我在右侧添加另一个带有拆分器的窗格,并且我发布了一个示例项目。主要优点是您可以选择新显示的显示位置,可以使用您喜欢的任何控件,并且如果显示的文本太多,用户可以滚动。

After working with the ruler columns extension point for a while, I learned about the org.python.pydev.pydev_pyedit_listener extension point that lets you intercept the PyEdit creation event and wrap other controls around it. Some digging in the SWT widget reference let me add another pane on the right with a splitter, and I published a sample project. The main advantages are that you can choose where the new display appears, you can use any controls you like, and the user can scroll if there's too much text to fit in the display.

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