Search in sources :

Example 26 with ITextViewerExtension

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

the class LinkedModeUI method leave.

void leave(final int flags) {
    if (!fIsActive)
        return;
    fIsActive = false;
    endCompoundChangeIfNeeded();
    Display display = null;
    if (fCurrentTarget.fWidget != null && !fCurrentTarget.fWidget.isDisposed())
        display = fCurrentTarget.fWidget.getDisplay();
    if (fCurrentTarget.fAnnotationModel != null)
        fCurrentTarget.fAnnotationModel.removeAllAnnotations();
    disconnect();
    for (LinkedModeUITarget fTarget : fTargets) {
        LinkedModeUITarget target = fTarget;
        ITextViewer viewer = target.getViewer();
        if (target.fKeyListener != null) {
            ((ITextViewerExtension) viewer).removeVerifyKeyListener(target.fKeyListener);
            target.fKeyListener = null;
        }
        viewer.removeTextInputListener(fCloser);
    }
    for (int i = 0; i < fTargets.length; i++) {
        if (fTargets[i].fAnnotationModel != null) {
            fTargets[i].fAnnotationModel.removeAllAnnotations();
            fTargets[i].fAnnotationModel.disconnect(fTargets[i].getViewer().getDocument());
            fTargets[i].fAnnotationModel = null;
        }
        uninstallAnnotationModel(fTargets[i]);
    }
    if ((flags & ILinkedModeListener.UPDATE_CARET) != 0 && fExitPosition != null && fFramePosition != fExitPosition && !fExitPosition.isDeleted())
        switchPosition(fExitPosition, true, false);
    final List<IDocument> docs = new ArrayList<>();
    for (LinkedModeUITarget fTarget : fTargets) {
        IDocument doc = fTarget.getViewer().getDocument();
        if (doc != null)
            docs.add(doc);
    }
    fModel.stopForwarding(flags);
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            if (fExitPosition != null)
                fExitPosition.getDocument().removePosition(fExitPosition);
            for (IDocument doc : docs) {
                doc.removePositionUpdater(fPositionUpdater);
                boolean uninstallCat = false;
                String[] cats = doc.getPositionCategories();
                for (String cat : cats) {
                    if (getCategory().equals(cat)) {
                        uninstallCat = true;
                        break;
                    }
                }
                if (uninstallCat)
                    try {
                        doc.removePositionCategory(getCategory());
                    } catch (BadPositionCategoryException e) {
                    // ignore
                    }
            }
            fModel.exit(flags);
        }
    };
    // gets correct document offsets.
    if (display != null)
        display.asyncExec(runnable);
    else
        runnable.run();
}
Also used : ArrayList(java.util.ArrayList) Point(org.eclipse.swt.graphics.Point) ITextViewer(org.eclipse.jface.text.ITextViewer) ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) BadPositionCategoryException(org.eclipse.jface.text.BadPositionCategoryException) IDocument(org.eclipse.jface.text.IDocument) Display(org.eclipse.swt.widgets.Display)

Example 27 with ITextViewerExtension

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

the class LinkedModeUI method endCompoundChangeIfNeeded.

private void endCompoundChangeIfNeeded() {
    if (fHasOpenCompoundChange) {
        ITextViewerExtension extension = (ITextViewerExtension) fCurrentTarget.getViewer();
        IRewriteTarget target = extension.getRewriteTarget();
        target.endCompoundChange();
        fHasOpenCompoundChange = false;
    }
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) IRewriteTarget(org.eclipse.jface.text.IRewriteTarget)

Example 28 with ITextViewerExtension

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

the class LinkedModeUI method connect.

private void connect() {
    Assert.isNotNull(fCurrentTarget);
    ITextViewer viewer = fCurrentTarget.getViewer();
    Assert.isNotNull(viewer);
    fCurrentTarget.fWidget = viewer.getTextWidget();
    if (fCurrentTarget.fWidget == null)
        leave(ILinkedModeListener.EXIT_ALL);
    if (fCurrentTarget.fKeyListener == null) {
        fCurrentTarget.fKeyListener = new KeyListener();
        ((ITextViewerExtension) viewer).prependVerifyKeyListener(fCurrentTarget.fKeyListener);
    } else
        fCurrentTarget.fKeyListener.setEnabled(true);
    registerAutoEditVetoer(viewer);
    ((IPostSelectionProvider) viewer).addPostSelectionChangedListener(fSelectionListener);
    createAnnotationModel();
    showSelection();
    fCurrentTarget.fShell = fCurrentTarget.fWidget.getShell();
    if (fCurrentTarget.fShell == null)
        leave(ILinkedModeListener.EXIT_ALL);
    fCurrentTarget.fShell.addShellListener(fCloser);
    fAssistant.install(viewer);
    viewer.addTextInputListener(fCloser);
    viewer.getDocument().addDocumentListener(fDocumentListener);
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) IPostSelectionProvider(org.eclipse.jface.viewers.IPostSelectionProvider) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 29 with ITextViewerExtension

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

