如何在Eclipse中实现内容辅助文档弹出菜单RCP
问题描述:
我已经实现了自己的编辑器并为其添加了代码完成功能。我的内容助理是注册在源代码查看器的配置是这样的:如何在Eclipse中实现内容辅助文档弹出菜单RCP
public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
if (assistant == null) {
assistant = new ContentAssistant();
assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
assistant.setContentAssistProcessor(getMyAssistProcessor(),
MyPartitionScanner.DESIRED_PARTITION_FOR_MY_ASSISTANCE);
assistant.enableAutoActivation(true);
assistant.setAutoActivationDelay(500);
assistant.setProposalPopupOrientation(IContentAssistant.PROPOSAL_OVERLAY);
assistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
}
return assistant;
}
当我按下Ctrl键+ SPACE 的所需的分区里面,完成弹出窗口和按预期工作。
这里是我的问题..我如何实现/注册出现在完成弹出窗口旁边的文档弹出窗口? (例如,在Java编辑器)
答
好,
我answear问题自己;-)
你要加入这一行
assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
上述配置。然后,在创建CompletionProposals时,构造函数的第八个(最后一个)参数additionalProposalInfo是文本,它将显示在文档弹出窗口中。
new CompletionProposal(replacementString,
replacementOffset,
replacementLength,
cursorPosition,
image,
displayString,
contextInformation,
additionalProposalInfo);
有关的更多信息可以发现here。
简单,是不是..如果你知道如何做到这一点;)
答
的DefaultInformationControl实例需要收到
建议可以使用基本的HTML标签字符串中的方法getAdditionalProposalInfo()。
对于风格的信息框(就像在JDT)。
HTMLTextPresenter
。然后import org.eclipse.jface.internal.text.html.HTMLTextPresenter;
public class MyConfiguration extends SourceViewerConfiguration {
[...]
public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
if (assistant == null) {
[...]
assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
}
return assistant;
}
@Override
public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) {
return new IInformationControlCreator() {
public IInformationControl createInformationControl(Shell parent) {
return new DefaultInformationControl(parent,new HTMLTextPresenter(false));
}
};
}
}
public class MyProposal implements ICompletionProposal {
[...]
@Override
public String getAdditionalProposalInfo() {
return "<b>Hello</b> <i>World</i>!";
}
}