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 中打开新编辑器时,我如何得到通知?
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
