-->

获取相关的文件扩展Eclipse编辑器(Get associated file extensions

2019-09-16 09:46发布

我想我(DLTK为主)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;
}    

Answer 1:

你可以得到所有的文件编辑器映射

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

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



文章来源: Get associated file extensions for an Eclipse editor