Search in sources :

Example 1 with ITextViewerExtension

use of org.eclipse.jface.text.ITextViewerExtension in project xtext-eclipse by eclipse.

the class MarkRegionTargetWithoutStatusline method swapMarkAndCursor.

@Override
public void swapMarkAndCursor() {
    if (!(fViewer instanceof ITextViewerExtension))
        return;
    ITextViewerExtension viewerExtension = ((ITextViewerExtension) fViewer);
    int markPosition = viewerExtension.getMark();
    if (markPosition == -1) {
        return;
    }
    if (!isVisible(fViewer, markPosition)) {
        return;
    }
    Point selection = fViewer.getSelectedRange();
    viewerExtension.setMark(selection.x);
    fViewer.setSelectedRange(markPosition, 0);
    fViewer.revealRange(markPosition, 0);
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 2 with ITextViewerExtension

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

the class AbstractTextEditor method setWordWrap.

/**
 * @see org.eclipse.ui.texteditor.ITextEditorExtension6#setWordWrap(boolean)
 * @since 3.10
 */
@Override
public void setWordWrap(boolean enable) {
    if (!isWordWrapSupported() || isWordWrapEnabled() == enable) {
        return;
    }
    ISourceViewer viewer = getSourceViewer();
    if (viewer != null) {
        StyledText styledText = viewer.getTextWidget();
        if (styledText != null) {
            if (isBlockSelectionModeEnabled()) {
                setBlockSelectionMode(false);
            }
            styledText.setWordWrap(enable);
            if (fVerticalRuler != null) {
                // update ruler layout so that it can consider
                // changed horizontal scrollbar visibility
                boolean updated = false;
                if (viewer instanceof ITextViewerExtension) {
                    Control control = ((ITextViewerExtension) viewer).getControl();
                    if (control instanceof Composite) {
                        ((Composite) control).layout();
                        updated = true;
                    }
                }
                if (!updated) {
                    fVerticalRuler.update();
                }
            }
        }
    }
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) Control(org.eclipse.swt.widgets.Control) StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer)

Example 3 with ITextViewerExtension

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

the class AbstractTextEditor method setFont.

/**
 * Sets the font for the given viewer sustaining selection and scroll position.
 *
 * @param sourceViewer the source viewer
 * @param font the font
 * @since 2.0
 */
private void setFont(ISourceViewer sourceViewer, Font font) {
    if (sourceViewer.getDocument() != null) {
        ISelectionProvider provider = sourceViewer.getSelectionProvider();
        ISelection selection = provider.getSelection();
        int topIndex = sourceViewer.getTopIndex();
        StyledText styledText = sourceViewer.getTextWidget();
        Control parent = styledText;
        if (sourceViewer instanceof ITextViewerExtension) {
            ITextViewerExtension extension = (ITextViewerExtension) sourceViewer;
            parent = extension.getControl();
        }
        parent.setRedraw(false);
        styledText.setFont(font);
        if (fVerticalRuler instanceof IVerticalRulerExtension) {
            IVerticalRulerExtension e = (IVerticalRulerExtension) fVerticalRuler;
            e.setFont(font);
        }
        provider.setSelection(selection);
        sourceViewer.setTopIndex(topIndex);
        if (parent instanceof Composite) {
            Composite composite = (Composite) parent;
            composite.layout(true);
        }
        parent.setRedraw(true);
    } else {
        StyledText styledText = sourceViewer.getTextWidget();
        styledText.setFont(font);
        if (fVerticalRuler instanceof IVerticalRulerExtension) {
            IVerticalRulerExtension e = (IVerticalRulerExtension) fVerticalRuler;
            e.setFont(font);
        }
    }
}
Also used : IVerticalRulerExtension(org.eclipse.jface.text.source.IVerticalRulerExtension) Control(org.eclipse.swt.widgets.Control) ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) StyledText(org.eclipse.swt.custom.StyledText) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) Composite(org.eclipse.swt.widgets.Composite) ISelection(org.eclipse.jface.viewers.ISelection) Point(org.eclipse.swt.graphics.Point)

Example 4 with ITextViewerExtension

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

the class CaseAction method run.

