Search in sources :

Example 1 with EditorRegistry

use of org.eclipse.ui.internal.registry.EditorRegistry in project n4js by eclipse.

the class N4JSApplicationWorkbenchWindowAdvisor method updateDefaultEditorMappingIfAbsent.

private void updateDefaultEditorMappingIfAbsent() {
    final EditorRegistry registry = (EditorRegistry) WorkbenchPlugin.getDefault().getEditorRegistry();
    for (final IFileEditorMapping editorMapping : registry.getFileEditorMappings()) {
        final IEditorDescriptor defaultEditor = editorMapping.getDefaultEditor();
        if (null == defaultEditor) {
            final String extension = editorMapping.getExtension();
            LOGGER.info("No default editor is associated with files with extension: '." + extension + "'.");
            final IEditorDescriptor defaultTextEditor = registry.findEditor(DEFAULT_TEXT_EDITOR_ID);
            if (null != defaultTextEditor) {
                ((FileEditorMapping) editorMapping).setDefaultEditor(defaultTextEditor);
                String editorName = defaultTextEditor.getLabel();
                if (null == editorName) {
                    editorName = defaultTextEditor.getId();
                }
                if (null != editorName) {
                    LOGGER.info("Associated files with extension " + extension + " with '" + editorName + "'.");
                }
            }
        }
    }
    registry.saveAssociations();
    PrefUtil.savePrefs();
}
Also used : EditorRegistry(org.eclipse.ui.internal.registry.EditorRegistry) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IFileEditorMapping(org.eclipse.ui.IFileEditorMapping) FileEditorMapping(org.eclipse.ui.internal.registry.FileEditorMapping) IFileEditorMapping(org.eclipse.ui.IFileEditorMapping)

Aggregations

IEditorDescriptor (org.eclipse.ui.IEditorDescriptor)1 IFileEditorMapping (org.eclipse.ui.IFileEditorMapping)1 EditorRegistry (org.eclipse.ui.internal.registry.EditorRegistry)1 FileEditorMapping (org.eclipse.ui.internal.registry.FileEditorMapping)1