Reputation: 17
I am working in static code analyzer tool. I need to scan many projects using my tool. My requirement is to check whether all the files inside my project are saved before i scan the project with my tool. I know how to check whether an individual file is saved or not. I am using the following code and it is working fine.
if(window.getActivePage().getActiveEditor().isDirty() == true) {
MessageDialog.openInformation(this.window.getShell(), "Message", "Please save the file before you scan it.");
return false;
}
But how to check for all files in the project?
Upvotes: 1
Views: 182
Reputation: 917
i hope this will help you:
IEditorReference[] ref = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage().getEditorReferences();
boolean isDirty = false;
for (IEditorReference iEditorReference : ref) {
if (iEditorReference.isDirty())
isDirty = true;
}
Upvotes: 1
Reputation: 111142
You can use IDE.saveAllEditors
to do a complete check for open editors using files in your project, confirmation and save:
IProject project = .... your project
boolean confirm = ... ask for confirmation flag
boolean canceled = IDE.saveAllEditors(new IResource [] {project}, confirm);
IDE
is org.eclipse.ui.ide.IDE
in the org.eclipse.ui.ide
plugin,
Upvotes: 1