【问题标题】:How to get the list of files open in active eclipse editor window in eclipse?如何获取在 Eclipse 的活动 Eclipse 编辑器窗口中打开的文件列表?
【发布时间】:2018-10-07 23:26:01
【问题描述】:

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

【问题讨论】:

    标签: eclipse eclipse-plugin eclipse-cdt


    【解决方案1】:

    您可以使用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);
    
      ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-10
      • 2015-04-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多