Search in sources :

Example 11 with ITextViewerExtension

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

the class IncrementalFindTarget method uninstall.

/**
 * Uninstalls itself. I.e. removes all listeners installed in <code>install</code>.
 */
private void uninstall() {
    fTextViewer.removeTextListener(this);
    ISelectionProvider selectionProvider = fTextViewer.getSelectionProvider();
    if (selectionProvider != null)
        selectionProvider.removeSelectionChangedListener(this);
    StyledText text = fTextViewer.getTextWidget();
    if (text != null) {
        text.removeMouseListener(this);
        text.removeFocusListener(this);
    }
    if (fTextViewer instanceof ITextViewerExtension) {
        ((ITextViewerExtension) fTextViewer).removeVerifyKeyListener(this);
    } else {
        if (text != null)
            text.removeVerifyKeyListener(this);
    }
    ICommandService commandService = PlatformUI.getWorkbench().getAdapter(ICommandService.class);
    if (commandService != null)
        commandService.removeExecutionListener(this);
    fInstalled = false;
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) StyledText(org.eclipse.swt.custom.StyledText) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 12 with ITextViewerExtension

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

the class MarkRegionTarget method setMarkAtCursor.

@Override
public void setMarkAtCursor(boolean set) {
    if (!(fViewer instanceof ITextViewerExtension))
        return;
    ITextViewerExtension viewerExtension = ((ITextViewerExtension) fViewer);
    if (set) {
        Point selection = fViewer.getSelectedRange();
        viewerExtension.setMark(selection.x);
        // $NON-NLS-1$
        fStatusLine.setErrorMessage("");
        fStatusLine.setMessage(EditorMessages.Editor_mark_status_message_mark_set);
    } else {
        viewerExtension.setMark(-1);
        // $NON-NLS-1$
        fStatusLine.setErrorMessage("");
        fStatusLine.setMessage(EditorMessages.Editor_mark_status_message_mark_cleared);
    }
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) Point(org.eclipse.swt.graphics.Point)

Example 13 with ITextViewerExtension

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

the class AbstractTextEditor method getAdapter.

@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Class<T> required) {
    if (IEditorStatusLine.class.equals(required)) {
        if (fEditorStatusLine == null) {
            IStatusLineManager statusLineManager = getStatusLineManager();
            ISelectionProvider selectionProvider = getSelectionProvider();
            if (statusLineManager != null && selectionProvider != null)
                fEditorStatusLine = new EditorStatusLine(statusLineManager, selectionProvider);
        }
        return (T) fEditorStatusLine;
    }
    if (IVerticalRulerInfo.class.equals(required)) {
        if (fVerticalRuler != null)
            return (T) fVerticalRuler;
    }
    if (IMarkRegionTarget.class.equals(required)) {
        if (fMarkRegionTarget == null) {
            IStatusLineManager manager = getStatusLineManager();
            if (manager != null)
                fMarkRegionTarget = (fSourceViewer == null ? null : new MarkRegionTarget(fSourceViewer, manager));
        }
        return (T) fMarkRegionTarget;
    }
    if (IDeleteLineTarget.class.equals(required)) {
        if (fDeleteLineTarget == null) {
            fDeleteLineTarget = new TextViewerDeleteLineTarget(fSourceViewer);
        }
        return (T) fDeleteLineTarget;
    }
    if (IncrementalFindTarget.class.equals(required)) {
        if (fIncrementalFindTarget == null) {
            IStatusLineManager manager = getStatusLineManager();
            if (manager != null)
                fIncrementalFindTarget = (fSourceViewer == null ? null : new IncrementalFindTarget(fSourceViewer, manager));
        }
        return (T) fIncrementalFindTarget;
    }
    if (IFindReplaceTarget.class.equals(required)) {
        if (fFindReplaceTarget == null) {
            IFindReplaceTarget target = (fSourceViewer == null ? null : fSourceViewer.getFindReplaceTarget());
            if (target != null) {
                fFindReplaceTarget = new FindReplaceTarget(this, target);
                if (fFindScopeHighlightColor != null)
                    fFindReplaceTarget.setScopeHighlightColor(fFindScopeHighlightColor);
            }
        }
        return (T) fFindReplaceTarget;
    }
    if (ITextOperationTarget.class.equals(required))
        return (fSourceViewer == null ? null : (T) fSourceViewer.getTextOperationTarget());
    if (IRewriteTarget.class.equals(required)) {
        if (fSourceViewer instanceof ITextViewerExtension) {
            ITextViewerExtension extension = (ITextViewerExtension) fSourceViewer;
            return (T) extension.getRewriteTarget();
        }
        return null;
    }
    if (Control.class.equals(required))
        return fSourceViewer != null ? (T) fSourceViewer.getTextWidget() : null;
    if (IColumnSupport.class.equals(required)) {
        if (fColumnSupport == null)
            fColumnSupport = createColumnSupport();
        return (T) fColumnSupport;
    }
    return super.getAdapter(required);
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) SWT(org.eclipse.swt.SWT) ST(org.eclipse.swt.custom.ST) IStatusLineManager(org.eclipse.jface.action.IStatusLineManager) IFindReplaceTarget(org.eclipse.jface.text.IFindReplaceTarget) IFindReplaceTarget(org.eclipse.jface.text.IFindReplaceTarget) IMarkRegionTarget(org.eclipse.jface.text.IMarkRegionTarget)

Example 14 with ITextViewerExtension

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

Example 15 with ITextViewerExtension

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

the class ContentAssistant2 method uninstallKeyListener.

/**
 * Uninstall the key listener from the text viewer's widget.
 */
private void uninstallKeyListener() {
    if (fKeyListenerHooked) {
        StyledText text = fViewer.getTextWidget();
        if (Helper2.okToUse(text)) {
            if (fViewer instanceof ITextViewerExtension) {
                ITextViewerExtension e = (ITextViewerExtension) fViewer;
                e.removeVerifyKeyListener(fInternalListener);
            } else {
                text.removeVerifyKeyListener(fInternalListener);
            }
            fKeyListenerHooked = false;
        }
    }
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) StyledText(org.eclipse.swt.custom.StyledText)

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