How to add a listener to the default code editor in Eclipse?(如何在 Eclipse 的默认代码编辑器中添加监听器?)
问题描述
我想在 Eclipse 的默认代码编辑器中添加一个监听器.每当打开或关闭新的代码文件时都应该触发它.有没有类似的东西?我用谷歌搜索了几个小时,但找到了一个可行的解决方案.
I want to add a listener to the default code editor in Eclipse. It should be triggered whenever a new code file is opened or closed. Is there anything available like that? I did a google search for hours, but could find a working solution.
我特别关注默认的 Java 代码编辑器.但是一旦我知道如何连接到这样的编辑器,添加其他编辑器应该不是什么大问题.到目前为止,我遇到的主要问题是,我不知道应该如何处理我可以获得的 IEditorDescriptor.
I'm especially focusing the default Java code editor. But once I know how to hook into such an editor it shouldn't be a big problem to add additional ones. The main problem I have so far is, that I don't know what I should do with the IEditorDescriptor I could get.
推荐答案
可以在PartService中注册一个IPartListener2,例如:
You can register an IPartListener2 with the PartService, for example:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().addPartListener(aListener)
还有其他注册 IPartListener 的方法,例如,如果您有对 IWorkbenchPage
的引用.
There are other ways to register the IPartListener, for example if you have a reference to an IWorkbenchPage
.
当编辑器打开或关闭时,部件侦听器会收到通知.对于 IPartListener2
,您将获得一个 IWorkbenchPartReference
,您可以使用它来检查所涉及的编辑器类型.例如,要检测标准 Java 编辑器,您可以检查 ID org.eclipse.jdt.ui.CompilationUnitEditor
.
The part listener is notified when editors are opened or closed, among other things. For IPartListener2
, you get an IWorkbenchPartReference
which you can use to check what kind of editor is involved. For example, to detect the standard Java editor, you can check for the ID org.eclipse.jdt.ui.CompilationUnitEditor
.
这篇关于如何在 Eclipse 的默认代码编辑器中添加监听器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Eclipse 的默认代码编辑器中添加监听器?
基础教程推荐
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 降序排序:Java Map 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01