Search in sources :

Example 1 with IEditingSupportRegistry

use of org.eclipse.jface.text.IEditingSupportRegistry in project eclipse.platform.text by eclipse.

the class CompletionProposalPopup 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
 * @param offset the offset
 * @since 2.1
 */
void insertProposal(ICompletionProposal p, char trigger, int stateMask, final int offset) {
    fInserting = true;
    IRewriteTarget target = null;
    IEditingSupport helper = new IEditingSupport() {

        @Override
        public boolean isOriginator(DocumentEvent event, IRegion focus) {
            return focus.getOffset() <= offset && focus.getOffset() + focus.getLength() >= offset;
        }

        @Override
        public boolean ownsFocusShell() {
            return false;
        }
    };
    try {
        IDocument document = fContentAssistSubjectControlAdapter.getDocument();
        if (fViewer instanceof ITextViewerExtension) {
            ITextViewerExtension extension = (ITextViewerExtension) fViewer;
            target = extension.getRewriteTarget();
        }
        if (target != null)
            target.beginCompoundChange();
        if (fViewer instanceof IEditingSupportRegistry) {
            IEditingSupportRegistry registry = (IEditingSupportRegistry) fViewer;
            registry.register(helper);
        }
        if (p instanceof ICompletionProposalExtension2 && fViewer != null) {
            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);
        }
        fireAppliedEvent(p);
        Point selection = p.getSelection(document);
        if (selection != null) {
            fContentAssistSubjectControlAdapter.setSelectedRange(selection.x, selection.y);
            fContentAssistSubjectControlAdapter.revealRange(selection.x, selection.y);
        }
        IContextInformation info = p.getContextInformation();
        if (info != null) {
            int contextInformationOffset;
            if (p instanceof ICompletionProposalExtension) {
                ICompletionProposalExtension e = (ICompletionProposalExtension) p;
                contextInformationOffset = e.getContextInformationPosition();
            } else {
                if (selection == null)
                    selection = fContentAssistSubjectControlAdapter.getSelectedRange();
                contextInformationOffset = selection.x + selection.y;
            }
            fContentAssistant.showContextInformation(info, contextInformationOffset);
        } else
            fContentAssistant.showContextInformation(null, -1);
    } finally {
        if (target != null)
            target.endCompoundChange();
        if (fViewer instanceof IEditingSupportRegistry) {
            IEditingSupportRegistry registry = (IEditingSupportRegistry) fViewer;
            registry.unregister(helper);
        }
        fInserting = false;
    }
}
Also used : IEditingSupport(org.eclipse.jface.text.IEditingSupport) ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) IRewriteTarget(org.eclipse.jface.text.IRewriteTarget) IEditingSupportRegistry(org.eclipse.jface.text.IEditingSupportRegistry) Point(org.eclipse.swt.graphics.Point) DocumentEvent(org.eclipse.jface.text.DocumentEvent) IRegion(org.eclipse.jface.text.IRegion) IDocument(org.eclipse.jface.text.IDocument) Point(org.eclipse.swt.graphics.Point)

Example 2 with IEditingSupportRegistry

use of org.eclipse.jface.text.IEditingSupportRegistry in project eclipse.platform.text by eclipse.

the class CompletionProposalPopup method hide.

/**
 * Hides this popup.
 */
public void hide() {
    unregister();
    if (fViewer instanceof IEditingSupportRegistry) {
        IEditingSupportRegistry registry = (IEditingSupportRegistry) fViewer;
        registry.unregister(fFocusHelper);
    }
    if (Helper.okToUse(fProposalShell)) {
        fContentAssistant.removeContentAssistListener(this, ContentAssistant.PROPOSAL_SELECTOR);
        fPopupCloser.uninstall();
        fProposalShell.setVisible(false);
        fProposalShell.dispose();
        fProposalShell = null;
    }
    if (fMessageTextFont != null) {
        fMessageTextFont.dispose();
        fMessageTextFont = null;
    }
    if (fMessageText != null) {
        fMessageText = null;
    }
    fEmptyMessage = null;
    fLastCompletionOffset = -1;
    fContentAssistant.fireSessionEndEvent();
}
Also used : IEditingSupportRegistry(org.eclipse.jface.text.IEditingSupportRegistry)

Example 3 with IEditingSupportRegistry

use of org.eclipse.jface.text.IEditingSupportRegistry in project eclipse.platform.text by eclipse.

the class CompletionProposalPopup2 method hide.

