2012-04-07 119 views
0

我试图以编程方式从我的(基于DLTK的)Eclipse插件中检索特定编辑器的关联文件扩展名。原因是我只想索引与我的编辑器关联的文件,并且我需要避免对扩展进行硬编码,因为用户可以通过Eclipse首选项将任何文件扩展名关联到编辑器。获取关联的文件扩展名为Eclipse编辑器

示例代码:

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

回答

2

你可以得到所有的file editor mappings

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

,然后选择只关联到您的editorId。

+0

完美的作品,谢谢。 – pulse00 2012-04-07 09:03:09

相关问题