Search code examples
eclipseeditoreclipse-cdt

Custom CEditor Eclipse CDT not recognized


How can I choose to use my implementation of CEditor instead of built in one?

<extension
  id="highlighter.CustomEditor1"
  point="org.eclipse.ui.editors">
  <editor
     default="true"
     name="CustomCHighlightEditor"
     extensions="c,cusc"
     icon="icons/c_file_obj.gif"
     class="highlighter.CustomEditor"
     contributorClass="org.eclipse.cdt.internal.ui.editor.CEditorActionContributor"
     symbolicFontName="org.eclipse.cdt.ui.editors.textfont"
     id="highlighter.CustomEditorC">
  </editor>

Is not working (no error, no changes). If I open a C file it's still opened with the old editor.

Edit:

When trying to change default editor like in this image:

.c and .cusc editor

It is only recognized for my created cusc extension like you see here:

cusc extension

So there have to be something that prevents to override the file association?

Also ceditor functionallity like folding or such things are missing in both filetypes :-/

EDIT: Works now, had some preference errors


Solution

  • Specializing Content type

    If you want to have your editor opened by default for some specific C files, you need to define your own content types and then associate your editor with that specialized content type.

    For example Ant extends the base xml content type to define an ant specific content type.

    <extension 
            point="org.eclipse.core.contenttype.contentTypes"> 
            <content-type  
                id="antBuildFile" 
                name="%antBuildFileContentType.name" 
                base-type="org.eclipse.core.runtime.xml"
                file-names="build.xml"
                file-extensions="macrodef,ent,xml,ant"
                priority="normal"> 
                <describer 
                    class="org.eclipse.ant.internal.core.contentDescriber.AntBuildfileContentDescriber">
                </describer> 
            </content-type> 
        </extension>
    

    The key thing is that ant files can be .xml files, but something about its content makes it different. Look at AntBuildfileContentDescriber to see how Ant distinguishes a build file from a plain xml file.

    If you then look at the plug-in XML for the ant UI, you will find the editor associated with the specialized content type.

    Changing Default Editors

    If you simply want to change which editor is used by default for a C file and there are multiple editors available, go to Preferences -> General -> Editors -> File Associations and select the file you want (*.c) and change the default editor.