/**
 * Hides this popup.
 */
public void hide() {
    unregister();
    if (fViewer instanceof IEditingSupportRegistry) {
        IEditingSupportRegistry registry = (IEditingSupportRegistry) fViewer;
        registry.unregister(fFocusEditingSupport);
    }
    if (Helper2.okToUse(fProposalShell)) {
        fContentAssistant.removeContentAssistListener(this, ContentAssistant2.PROPOSAL_SELECTOR);
        fPopupCloser.uninstall();
        // see bug 47511: setVisible may run the event loop on GTK
        // and trigger a rentrant call - have to make sure we don't
        // dispose another shell that was already brought up in a
        // reentrant call when calling setVisible()
        Shell tempShell = fProposalShell;
        fProposalShell = null;
        tempShell.setVisible(false);
        tempShell.dispose();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IEditingSupportRegistry(org.eclipse.jface.text.IEditingSupportRegistry)

Example 4 with IEditingSupportRegistry

use of org.eclipse.jface.text.IEditingSupportRegistry in project eclipse.platform.text by eclipse.

the class CompletionProposalPopup2 method displayProposals.

/**
 *Displays this popup and install the additional info controller, so that additional info
 * is displayed when a proposal is selected and additional info is available.
 */
private void displayProposals() {
    if (fContentAssistant.addContentAssistListener(this, ContentAssistant2.PROPOSAL_SELECTOR)) {
        if (fDocumentListener == null)
            fDocumentListener = new IDocumentListener() {

                @Override
                public void documentAboutToBeChanged(DocumentEvent event) {
                    if (!fInserting)
                        fDocumentEvents.add(event);
                }

                @Override
                public void documentChanged(DocumentEvent event) {
                    if (!fInserting)
                        filterProposals();
                }
            };
        IDocument document = fViewer.getDocument();
        if (document != null)
            document.addDocumentListener(fDocumentListener);
        if (fViewer instanceof IEditingSupportRegistry) {
            IEditingSupportRegistry registry = (IEditingSupportRegistry) fViewer;
            registry.register(fFocusEditingSupport);
        }
        fProposalShell.setVisible(true);
        // visible
        if (!Helper2.okToUse(fProposalShell))
            return;
        if (fAdditionalInfoController != null) {
            fAdditionalInfoController.install(fProposalTable);
            fAdditionalInfoController.handleTableSelectionChanged();
        }
    }
}
Also used : IEditingSupportRegistry(org.eclipse.jface.text.IEditingSupportRegistry) IDocumentListener(org.eclipse.jface.text.IDocumentListener) DocumentEvent(org.eclipse.jface.text.DocumentEvent) IDocument(org.eclipse.jface.text.IDocument)

Example 5 with IEditingSupportRegistry

use of org.eclipse.jface.text.IEditingSupportRegistry 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;
    }
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) IRewriteTarget(org.eclipse.jface.text.IRewriteTarget) IEditingSupportRegistry(org.eclipse.jface.text.IEditingSupportRegistry) ICompletionProposalExtension(org.eclipse.jface.text.contentassist.ICompletionProposalExtension) IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) ICompletionProposalExtension2(org.eclipse.jface.text.contentassist.ICompletionProposalExtension2) Point(org.eclipse.swt.graphics.Point) IDocument(org.eclipse.jface.text.IDocument) Point(org.eclipse.swt.graphics.Point)

Aggregations

IEditingSupportRegistry (org.eclipse.jface.text.IEditingSupportRegistry)6 DocumentEvent (org.eclipse.jface.text.DocumentEvent)3 IDocument (org.eclipse.jface.text.IDocument)3 IEditingSupport (org.eclipse.jface.text.IEditingSupport)2 IRegion (org.eclipse.jface.text.IRegion)2 IRewriteTarget (org.eclipse.jface.text.IRewriteTarget)2 ITextViewerExtension (org.eclipse.jface.text.ITextViewerExtension)2 Point (org.eclipse.swt.graphics.Point)2 IDocumentListener (org.eclipse.jface.text.IDocumentListener)1 ICompletionProposalExtension (org.eclipse.jface.text.contentassist.ICompletionProposalExtension)1 ICompletionProposalExtension2 (org.eclipse.jface.text.contentassist.ICompletionProposalExtension2)1 IContextInformation (org.eclipse.jface.text.contentassist.IContextInformation)1 Shell (org.eclipse.swt.widgets.Shell)1