Search in sources :

Example 56 with ITextViewer

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

the class XtendHoverInEditorTest method testHoverOfReferencedElement.

@Test
public void testHoverOfReferencedElement() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("/**");
        _builder.newLine();
        _builder.append(" ");
        _builder.append("* Hello Foo");
        _builder.newLine();
        _builder.append(" ");
        _builder.append("*/");
        _builder.newLine();
        _builder.append("class Foo {}");
        _builder.newLine();
        final String contentFoo = _builder.toString();
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("class Bar extends Foo {}");
        _builder_1.newLine();
        final String contentBar = _builder_1.toString();
        final IFile fileFoo = this.helper.createFile("Foo.xtend", contentFoo);
        final IFile fileBar = this.helper.createFile("Bar.xtend", contentBar);
        this._syncUtil.waitForBuild(null);
        final XtextEditor editor = this.helper.openEditor(fileBar);
        ISourceViewer _internalSourceViewer = editor.getInternalSourceViewer();
        Region _region = new Region(19, 1);
        Object _hoverInfo2 = ((ITextHoverExtension2) this.hoverer).getHoverInfo2(((ITextViewer) _internalSourceViewer), _region);
        final XtextBrowserInformationControlInput info = ((XtextBrowserInformationControlInput) _hoverInfo2);
        Assert.assertTrue(info.getHtml().contains("Hello Foo"));
        final XtextEditor fooEditor = this.helper.openEditor(fileFoo);
        IXtextDocument _document = fooEditor.getDocument();
        StringConcatenation _builder_2 = new StringConcatenation();
        _builder_2.append("/**");
        _builder_2.newLine();
        _builder_2.append(" ");
        _builder_2.append("* Hello BAZ");
        _builder_2.newLine();
        _builder_2.append(" ");
        _builder_2.append("*/");
        _builder_2.newLine();
        _builder_2.append("class Foo {}");
        _builder_2.newLine();
        _document.set(_builder_2.toString());
        this._syncUtil.waitForReconciler(fooEditor);
        this._syncUtil.waitForReconciler(editor);
        ISourceViewer _internalSourceViewer_1 = editor.getInternalSourceViewer();
        Region _region_1 = new Region(19, 1);
        Object _hoverInfo2_1 = ((ITextHoverExtension2) this.hoverer).getHoverInfo2(((ITextViewer) _internalSourceViewer_1), _region_1);
        final XtextBrowserInformationControlInput info2 = ((XtextBrowserInformationControlInput) _hoverInfo2_1);
        Assert.assertFalse(info2.getHtml().contains("Hello Foo"));
        Assert.assertTrue(info2.getHtml().contains("Hello BAZ"));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Region(org.eclipse.jface.text.Region) ITextHoverExtension2(org.eclipse.jface.text.ITextHoverExtension2) XtextBrowserInformationControlInput(org.eclipse.xtext.ui.editor.hover.html.XtextBrowserInformationControlInput) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) ITextViewer(org.eclipse.jface.text.ITextViewer) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) Test(org.junit.Test)

Example 57 with ITextViewer

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

the class TextViewerShiftAction method update.

@Override
public void update() {
    super.update();
    if (!isEnabled())
        return;
    if (!canModifyViewer()) {
        setEnabled(false);
        return;
    }
    ITextViewer viewer = getTextViewer();
    if (fOperationTarget == null && viewer != null && fOperationCode != -1)
        fOperationTarget = viewer.getTextOperationTarget();
}
Also used : ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 58 with ITextViewer

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

the class TextViewerShiftAction method updateForTab.

/**
 * Enablement when tab key is pressed - the current selection has to be cover multiple lines.
 *
 * @since 3.0
 */
protected void updateForTab() {
    super.update();
    if (isEnabled()) {
        if (!canModifyViewer()) {
            setEnabled(false);
            return;
        }
        ITextViewer viewer = getTextViewer();
        if (fOperationTarget == null && viewer != null && fOperationCode != -1)
            fOperationTarget = viewer.getTextOperationTarget();
        boolean isEnabled = (fOperationTarget != null && fOperationTarget.canDoOperation(fOperationCode));
        setEnabled(isEnabled);
    }
}
Also used : ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 59 with ITextViewer

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

the class AbstractCompositeHoverTest method testSingleHover.

@SuppressWarnings("deprecation")
@Test
public void testSingleHover() {
    AbstractCompositeHover hover = new AbstractCompositeHover() {

        @Override
        protected List<ITextHover> createHovers() {
            List<ITextHover> hovers = Lists.newArrayList();
            hovers.add(new ITextHover() {

                @Override
                public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
                    // TODO Auto-generated method stub
                    if (offset == 0)
                        return new Region(offset, 0);
                    return null;
                }

                @Override
                public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
                    return "test";
                }
            });
            return hovers;
        }
    };
    assertEquals(1, hover.getHovers().size());
    assertNotNull(hover.getHoverRegion(editor.getInternalSourceViewer(), 0));
    assertEquals("test", hover.getHoverInfo(editor.getInternalSourceViewer(), new Region(0, 0)));
    assertNull(hover.getHoverRegion(editor.getInternalSourceViewer(), 5));
    assertNull(hover.getHoverInfo(editor.getInternalSourceViewer(), new Region(0, 0)));
}
Also used : ITextHover(org.eclipse.jface.text.ITextHover) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IRegion(org.eclipse.jface.text.IRegion) AbstractCompositeHover(org.eclipse.xtext.ui.editor.hover.AbstractCompositeHover) ITextViewer(org.eclipse.jface.text.ITextViewer) Test(org.junit.Test) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest)

Example 60 with ITextViewer

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

the class TextViewerJoinLinesAction method update.

@Override
public void update() {
    super.update();
    if (!isEnabled())
        return;
    if (!canModifyViewer()) {
        setEnabled(false);
        return;
    }
    ITextViewer viewer = getTextViewer();
    setEnabled(viewer.isEditable());
}
Also used : ITextViewer(org.eclipse.jface.text.ITextViewer)

Aggregations

ITextViewer (org.eclipse.jface.text.ITextViewer)75 BadLocationException (org.eclipse.jface.text.BadLocationException)13 IDocument (org.eclipse.jface.text.IDocument)13 Region (org.eclipse.jface.text.Region)13 StyledText (org.eclipse.swt.custom.StyledText)13 IRegion (org.eclipse.jface.text.IRegion)11 ArrayList (java.util.ArrayList)9 Point (org.eclipse.swt.graphics.Point)9 Test (org.junit.Test)9 ITextSelection (org.eclipse.jface.text.ITextSelection)8 IEditorPart (org.eclipse.ui.IEditorPart)8 ITextViewerExtension5 (org.eclipse.jface.text.ITextViewerExtension5)6 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)6 Document (org.eclipse.jface.text.Document)5 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)5 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)5 Display (org.eclipse.swt.widgets.Display)5 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)5 List (java.util.List)4 ITextViewerExtension (org.eclipse.jface.text.ITextViewerExtension)4