[英]How to check whether all files inside a project are saved or not in Eclipse?
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? 但是如何检查项目中的所有文件?
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;
}
You can use IDE.saveAllEditors
to do a complete check for open editors using files in your project, confirmation and save: 您可以使用IDE.saveAllEditors
使用项目中的文件对打开的编辑器进行完整检查,确认并保存:
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, IDE
是org.eclipse.ui.ide.IDE
在org.eclipse.ui.ide
插件,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.