Search code examples
eclipseeclipse-plugineclipse-cdt

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


Interest is to get list of opened files in eclipse cdt editor. Lets say aaa.c, bbb.c, ddd.c are the files opened in eclipse editor. How to get the IFile[] for these files.


Solution

  • You can get a list of all open editors using the IWorkbenchPage getEditorReferences method. You can use this to find the editors you are interested in. So:

    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);
    
      ...
    }