the class ContextInformationPopup method createContextSelector.

/**
 * Creates the context selector in case the user has the choice between multiple valid contexts
 * at a given offset.
 */
private void createContextSelector() {
    if (Helper.okToUse(fContextSelectorShell))
        return;
    Control control = fContentAssistSubjectControlAdapter.getControl();
    fContextSelectorShell = new Shell(control.getShell(), SWT.ON_TOP | SWT.RESIZE);
    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    fContextSelectorShell.setLayout(layout);
    fContextSelectorShell.setBackground(control.getDisplay().getSystemColor(SWT.COLOR_BLACK));
    fContextSelectorShell.addControlListener(new ControlListener() {

        @Override
        public void controlMoved(ControlEvent e) {
        }

        @Override
        public void controlResized(ControlEvent e) {
            fContextSelectorPopupSize = fContextSelectorShell.getSize();
        }
    });
    if (fViewer instanceof ITextViewerExtension) {
        final ITextViewerExtension textViewerExtension = (ITextViewerExtension) fViewer;
        final StyledText textWidget = fViewer.getTextWidget();
        final VerifyKeyListener verifyListener = new VerifyKeyListener() {

            @Override
            public void verifyKey(VerifyEvent event) {
                if (isActive() && event.keyCode == 13 && event.character == '\r' && event.widget == textWidget) {
                    event.doit = false;
                    insertSelectedContext();
                    hideContextSelector();
                }
            }
        };
        textViewerExtension.prependVerifyKeyListener(verifyListener);
        fContextSelectorShell.addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                textViewerExtension.removeVerifyKeyListener(verifyListener);
            }
        });
    }
    fContextSelectorTable = new Table(fContextSelectorShell, SWT.H_SCROLL | SWT.V_SCROLL);
    fContextSelectorTable.setLocation(1, 1);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = fContextSelectorTable.getItemHeight() * 10;
    gd.widthHint = 300;
    fContextSelectorTable.setLayoutData(gd);
    Point size = fContentAssistant.restoreContextSelectorPopupSize();
    if (size != null)
        fContextSelectorShell.setSize(size);
    else
        fContextSelectorShell.pack(true);
    Color c = fContentAssistant.getContextSelectorBackground();
    if (c == null)
        c = control.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND);
    fContextSelectorTable.setBackground(c);
    c = fContentAssistant.getContextSelectorForeground();
    if (c == null)
        c = control.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND);
    fContextSelectorTable.setForeground(c);
    fContextSelectorTable.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            insertSelectedContext();
            hideContextSelector();
        }
    });
    fPopupCloser.install(fContentAssistant, fContextSelectorTable);
    fContextSelectorTable.setHeaderVisible(false);
    fContentAssistant.addToLayout(this, fContextSelectorShell, ContentAssistant.LayoutManager.LAYOUT_CONTEXT_SELECTOR, fContentAssistant.getSelectionOffset());
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) StyledText(org.eclipse.swt.custom.StyledText) Table(org.eclipse.swt.widgets.Table) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) Color(org.eclipse.swt.graphics.Color) Point(org.eclipse.swt.graphics.Point) DisposeEvent(org.eclipse.swt.events.DisposeEvent) IContentAssistSubjectControl(org.eclipse.jface.contentassist.IContentAssistSubjectControl) Control(org.eclipse.swt.widgets.Control) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) VerifyEvent(org.eclipse.swt.events.VerifyEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 30 with ITextViewerExtension

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

the class LineNumberRulerColumn method layout.

/**
 * Layouts the enclosing viewer to adapt the layout to changes of the
 * size of the individual components.
 *
 * @param redraw <code>true</code> if this column can be redrawn
 */
protected void layout(boolean redraw) {
    if (!redraw) {
        fRelayoutRequired = true;
        return;
    }
    fRelayoutRequired = false;
    if (fCachedTextViewer instanceof ITextViewerExtension) {
        ITextViewerExtension extension = (ITextViewerExtension) fCachedTextViewer;
        Control control = extension.getControl();
        if (control instanceof Composite && !control.isDisposed()) {
            Composite composite = (Composite) control;
            composite.layout(true);
        }
    }
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite)

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