我在静态代码分析器工具中工作。我需要使用我的工具扫描许多项目。在使用工具扫描项目之前,我的要求是检查项目中的所有文件是否都已保存。我知道如何检查单个文件是否保存。我正在使用下面的代码,它运行得很好。
if(window.getActivePage().getActiveEditor().isDirty() == true) {
MessageDialog.openInformation(this.window.getShell(), "Message", "Please save the file before you scan it.");
return false;
} 但是如何检查项目中的所有文件呢?
发布于 2018-05-30 06:05:33
我希望这能帮到你:
IEditorReference[] ref = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage().getEditorReferences();
boolean isDirty = false;
for (IEditorReference iEditorReference : ref) {
if (iEditorReference.isDirty())
isDirty = true;
}发布于 2018-05-30 07:26:19
您可以使用IDE.saveAllEditors对打开的编辑器进行完整检查,使用项目中的文件、确认和保存:
IProject project = .... your project
boolean confirm = ... ask for confirmation flag
boolean canceled = IDE.saveAllEditors(new IResource [] {project}, confirm);IDE是org.eclipse.ui.ide插件中的org.eclipse.ui.ide.IDE,
https://stackoverflow.com/questions/50597333
复制相似问题