use of org.eclipse.jface.text.contentassist.IContextInformation in project eclipse.platform.text by eclipse.
the class CompletionProposalPopup2 method insertProposal.
/**
* Applies the given proposal at the given offset. The given character is the
* one that triggered the insertion of this proposal.
*
* @param p the completion proposal
* @param trigger the trigger character
* @param stateMask the state mask of the keyboard event triggering the insertion
* @param offset the offset
* @since 2.1
*/
private void insertProposal(ICompletionProposal p, char trigger, int stateMask, final int offset) {
fInserting = true;
IRewriteTarget target = null;
IEditingSupportRegistry registry = null;
try {
IDocument document = fViewer.getDocument();
if (fViewer instanceof ITextViewerExtension) {
ITextViewerExtension extension = (ITextViewerExtension) fViewer;
target = extension.getRewriteTarget();
}
if (target != null)
target.beginCompoundChange();
if (fViewer instanceof IEditingSupportRegistry) {
registry = (IEditingSupportRegistry) fViewer;
registry.register(fModificationEditingSupport);
}
if (p instanceof ICompletionProposalExtension2) {
ICompletionProposalExtension2 e = (ICompletionProposalExtension2) p;
e.apply(fViewer, trigger, stateMask, offset);
} else if (p instanceof ICompletionProposalExtension) {
ICompletionProposalExtension e = (ICompletionProposalExtension) p;
e.apply(document, trigger, offset);
} else {
p.apply(document);
}
Point selection = p.getSelection(document);
if (selection != null) {
fViewer.setSelectedRange(selection.x, selection.y);
fViewer.revealRange(selection.x, selection.y);
}
IContextInformation info = p.getContextInformation();
if (info != null) {
int position;
if (p instanceof ICompletionProposalExtension) {
ICompletionProposalExtension e = (ICompletionProposalExtension) p;
position = e.getContextInformationPosition();
} else {
if (selection == null)
selection = fViewer.getSelectedRange();
position = selection.x + selection.y;
}
fContentAssistant.showContextInformation(info, position);
}
fContentAssistant.fireProposalChosen(p);
} finally {
if (target != null)
target.endCompoundChange();
if (registry != null)
registry.unregister(fModificationEditingSupport);
fInserting = false;
}
}
use of org.eclipse.jface.text.contentassist.IContextInformation in project eclipse.platform.text by eclipse.
the class ContentAssistant2 method computeContextInformation.
/**
* Returns an array of context information objects computed based
* on the specified document position. The position is used to determine
* the appropriate content assist processor to invoke.
*
* @param viewer the viewer for which to compute the context information
* @param position a document position
* @return an array of context information objects
*
* @see IContentAssistProcessor#computeContextInformation
*/
IContextInformation[] computeContextInformation(ITextViewer viewer, int position) {
fLastErrorMessage = null;
IContextInformation[] result = null;
IContentAssistProcessor p = getProcessor(viewer, position);
if (p != null) {
result = p.computeContextInformation(viewer, position);
fLastErrorMessage = p.getErrorMessage();
}
return result;
}
Aggregations