Search in sources :

Example 6 with ITextViewerExtension

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

the class MarkRegionTarget method swapMarkAndCursor.

@Override
public void swapMarkAndCursor() {
    if (!(fViewer instanceof ITextViewerExtension))
        return;
    ITextViewerExtension viewerExtension = ((ITextViewerExtension) fViewer);
    int markPosition = viewerExtension.getMark();
    if (markPosition == -1) {
        fStatusLine.setErrorMessage(EditorMessages.MarkRegionTarget_markNotSet);
        // $NON-NLS-1$
        fStatusLine.setMessage("");
        return;
    }
    if (!isVisible(fViewer, markPosition)) {
        fStatusLine.setErrorMessage(EditorMessages.MarkRegionTarget_markNotVisible);
        // $NON-NLS-1$
        fStatusLine.setMessage("");
        return;
    }
    Point selection = fViewer.getSelectedRange();
    viewerExtension.setMark(selection.x);
    fViewer.setSelectedRange(markPosition, 0);
    fViewer.revealRange(markPosition, 0);
    // $NON-NLS-1$
    fStatusLine.setErrorMessage("");
    fStatusLine.setMessage(EditorMessages.Editor_mark_status_message_mark_swapped);
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 7 with ITextViewerExtension

use of org.eclipse.jface.text.ITextViewerExtension 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 8 with ITextViewerExtension

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

the class ContentAssistant2 method manageAutoActivation.

/**
 * Installs and uninstall the listeners needed for auto activation.
 *
 * @param start <code>true</code> if listeners must be installed, <code>false</code> if they
 *            must be removed
 * @since 2.0
 */
private void manageAutoActivation(boolean start) {
    if (start) {
        if (fViewer != null && fAutoAssistListener == null) {
            fAutoAssistListener = new AutoAssistListener();
            if (fViewer instanceof ITextViewerExtension) {
                ITextViewerExtension extension = (ITextViewerExtension) fViewer;
                extension.appendVerifyKeyListener(fAutoAssistListener);
            } else {
                StyledText textWidget = fViewer.getTextWidget();
                if (Helper2.okToUse(textWidget))
                    textWidget.addVerifyKeyListener(fAutoAssistListener);
            }
        }
    } else if (fAutoAssistListener != null) {
        if (fViewer instanceof ITextViewerExtension) {
            ITextViewerExtension extension = (ITextViewerExtension) fViewer;
            extension.removeVerifyKeyListener(fAutoAssistListener);
        } else {
            StyledText textWidget = fViewer.getTextWidget();
            if (Helper2.okToUse(textWidget))
                textWidget.removeVerifyKeyListener(fAutoAssistListener);
        }
        fAutoAssistListener = null;
    }
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) StyledText(org.eclipse.swt.custom.StyledText)

Example 9 with ITextViewerExtension

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

the class CompositeRuler method layoutTextViewer.

/**
 * Layouts the text viewer. This also causes this ruler to get
 * be layouted.
 */
private void layoutTextViewer() {
    Control parent = fTextViewer.getTextWidget();
    if (fTextViewer instanceof ITextViewerExtension) {
        ITextViewerExtension extension = (ITextViewerExtension) fTextViewer;
        parent = extension.getControl();
    }
    if (parent instanceof Composite && !parent.isDisposed())
        ((Composite) parent).layout(true);
}
Also used : Control(org.eclipse.swt.widgets.Control) ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) Composite(org.eclipse.swt.widgets.Composite)

Example 10 with ITextViewerExtension

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

the class LinkedModeUI method beginCompoundChangeIfNeeded.

private void beginCompoundChangeIfNeeded() {
    if (!fHasOpenCompoundChange) {
        ITextViewerExtension extension = (ITextViewerExtension) fCurrentTarget.getViewer();
        IRewriteTarget target = extension.getRewriteTarget();
        target.beginCompoundChange();
        fHasOpenCompoundChange = true;
    }
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) IRewriteTarget(org.eclipse.jface.text.IRewriteTarget)

Aggregations

ITextViewerExtension (org.eclipse.jface.text.ITextViewerExtension)21 StyledText (org.eclipse.swt.custom.StyledText)10 Point (org.eclipse.swt.graphics.Point)8 Control (org.eclipse.swt.widgets.Control)5 IDocument (org.eclipse.jface.text.IDocument)4 IRewriteTarget (org.eclipse.jface.text.IRewriteTarget)4 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)4 Composite (org.eclipse.swt.widgets.Composite)4 IEditingSupportRegistry (org.eclipse.jface.text.IEditingSupportRegistry)2 IRegion (org.eclipse.jface.text.IRegion)2 ITextViewer (org.eclipse.jface.text.ITextViewer)2 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)2 VerifyKeyListener (org.eclipse.swt.custom.VerifyKeyListener)2 ICommandService (org.eclipse.ui.commands.ICommandService)2 ArrayList (java.util.ArrayList)1 IStatusLineManager (org.eclipse.jface.action.IStatusLineManager)1 IContentAssistSubjectControl (org.eclipse.jface.contentassist.IContentAssistSubjectControl)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 BadPositionCategoryException (org.eclipse.jface.text.BadPositionCategoryException)1 DocumentEvent (org.eclipse.jface.text.DocumentEvent)1