Eclipse插件开发 – 自定义编辑器首选项

huangapple go评论90阅读模式
英文:

Eclipse plugin development - customizing editor preference

问题

我正在开发 Eclipse 插件。当在我的编辑器插件中右键单击并选择“首选项”时,它会在“常规”下显示两个树,“外观”和“编辑器”。我想从“窗口”->“首选项”中添加更多节点,显示代码模板、内容辅助等等。我该如何做到这一点?
我尝试重写 AbstractDecoratedTextEditor 中的 collectContextMenuPreferencePages 方法,并尝试添加与代码模板相关的扩展,但是在首选项页面中没有显示出来。

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

我如何将出现在“窗口”->“首选项”中的“常规”节点添加到编辑器首选项中?谢谢。

英文:

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

得分: 1

以下是翻译好的内容:

这是正确的覆盖方法。

这是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;
}

当然,所有这些 ID 必须按照通常的方式使用 org.eclipse.ui.preferencePages 扩展点声明。

数组中的第一个页面是在显示首选项时选择的页面。

英文:

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.

huangapple
  • 本文由 发表于 2020年4月6日 14:31:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/61054141.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定