在進(jìn)行文本編輯器的開發(fā)時(shí)候,經(jīng)常會(huì)遇到對相關(guān)內(nèi)容的提示,可以通過如下代碼實(shí)現(xiàn)SourceViewerConfiguration的
public IContentAssistant getContentAssistant(ISourceViewer sourceViewer)
{
ContentAssistant assistant = new ContentAssistant();
assistant.setContentAssistProcessor (new XMLCompletionProcessor (), XMLPartitionScanner.XML_TAG);
assistant.enableAutoActivation(true);
assistant.setAutoActivationDelay(250);
assistant.setProposalPopupOrientation(IContentAssistant.PROPOSAL_OVERLAY);
assistant.setProposalSelectorBackground(ColorManager.background);
assistant.setProposalSelectorForeground(ColorManager.foreground);
return assistant;
}
其中XMLCompletionProcessor 主要實(shí)現(xiàn)IContentAssistProcessor接口,內(nèi)容輔助主要實(shí)現(xiàn)接口中的
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset)
{
for (int i = 0; i < 5;i++)
{
result[i] = new CompletionProposal("bbb", documentOffset, 0, 3, null,
"aaa",null, "");
}
return result;
}
此時(shí)會(huì)在輔助框中出現(xiàn)5個(gè)aaa,當(dāng)確定后,補(bǔ)充到文本編輯器的相應(yīng)位置是bbb,具體參數(shù)的說明請見API說明。