@Override
public void run() {
    ITextEditor editor = getTextEditor();
    if (editor == null)
        return;
    if (!validateEditorInputState())
        return;
    ISourceViewer viewer = ((AbstractTextEditor) editor).getSourceViewer();
    if (viewer == null)
        return;
    IDocument document = viewer.getDocument();
    if (document == null)
        return;
    StyledText st = viewer.getTextWidget();
    if (st == null)
        return;
    ITextSelection selection = (ITextSelection) viewer.getSelectionProvider().getSelection();
    int adjustment = 0;
    try {
        if (JFaceTextUtil.isEmpty(viewer, selection))
            return;
        IRegion[] ranges = JFaceTextUtil.getCoveredRanges(viewer, selection);
        if (ranges.length > 1 && viewer instanceof ITextViewerExtension)
            ((ITextViewerExtension) viewer).getRewriteTarget().beginCompoundChange();
        for (int i = 0; i < ranges.length; i++) {
            IRegion region = ranges[i];
            String target = document.get(region.getOffset(), region.getLength());
            String replacement = (fToUpper ? target.toUpperCase() : target.toLowerCase());
            if (!target.equals(replacement)) {
                document.replace(region.getOffset(), region.getLength(), replacement);
                // https://bugs.eclipse.org/bugs/show_bug.cgi?id=145326: replacement might be larger than the original
                adjustment = replacement.length() - target.length();
            }
        }
        if (ranges.length > 1 && viewer instanceof ITextViewerExtension)
            ((ITextViewerExtension) viewer).getRewriteTarget().endCompoundChange();
    } catch (BadLocationException x) {
        // ignore and return
        return;
    }
    // reinstall selection and move it into view
    if (!(selection instanceof IBlockTextSelection))
        viewer.setSelectedRange(selection.getOffset(), selection.getLength() + adjustment);
    else
        viewer.getSelectionProvider().setSelection(selection);
    // don't use the viewer's reveal feature in order to avoid jumping around
    st.showSelection();
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) ITextSelection(org.eclipse.jface.text.ITextSelection) IRegion(org.eclipse.jface.text.IRegion) ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) IBlockTextSelection(org.eclipse.jface.text.IBlockTextSelection) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 5 with ITextViewerExtension

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

the class IncrementalFindTarget method install.

/**
 * Installs this target. I.e. adds all required listeners.
 */
private void install() {
    if (fInstalled)
        return;
    StyledText text = fTextViewer.getTextWidget();
    if (text == null)
        return;
    text.addMouseListener(this);
    text.addFocusListener(this);
    fTextViewer.addTextListener(this);
    ISelectionProvider selectionProvider = fTextViewer.getSelectionProvider();
    if (selectionProvider != null)
        selectionProvider.addSelectionChangedListener(this);
    if (fTextViewer instanceof ITextViewerExtension)
        ((ITextViewerExtension) fTextViewer).prependVerifyKeyListener(this);
    else
        text.addVerifyKeyListener(this);
    ICommandService commandService = PlatformUI.getWorkbench().getAdapter(ICommandService.class);
    if (commandService != null)
        commandService.addExecutionListener(this);
    fInstalled = true;
}
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)

Aggregations

ITextViewerExtension (org.eclipse.jface.text.ITextViewerExtension)36 StyledText (org.eclipse.swt.custom.StyledText)13 Point (org.eclipse.swt.graphics.Point)13 IDocument (org.eclipse.jface.text.IDocument)8 IRewriteTarget (org.eclipse.jface.text.IRewriteTarget)7 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)6 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)5 Control (org.eclipse.swt.widgets.Control)5 ITextViewer (org.eclipse.jface.text.ITextViewer)4 Composite (org.eclipse.swt.widgets.Composite)4 ICommandService (org.eclipse.ui.commands.ICommandService)4 BadLocationException (org.eclipse.jface.text.BadLocationException)3 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)2 IEditingSupportRegistry (org.eclipse.jface.text.IEditingSupportRegistry)2 IRegion (org.eclipse.jface.text.IRegion)2 ICompletionProposalExtension (org.eclipse.jface.text.contentassist.ICompletionProposalExtension)2 ICompletionProposalExtension2 (org.eclipse.jface.text.contentassist.ICompletionProposalExtension2)2 LinkedModeModel (org.eclipse.jface.text.link.LinkedModeModel)2 LinkedModeUI (org.eclipse.jface.text.link.LinkedModeUI)2 LinkedPosition (org.eclipse.jface.text.link.LinkedPosition)2