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

相關問題