1

I need an eclipse plug-in, used to save opened editors. I know that Extended VS Presentation is good, but are there other better plugins?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Judas.n
  • 21
  • 3
  • 3
    I don't understand. Do you ask for a code that saves all currently open editors in eclipse? – Protostome Jul 19 '12 at 11:32
  • Yes, I want to saves all currently open editors in eclipse, convenient for the next open.You have such a plugin?(Thank you for your answer!) – Judas.n Jul 20 '12 at 01:51
  • Possible duplicate of [How can I call save method in eclipse plugin development programmatically](http://stackoverflow.com/questions/5879218/how-can-i-call-save-method-in-eclipse-plugin-development-programmatically) – Rüdiger Herrmann Feb 01 '16 at 13:20
  • I think the OP asked for a plug-in, not for code samples... – SanThee Jul 07 '17 at 07:28

2 Answers2

1

This code should save all open (dirty) editors in 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);
    }
}

In newer versions of eclipse, you can make a small shortcut:

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

Hope that helps ...

Protostome
  • 5,569
  • 5
  • 30
  • 45
  • Thank you very much for Protostome answer, but I won't RCP, but that's ok I'm going to try it. Thank you again. – Judas.n Jul 21 '12 at 01:34
0

You an also save all editors at once ..

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);
    }
}
Yaza
  • 543
  • 3
  • 9