简体   繁体   中英

Save an Eclipse editor programmatically

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?

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.

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

I used -

IDEWorkbenchPlugin.getDefault().getWorkbench().saveAllEditors(true);    

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM