2009-05-20 10 views
3

Ich habe meinen eigenen Editor implementiert und eine Code-Vervollständigungsfunktion hinzugefügt. Mein Inhalt Assistent wird in der Quelle-Viewer-Konfiguration wie folgt registriert:Wie Sie das Dokumentations-Popup von content assist in Eclipse RCP implementieren

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 Ctrl +SPACE innerhalb der gewünschten Partition drücken, die Fertigstellung Pop-up angezeigt wird, und wie erwartet funktioniert.

Und hier ist meine Frage .. Wie implementiere/registriere ich ein Dokumentations-Popup, das neben dem Fertigstellungs-Popup erscheint? (Zum Beispiel in Java-Editor)

Antwort

3

Nun,

Ich werde die Frage mich answear ;-)

Sie haben diese Zeile über

assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer)); 

zur Konfiguration hinzuzufügen. Beim Erstellen der CompletionProposals ist der achte (letzte) Parameter additionalProposalInfo des Konstruktors der Text, der im Dokumentations-Popup angezeigt wird.

new CompletionProposal(replacementString, 
          replacementOffset, 
          replacementLength, 
          cursorPosition, 
          image, 
          displayString, 
          contextInformation, 
          additionalProposalInfo); 

Weitere Informationen finden Sie unter here.

Einfach ist es nicht .. wenn Sie wissen, wie es zu tun;)

3

Für den Stil Informationen (wie in JDT).

Styled additionnal information


  • Die DefaultInformationControl Instanz muss eine HTMLTextPresenter erhalten.
  • 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)); 
          } 
         }; 
        } 
    } 
    

  • Vorschläge dann getAdditionalProposalInfo() grundlegende HTML-Tags in der Zeichenfolge von Verfahren verwenden können.
  • public class MyProposal implements ICompletionProposal { 
        [...] 
        @Override 
        public String getAdditionalProposalInfo() { 
         return "<b>Hello</b> <i>World</i>!"; 
        } 
    }