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 创建 X509 证书? 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 降序排序:Java Map 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01