2012-04-07 16 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

関連する問題