繁体   English   中英

如何检查项目中的所有文件是否在Eclipse中保存?

[英]How to check whether all files inside a project are saved or not in Eclipse?

我正在使用静态代码分析器工具。 我需要使用我的工具扫描许多项目。 我的要求是在使用工具扫描项目之前,检查项目中所有文件是否都已保存。 我知道如何检查单个文件是否已保存。 我正在使用以下代码,它工作正常。

if(window.getActivePage().getActiveEditor().isDirty() == true) {
     MessageDialog.openInformation(this.window.getShell(), "Message", "Please save the file before you scan it.");
     return false;
} 

但是如何检查项目中的所有文件?

我希望这能帮到您:

    IEditorReference[] ref = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
    .getActivePage().getEditorReferences();
    boolean isDirty = false;
    for (IEditorReference iEditorReference : ref) {
        if (iEditorReference.isDirty())
            isDirty = true;
    }

您可以使用IDE.saveAllEditors使用项目中的文件对打开的编辑器进行完整检查,确认并保存:

IProject project = .... your project

boolean confirm = ... ask for confirmation flag

boolean canceled = IDE.saveAllEditors(new IResource [] {project}, confirm);

IDEorg.eclipse.ui.ide.IDEorg.eclipse.ui.ide插件,

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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