0

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.

ariana777
  • 53
  • 9
  • @greg-449 Thanks for the reply. I have already added the java editor but i am unable to see java node in preference. – ariana777 Apr 06 '20 at 07:06

1 Answers1

1

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.

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • After adding these i am still seeing only two nodes(Appearance & editors) in editor's preference page :(. Is there any thing i need to specify in plugin.xml? – ariana777 Apr 06 '20 at 07:11
  • No. The ids (these are page ids not classes) must be declared preference pages but that is all – greg-449 Apr 06 '20 at 07:27
  • I am still seeing only two node under general tree node after adding above code. I have tried adding jdt dependencies in plugin also,however its not working :( – ariana777 Apr 06 '20 at 08:20
  • Well is your method being called at all? – greg-449 Apr 06 '20 at 08:54