How do I get notified whenever a new editor is opened in Eclipse?(每当在 Eclipse 中打开新编辑器时,我如何得到通知?)
问题描述
我有一个视图希望收到所有当前打开的编辑器的通知.我在哪里可以添加监听器来实现这一点?
I have a view which would like to be notified about all the currently opened editors. Where can I add a listener to achieve this?
我希望 WorkbenchPage 或 EditorManager 有一些合适的监听器注册表,但我找不到它.
I was expecting WorkbenchPage or EditorManager to have some appropriate listener registry, but I couldn't find it.
推荐答案
您的视图是否使用 org.eclipse.ui.IPartListener2
?
Does your view uses a org.eclipse.ui.IPartListener2
?
这就是使用这个 EditorListener,其工作是针对给定视图对编辑器事件(包括打开和关闭)做出反应
That is what is using this EditorListener, whose job is to react, for a given view, to Editor events (including open and close)
public class EditorListener implements ISelectionListener, IFileBufferListener,
IPartListener2 {
protected BytecodeOutlineView view;
EditorListener(BytecodeOutlineView view){
this.view = view;
}
[...]
/**
* @see org.eclipse.ui.IPartListener2#partOpened(org.eclipse.ui.IWorkbenchPartReference)
*/
public void partOpened(IWorkbenchPartReference partRef) {
view.handlePartVisible(partRef.getPart(false));
}
<小时>
现在,如果您的 ViewPart
直接实现 IPartListener2
,它可以将自己注册到各种 Editors
,就像这样 BytecodeReferenceView
Now if your ViewPart
directly implements an IPartListener2
, it can register itself to the various Editors
, like this BytecodeReferenceView
public class BytecodeReferenceView extends ViewPart implements IPartListener2, ISelectionListener {
[...]
public void createPartControl(Composite parent) {
browser = new Browser(parent, SWT.BORDER);
browser.setText(BytecodeOutlinePlugin.getResourceString(NLS_PREFIX
+ "empty.selection.text"));
final IWorkbenchWindow workbenchWindow = getSite().getWorkbenchWindow();
workbenchWindow.getPartService().addPartListener(this);
[...]
这篇关于每当在 Eclipse 中打开新编辑器时,我如何得到通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:每当在 Eclipse 中打开新编辑器时,我如何得到通知?


基础教程推荐
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 多个组件的复杂布局 2022-01-01