【问题标题】:Eclispe RCP: Is there an extension point that notifies me that an editor is opened?Eclipse RCP:是否有通知我编辑器已打开的扩展点?
【发布时间】:2014-06-03 17:52:48
【问题描述】:

在我的 Eclipse RCP 中打开编辑器时,我可能想根据编辑器的内容再次关闭它。

关闭刚刚打开的编辑器的最佳位置在哪里?是否有某种可用的扩展点,或者有没有办法完全避免打开编辑器?

编辑器本身是通过扩展点org.eclipse.ui.editors添加的。

我试图将自己挂在编辑器的连接方法中,但我没有设法避免打开编辑器。

解决方案:感谢 greg 为我指明了正确的方向!

我的编辑器现在实现了 IPartListener,实现的工作方式如下:

@Override
public void partOpened(IWorkbenchPart part) {
    if (part instanceof MyEditor) {
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditor(this, false);
    }
}

这将在打开编辑器后关闭它。

【问题讨论】:

  • 很高兴您编写了您最终完成的解决方案,但为了提高可读性,请将其写为答案而不是编辑问题。

标签: eclipse-plugin eclipse-rcp


【解决方案1】:

您可以使用IPartListener 监听所有部件的打开、关闭和被激活。

IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();

window.getPartService().addPartListener(partListener);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-05
    • 1970-01-01
    • 2012-12-31
    • 1970-01-01
    • 1970-01-01
    • 2011-01-13
    • 1970-01-01
    相关资源
    最近更新 更多