Search in sources :

Example 16 with ITextViewerExtension

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

the class ContentAssistant2 method installKeyListener.

/**
 * Installs a key listener on the text viewer's widget.
 */
private void installKeyListener() {
    if (!fKeyListenerHooked) {
        StyledText text = fViewer.getTextWidget();
        if (Helper2.okToUse(text)) {
            if (fViewer instanceof ITextViewerExtension) {
                ITextViewerExtension e = (ITextViewerExtension) fViewer;
                e.prependVerifyKeyListener(fInternalListener);
            } else {
                text.addVerifyKeyListener(fInternalListener);
            }
            fKeyListenerHooked = true;
        }
    }
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) StyledText(org.eclipse.swt.custom.StyledText)

Example 17 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 18 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 19 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 20 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)

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