【问题标题】:How to save opened editors in eclipse?如何在eclipse中保存打开的编辑器?
【发布时间】:2012-07-19 07:54:38
【问题描述】:

我需要一个eclipse插件,用来保存打开的编辑器。 我知道 Extended VS Presentation 不错,但是还有其他更好的插件吗?

【问题讨论】:

  • 我不明白。您是否要求在 Eclipse 中保存所有当前打开的编辑器的代码?
  • 是的,我想把当前打开的所有编辑器都保存在eclipse中,方便下次打开。你有这样的插件吗?(谢谢你的回答!)
  • 我认为 OP 要求的是插件,而不是代码示例...

标签: eclipse eclipse-plugin


【解决方案1】:

这段代码应该在 eclipse 中保存所有打开(脏)的编辑器:

IEditorReference[] editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
NullProgressMonitor monitor = new NullProgressMonitor();
if ( editorReferences != null ){ 
    for (IEditorReference iEditorReference : editorReferences) {
        IEditorPart editor = iEditorReference.getEditor(false);
        if ( editor.isDirty() )
            editor.doSave(monitor);
    }
}

在较新版本的eclipse中,你可以做一个小捷径:

IEditorPart[] dirtyEditors = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getDirtyEditors();
for (IEditorPart iEditorPart : dirtyEditors) {
    iEditorPart.doSave(monitor);
}

希望对你有帮助……

【讨论】:

  • 非常感谢 Protostome 的回答,但我不会 RCP,但没关系,我会尝试一下。再次感谢您。
【解决方案2】:

您还可以一次保存所有编辑器..

private void doCloseEditors(IWorkbenchPage pActivePage) {
    ArrayList<IEditorReference> openParts = new ArrayList<IEditorReference>();
    for (IEditorReference part : pActivePage.getEditorReferences()) {
        if (part.isDirty()) {
            openParts.add(part);
        }
    }
    if (openParts.size() > 0) {
        pActivePage.closeEditors(openParts.toArray(new IEditorReference[0]), true);
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-08
    • 1970-01-01
    • 2010-11-05
    • 2013-11-18
    相关资源
    最近更新 更多