Wie Inhalt assist Dokumentation Popup in Eclipse RCP implementieren
-
23-08-2019 - |
Frage
Ich habe meine eigenen Editor implementiert und eine Code-Vervollständigung Funktionalität hinzugefügt. Mein Inhalt Assistent wird in der Quelle-Viewer-Konfiguration wie folgt registriert:
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;
}
Wenn ich die Taste Strg + SPACE innerhalb der gewünschten Partition, die Fertigstellung Pop-up angezeigt wird und funktioniert wie erwartet.
Und hier ist meine Frage .. Wie implementiere ich / registrieren eine Dokumentation Popup, das neben Fertigstellung Pop-up angezeigt wird? (Zum Beispiel in Java-Editor)
Lösung
Nun,
Ich werde answear die Frage selbst; -)
Sie haben diese Zeile hinzufügen
assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
oben auf die Konfiguration. Dann, wenn Erstellen CompletionProposals , die achten (letzten) Parameter namens additionalProposalInfo von dem Konstruktor ist der Text, der in der Dokumentation Popup angezeigt wird.
new CompletionProposal(replacementString,
replacementOffset,
replacementLength,
cursorPosition,
image,
displayString,
contextInformation,
additionalProposalInfo);
Weitere Informationen über können hier .
Einfach ist es nicht .. wenn Sie wissen, wie es zu tun;)
Andere Tipps
Für den Stil Informationen (wie in JDT).
HTMLTextPresenter
empfangen.
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>!";
}
}