3

I am developing a plug-in.

On clicking a button, I'd like to call the save method of Eclipse or call the save button on Eclipse toolbar.

What is the way to do it?

Lii
  • 11,553
  • 8
  • 64
  • 88
Abhishek Choudhary
  • 8,255
  • 19
  • 69
  • 128

3 Answers3

5
org.eclipse.ui.PlatformUI.getWorkbench().saveAll(..) 

should do the trick.

If you want to save the active editor, please try

IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editor = page.getActiveEditor();
page.saveEditor(editor, true /* confirm */);

Note that the elements in the navigation path may be null.

Sebastian Zarnekow
  • 6,609
  • 20
  • 23
0

I use this to save dirty editors for one or more projects:

//Save all changes
    Display.getDefault().syncExec(new Runnable() { // save all editors needs to be called by the ui thread!
        @Override
        public void run() {
            IDE.saveAllEditors(new IResource[]{prj}, true);
        }
    });

where prj is an IProject object.

hope this helps

bye

hara
  • 3,274
  • 4
  • 37
  • 55
0

I used -

IDEWorkbenchPlugin.getDefault().getWorkbench().saveAllEditors(true);    
Abhishek Choudhary
  • 8,255
  • 19
  • 69
  • 128
  • Note: that `IDEWorkbenchPlugin` is internal and should not be used. If you don't have access to your window or page, you can fall back on `PlatformUI.getWorkbench()` which is API. – Paul Webster May 04 '11 at 18:13