0

This question is already posted in link Java Eclipse plugin Development - Save all project's files programmatically

I was trying with the below code but it is not working/ So I have the query that what entry I would required to add in plugin.xml so that as I use ctrl+s or ctrl+all+ save icon below should start working. Or its better if I got complete example.

import org.eclipse.core.resources.IProject;

@SuppressWarnings("restriction")
public class SaveOpenFilesHandler extends org.eclipse.debug.internal.ui.launchConfigurations.SaveScopeResourcesHandler
{   
       public void showSaveDialog(IProject project)
       {
           super.showSaveDialog(new IProject[] {project}, true, true);
           super.doSave();
       }
}
greg-449
  • 109,219
  • 232
  • 102
  • 145
  • It i not at all clear how the original answer intended this code to be used. It is based on code which only works when launching a program and in any case uses **internal** classes which means it is breaking the [Eclipse API Rules of Engagement](https://www.eclipse.org/articles/Article-API-Use/index.html) – greg-449 Jan 02 '18 at 08:25
  • Is there any other way to do this? – user1413069 Jan 03 '18 at 05:37

2 Answers2

0

The IDE.saveAllEditors method is the closest official API for this:

public boolean saveAllEditors(IResource[] resources, boolean confirm)

Save all dirty editors in the workbench that are open on files that may be affected by this operation. Opens a dialog to prompt the user if confirm is true. Return true if successful. Return false if the user has canceled the command. Must be called from the UI thread.

The simplest call to this is:

IDE.saveAllEditors(new IResource[]{ResourcesPlugin.getWorkspace().getRoot()}, true);

to save everything in the workspace.

IDE is org.eclipse.ui.ide.IDE

greg-449
  • 109,219
  • 232
  • 102
  • 145
0

I have done this with on early start up now it is working fine for me.