简体   繁体   English

Eclipse 插件开发 - 自定义编辑器偏好

[英]Eclipse plugin development - customizing editor preference

I'm developing eclipse plugin.我正在开发 eclipse 插件。 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.我想从 Window-->preference 添加更多节点,它显示代码模板、内容辅助等等。 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.我尝试从 AbstractDecoratedTextEditor 覆盖 collectContextMenuPreferencePages 并尝试添加与代码模板相关的扩展,但它没有显示在首选项页面中。

    @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.谢谢你。

That is the correct method to override.这是覆盖的正确方法。

This is what the Java editor does:这就是 Java 编辑器所做的:

@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.当然,所有这些 id 必须以通常的方式使用org.eclipse.ui.preferencePages扩展点声明。

The first page in the array is the one selected when the preferences are shown.数组中的第一页是显示首选项时选择的页。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM