eclipse行号状态行贡献项是如何实现的?
我需要更新状态行编辑器特定的信息。我已经有了自己的实现,但我想看看 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我一直在研究它,它非常复杂,我不确定我是否了解了完整的情况,但以防万一这对某人有帮助......
将编辑器与 StatusLine (以及菜单和工具栏)通过 IEditorActionBarContributor 类。该类是在plugin.xml中为编辑器类型声明的 - 通常为每个编辑器类型创建一个实例(同一编辑器类型的多个运行实例将共享一个
IEditorActionBarContributor
实例,调用其doSetActiveEditor()
方法(激活时),并且当该类型的最后一个运行的编辑器关闭时它将被释放。让我们以 Eclipse 中的默认文本编辑器如何更新状态行中的“插入/覆盖”信息为例(从 Eclipse 3.7 开始)
默认文本编辑器在 org.eclipse.ui.editors 中声明的
plugin.xml
(修剪了一些行)为:TextEditorActionContributor
是关键。我们感兴趣的是在父类中实现的 BasicTextEditorActionContributor;它(静态)定义了 4 个状态字段 (STATUS_FIELD_DEFS
),并在内部存储每个 statusField(例如规范)到 StatusLineContributionItem 对象的固定映射 (fStatusFields
) 。当从 Eclipse UI 调用时,它会在方法contributeToStatusLine(IStatusLineManager statusLineManager)
中注册状态行中的 4 个字段(基本上是标题),并且每次激活编辑器时,它都会传递给它 -在doSetActiveEditor(IEditorPart part)
中 - 全套StatusLineContributionItem
,使用相应的 actionHandler 准备。编辑器理解这一切,因为它实现了 ITextEditorExtension.setStatusField()。对于
AbstractTextEditor
来说,它有一个ToggleOverwriteModeAction
类型(内部类)的私有字段,它调用编辑器查看它是否有
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 itsdoSetActiveEditor()
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
'splugin.xml
(some lines trimmed) as: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 methodcontributeToStatusLine(IStatusLineManager statusLineManager)
And each time a editor is activated, it passes to it -indoSetActiveEditor(IEditorPart part)
- the full set ofStatusLineContributionItem
s , prepared with the corresponding actionHandlers. The editor understands all this because it implementsITextEditorExtension.setStatusField()
.In the case of
AbstractTextEditor
, it has an private field of (inner class) typeToggleOverwriteModeAction
, which callsThe editor looks if it has a
statusField
stored with this category, if so it will callIStatusField.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).为了了解 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.
我不太确定您要什么,但是这里有
IStatusLineManager
的具体实现:org.eclipse.jface.action.StatusLineManager
通常,如果您愿意要访问状态行并且您有编辑器的句柄,您可以执行类似的操作(借自 org.eclipse.jdt.internal.ui.javaeditor.AddImportOnSelectionAction:
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
: