如何获取在 Eclipse 中的活动 Eclipse 编辑器 window 中打开的文件列表?

How to get the list of files open in active eclipse editor window in eclipse?

兴趣是获取在 Eclipse cdt 编辑器中打开的文件列表。 假设 aaa.c、bbb.c、ddd.c 是在 Eclipse 编辑器中打开的文件。如何获取这些文件的 IFile[]。

您可以使用 IWorkbenchPage getEditorReferences 方法获取所有打开的编辑器的列表。您可以使用它来找到您感兴趣的编辑器。因此:

IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

IEditorReference [] editors = page.getEditorReferences();

for (IEditorReference editor : editors) {
  String editorId = editor.getId();

  // TODO test if this is an editor you are interested in

  IEditorInput inout = editor.getEditorInput();

  IFile file = inout.getAdapter(IFile.class);

  ...
}