蚀行号状态行贡献项目如何实施? [英] How is eclipse line number status line contribution item implemented?

查看:74
本文介绍了蚀行号状态行贡献项目如何实施?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

在此先感谢
AlexG。

Thanks in advance, AlexG.

推荐答案

我一直在研究它,它涉及很多,而且我不确定我是否了解完整的情况,但是如果这对某人有帮助...

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...

以状态栏(以及菜单和工具栏)的内容来绑定编辑器的声明方式是通过 IEditorActionBarContributor 类。此类在plugin.xml中为编辑器类型声明-通常为每种编辑器类型创建一个实例(同一编辑器类型的多个运行实例将共享 IEditorActionBarContributor 例如,在激活时调用其 doSetActiveEditor()方法),并在关闭该类型的最后一个运行的编辑器时将其丢弃。

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.

以一个示例为例,Eclipse中的默认文本编辑器如何更新状态行中的插入/覆盖信息(来自Eclipse 3.7)

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)

默认的文本编辑器在 org.eclipse.ui.editors plugin.xml 中声明(某些行已删节) )为:

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 是关键。在父类中实现了我们感兴趣的内容 BasicTextEditorActionContributor ;它(静态)定义了4个状态字段( STATUS_FIELD_DEFS ),并在内部存储了每个字段的固定映射( fStatusFields ) statusField(规范)到StatusLineContributionItem对象)。从Eclipse UI调用时,它将在方法 contributeToStatusLine(IStatusLineManager statusLineManager)的状态行(基本上是标题)中注册4个字段,并且每次激活编辑器时,它传递给它-在 doSetActiveEditor(IEditorPart part)中-完整的 StatusLineContributionItem s集合,并准备了相应的actionHandlers。编辑器理解所有这一切,因为它实现了 ITextEditorExtension.setStatusField()

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().

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

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

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

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

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.

这是一个示例,但是我想它给出了一个大致的想法: EditorActionContributor 的实例,绑定到编辑器类型,包含要更新的StatusLineContributionItem的列表,并且编辑器必须写入对象当相应状态更改时,此列表中的。这样,编辑器便与状态行分离(它不知道是否/如何在用户界面中显示状态更改)。

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).

这篇关于蚀行号状态行贡献项目如何实施?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