Question

I'm trying to programmatically retrieve the associated file extensions for a specific editor from within my (DLTK based) Eclipse plugin. The reason for it is that I only want to index files that are associated to my editor, and I need to avoid hardcoding the extensions as users are able to associate any file extension to the editor via the Eclipse preferences.

Example code:

public boolean isValidPluginFile(ISourceModule sourceModule) {

    // currently: 
    if (sourceModule.getUnderlyingResource().getFileExtension().equals("twig")) {
      return true;
    }
    return false;

    // what i would need instead (pseudocode):

    List extensions = Somehow.Retrieve.AssociatedExtensionsFor('MyEditorID');
    for (String extension : extensions) {
       if (sourceModule.getUnderlyingResource().getFileExtension().equals(extension)) {
         return true;
       }
    }

    return false;
}    
Was it helpful?

Solution

You can get all the file editor mappings

IEditorRegistry editorReg = PlatformUI.getWorkbench().getEditorRegistry();
IFileEditorMapping[] mappings = editorReg.getFileEditorMappings();

and then select only associated to your editorId.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top