获取Eclipse编辑器的相关文件扩展名 [英] Get associated file extensions for an Eclipse editor

查看:168
本文介绍了获取Eclipse编辑器的相关文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

示例代码:

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


推荐答案

a href =http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/ui/IFileEditorMapping.html = nofollow>文件编辑器映射

You can get all the file editor mappings

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

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

and then select only associated to your editorId.

这篇关于获取Eclipse编辑器的相关文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