Eclipse plugin development - customizing editor preference

180 Views Asked by At

I'm developing eclipse plugin. When right clicking and chose 'preferences' in my editor plugin it shows two trees 'Appearance' & 'Editors'under 'General'. I want to add few more nodes from Window-->preference which shows code templates, content assist and many more. How can i do that? I have tried overriding collectContextMenuPreferencePages from AbstractDecoratedTextEditor and try to add extension which are related to code templates, however its not showing in preference page.

    @Override
     protected String[] collectContextMenuPreferencePages() {
    return new String[] { "org.eclipse.ui.preferencePages.GeneralTextEditor", //$NON-NLS-1$
            "org.eclipse.ui.editors.preferencePages.Annotations", //$NON-NLS-1$
            "org.eclipse.ui.editors.preferencePages.QuickDiff", //$NON-NLS-1$
            "org.eclipse.ui.editors.preferencePages.Accessibility", //$NON-NLS-1$
            "org.eclipse.ui.editors.preferencePages.Spelling", //$NON-NLS-1$
            "org.eclipse.ui.editors.preferencePages.LinkedModePreferencePage", //$NON-NLS-1$
            "org.eclipse.ui.preferencePages.ColorsAndFonts", //$NON-NLS-1$
            "org.eclipse.ui.editors.templates",
    };
}

How can i add General node which is present in window-->preference to editor preference? Thank you.

1

There are 1 best solutions below

4
On BEST ANSWER

That is the correct method to override.

This is what the Java editor does:

@Override
protected String[] collectContextMenuPreferencePages() {
    String[] inheritedPages= super.collectContextMenuPreferencePages();
    int length= 10;
    String[] result= new String[inheritedPages.length + length];
    result[0]= "org.eclipse.jdt.ui.preferences.JavaEditorPreferencePage"; 
    result[1]= "org.eclipse.jdt.ui.preferences.JavaTemplatePreferencePage"; 
    result[2]= "org.eclipse.jdt.ui.preferences.CodeAssistPreferencePage"; 
    result[3]= "org.eclipse.jdt.ui.preferences.CodeAssistPreferenceAdvanced"; 
    result[4]= "org.eclipse.jdt.ui.preferences.JavaEditorHoverPreferencePage"; 
    result[5]= "org.eclipse.jdt.ui.preferences.JavaEditorColoringPreferencePage"; 
    result[6]= "org.eclipse.jdt.ui.preferences.FoldingPreferencePage"; 
    result[7]= "org.eclipse.jdt.ui.preferences.MarkOccurrencesPreferencePage";
    result[8]= "org.eclipse.jdt.ui.preferences.SmartTypingPreferencePage";
    result[9]= "org.eclipse.jdt.ui.preferences.SaveParticipantPreferencePage";
    System.arraycopy(inheritedPages, 0, result, length, inheritedPages.length);
    return result;
}

Of course all these ids must be declared using the org.eclipse.ui.preferencePages extension point in the usual way.

The first page in the array is the one selected when the preferences are shown.