eclipse行号状态行贡献项是如何实现的?

发布于 2024-12-13 14:16:15 字数 113 浏览 1 评论 0原文

我需要更新状态行编辑器特定的信息。我已经有了自己的实现,但我想看看 eclipse 贡献项是如何实现的,它显示状态行中的行号/列位置。谁能指点一下,哪里可以找到源代码?

提前致谢, 亚历克斯·G.

I need to update status line editor-specific information. I already have my own implementation, but I would like to take a look how is eclipse contribution item, which shows line number/column position in status line is implemented. Can anyone point me, where could I find the source code?

Thanks in advance,
AlexG.

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

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

发布评论

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

评论(3

蓝眸 2024-12-20 14:16:15

我一直在研究它,它非常复杂,我不确定我是否了解了完整的情况,但以防万一这对某人有帮助......

将编辑器与 StatusLine (以及菜单和工具栏)通过 IEditorActionBarContributor 类。该类是在plugin.xml中为编辑器类型声明的 - 通常为每个编辑器类型创建一个实例(同一编辑器类型的多个运行实例将共享一个IEditorActionBarContributor实例,调用其doSetActiveEditor() 方法(激活时),并且当该类型的最后一个运行的编辑器关闭时它将被释放。

让我们以 Eclipse 中的默认文本编辑器如何更新状态行中的“插入/覆盖”信息为例(从 Eclipse 3.7 开始)

默认文本编辑器在 org.eclipse.ui.editors 中声明的 plugin.xml (修剪了一些行)为:

 <extension point="org.eclipse.ui.editors">
      <editor  name="%Editors.DefaultTextEditor"
            class="org.eclipse.ui.editors.text.TextEditor"
            contributorClass="org.eclipse.ui.editors.text.TextEditorActionContributor"
            id="org.eclipse.ui.DefaultTextEditor">
      </editor>
 </extension>

TextEditorActionContributor 是关键。我们感兴趣的是在父类中实现的 BasicTextEditorActionContributor;它(静态)定义了 4 个状态字段 (STATUS_FIELD_DEFS),并在内部存储每个 statusField(例如规范)到 StatusLineContributionItem 对象的固定映射 (fStatusFields) 。当从 Eclipse UI 调用时,它会在方法 contributeToStatusLine(IStatusLineManager statusLineManager) 中注册状态行中的 4 个字段(基本上是标题),并且每次激活编辑器时,它都会传递给它 -在 doSetActiveEditor(IEditorPart part) 中 - 全套 StatusLineContributionItem,使用相应的 actionHandler 准备。编辑器理解这一切,因为它实现了 ITextEditorExtension.setStatusField()。

对于 AbstractTextEditor 来说,它有一个 ToggleOverwriteModeAction 类型(内部类)的私有字段,它调用

toggleOverwriteMode()->handleInsertModeChanged()->updateStatusField("InputMode")

编辑器查看它是否有 statusField与此类别一起存储,如果是这样,它将调用IStatusField.setText("Insert" / "Overwrite"),这将导致状态行消息的更新。

这是一个示例,但我想它给出了总体思路:绑定到编辑器类型的 EditorActionContributor 实例,维护要更新的 StatusLineContributionItem 列表,并且编辑器必须写入对象当相应的状态发生变化时,该列表的内容将被删除。通过这种方式,编辑器与状态行解耦(它不知道状态更改是否/如何显示在 UI 中)。

I've been looking into it, it's quite involved, and I'm not sure I got the complete picture, but in case this helps someone...

The declarative way of binding an Editor with the contributions to the StatusLine (and Menu and Toolbar) is through IEditorActionBarContributor class. This class is declared for a editor type in plugin.xml - and typically a single instance is created for each editor type (several running instances of a same editor type will share a IEditorActionBarContributor instance, calling its doSetActiveEditor() method when activated), and it will be disposed when when the last running editor of that type is closed.

Lets take as an example how the default text editor in Eclipse updates the "Insert/Override" info in the status line (from Eclipse 3.7)

The default text editor is declared in org.eclipse.ui.editors's plugin.xml (some lines trimmed) as:

 <extension point="org.eclipse.ui.editors">
      <editor  name="%Editors.DefaultTextEditor"
            class="org.eclipse.ui.editors.text.TextEditor"
            contributorClass="org.eclipse.ui.editors.text.TextEditorActionContributor"
            id="org.eclipse.ui.DefaultTextEditor">
      </editor>
 </extension>

TextEditorActionContributor is the key. What interest us is implemented in the parent class BasicTextEditorActionContributor; it defines (statically) the 4 status fields (STATUS_FIELD_DEFS) and it stores internally a fixed map (fStatusFields) of each statusField (the spec, say) to a StatusLineContributionItem object). When called from the Eclipse UI, it registers the 4 fields in the status line (the titles, basically) in the method contributeToStatusLine(IStatusLineManager statusLineManager) And each time a editor is activated, it passes to it -in doSetActiveEditor(IEditorPart part)- the full set of StatusLineContributionItems , prepared with the corresponding actionHandlers. The editor understands all this because it implements ITextEditorExtension.setStatusField().

In the case of AbstractTextEditor, it has an private field of (inner class) type ToggleOverwriteModeAction, which calls

toggleOverwriteMode()->handleInsertModeChanged()->updateStatusField("InputMode")

The editor looks if it has a statusField stored with this category, if so it will call IStatusField.setText("Insert" / "Overwrite") and this will result in the update of the status line message.

This is an example, but I guess it gives the general idea: an instance of EditorActionContributor, binded to a editor type, mantains a list of the StatusLineContributionItem to be updated, and the editor must write into the objects of this list when the corresponding status changes. In this way, the editor is decoupled from the status line (it doesn't know if/how a status change will be displayed in the UI).

深海不蓝 2024-12-20 14:16:15

为了了解 Eclipse 中的某些功能是如何实现的,您还可以使用所谓的插件间谍。插件间谍包含在插件开发环境 (PDE) 中。它是通过ALT+SHIFT+F1执行的。有关更多详细信息,请参阅插件开发常见问题解答

In order to find out how something is implemented in Eclipse, you can also use the so called Plug-in spy. The Plug-in spy is included in the Plug-in Development Environmend (PDE). It is executed with ALT+SHIFT+F1. For further details look this Plug-in development FAQ.

痴骨ら 2024-12-20 14:16:15

我不太确定您要什么,但是这里有 IStatusLineManager 的具体实现:org.eclipse.jface.action.StatusLineManager

通常,如果您愿意要访问状态行并且您有编辑器的句柄,您可以执行类似的操作(借自 org.eclipse.jdt.internal.ui.javaeditor.AddImportOnSelectionAction:

private IStatusLineManager getStatusLineManager() {
    return fEditor.getEditorSite().getActionBars().getStatusLineManager();
}

I'm not exactly sure what you are asking for, but there is a concrete implementation of IStatusLineManager here: org.eclipse.jface.action.StatusLineManager

Typically, if you want to access the status line and you have a handle for an editor, you can do something like this (borrowed from org.eclipse.jdt.internal.ui.javaeditor.AddImportOnSelectionAction:

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