Search in sources :

Example 66 with TextSelection

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

the class WorkflowPropertyTester method test.

@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    if (receiver == null)
        return false;
    IResource resource = (IResource) Platform.getAdapterManager().getAdapter(receiver, org.eclipse.core.resources.IResource.class);
    if (resource != null) {
        return WorkflowLaunchUtils.workflowFileAvailableForGrammarFile(resource);
    } else if (receiver instanceof IOutlineNode) {
        IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        XtextEditor activeEditor = (XtextEditor) activePage.getActiveEditor();
        return WorkflowLaunchUtils.workflowFileAvailableFor(activeEditor);
    }
    TextSelection textSelection = (TextSelection) Platform.getAdapterManager().getAdapter(receiver, org.eclipse.jface.text.TextSelection.class);
    if (textSelection != null) {
        IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        IEditorPart activeEditor = activePage.getActiveEditor();
        return WorkflowLaunchUtils.workflowFileAvailableFor(activeEditor);
    }
    return false;
}
Also used : TextSelection(org.eclipse.jface.text.TextSelection) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) IResource(org.eclipse.core.resources.IResource) IOutlineNode(org.eclipse.xtext.ui.editor.outline.IOutlineNode)

Example 67 with TextSelection

use of org.eclipse.jface.text.TextSelection in project erlide_eclipse by erlang.

the class ErlangEditor method setSelection.

public void setSelection(final ISourceReference reference, final boolean moveCursor) {
    if (getSelectionProvider() == null) {
        return;
    }
    final ISelection selection = getSelectionProvider().getSelection();
    if (selection instanceof TextSelection) {
        final TextSelection textSelection = (TextSelection) selection;
        if (moveCursor && (textSelection.getOffset() != 0 || textSelection.getLength() != 0)) {
            markInNavigationHistory();
        }
    }
    if (reference != null) {
        StyledText textWidget = null;
        final ISourceViewer sourceViewer = getSourceViewer();
        if (sourceViewer == null) {
            return;
        }
        textWidget = sourceViewer.getTextWidget();
        if (textWidget == null) {
            return;
        }
        try {
            ISourceRange range = null;
            range = reference.getSourceRange();
            if (range == null) {
                return;
            }
            int offset = range.getOffset();
            int length = range.getLength();
            if (offset < 0 || length < 0) {
                return;
            }
            setHighlightRange(offset, length, moveCursor);
            if (!moveCursor) {
                return;
            }
            offset = -1;
            length = -1;
            if (reference instanceof IErlMember) {
                range = ((IErlMember) reference).getNameRange();
                if (range != null) {
                    offset = range.getOffset();
                    length = range.getLength();
                }
            } else if (reference instanceof IErlAttribute) {
                range = ((IErlAttribute) reference).getNameRange();
                if (range != null) {
                    offset = range.getOffset();
                    length = range.getLength();
                }
            } else if (reference instanceof IErlFunctionClause) {
                range = ((IErlFunctionClause) reference).getNameRange();
                if (range != null) {
                    offset = range.getOffset();
                    length = range.getLength();
                }
            }
            if (offset > -1 && length > 0) {
                try {
                    textWidget.setRedraw(false);
                    sourceViewer.revealRange(offset, length);
                    sourceViewer.setSelectedRange(offset, length);
                } finally {
                    textWidget.setRedraw(true);
                }
                markInNavigationHistory();
            }
        } catch (final IllegalArgumentException x) {
        }
    } else if (moveCursor) {
        resetHighlightRange();
        markInNavigationHistory();
    }
}
Also used : IErlMember(org.erlide.engine.model.erlang.IErlMember) StyledText(org.eclipse.swt.custom.StyledText) ITextSelection(org.eclipse.jface.text.ITextSelection) TextSelection(org.eclipse.jface.text.TextSelection) ISelection(org.eclipse.jface.viewers.ISelection) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IErlAttribute(org.erlide.engine.model.erlang.IErlAttribute) Point(org.eclipse.swt.graphics.Point) ISourceRange(org.erlide.engine.model.erlang.ISourceRange) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause)

Example 68 with TextSelection

use of org.eclipse.jface.text.TextSelection in project erlide_eclipse by erlang.

the class SendToConsoleAction method getLineSelection.

protected ITextSelection getLineSelection(final ITextSelection selection0, final boolean beginningOfNextLine) {
    ITextSelection selection = selection0;
    final IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
    if (selection.getLength() == 0) {
        // don't use isEmpty()!
        selection = ErlangAbstractHandler.extendSelectionToWholeLines(document, selection);
    }
    if (beginningOfNextLine) {
        final int endLine = selection.getEndLine();
        int offset;
        try {
            offset = document.getLineOffset(endLine) + document.getLineLength(endLine);
            selection = new TextSelection(offset, 0);
        } catch (final BadLocationException e) {
            offset = document.getLength();
        }
    }
    return selection;
}
Also used : ITextSelection(org.eclipse.jface.text.ITextSelection) TextSelection(org.eclipse.jface.text.TextSelection) ITextSelection(org.eclipse.jface.text.ITextSelection) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 69 with TextSelection

use of org.eclipse.jface.text.TextSelection in project erlide_eclipse by erlang.

the class ErlideSelection method selectCompleteLine.

/**
 * In event of partial selection, used to select the full lines involved.
 */
public void selectCompleteLine() {
    final IRegion endLine = getEndLine();
    final IRegion startLine = getStartLine();
    textSelection = new TextSelection(doc, startLine.getOffset(), endLine.getOffset() + endLine.getLength() - startLine.getOffset());
}
Also used : ITextSelection(org.eclipse.jface.text.ITextSelection) TextSelection(org.eclipse.jface.text.TextSelection) IRegion(org.eclipse.jface.text.IRegion)

Example 70 with TextSelection

use of org.eclipse.jface.text.TextSelection in project abstools by abstools.

the class WizardUtil method saveEditorAndGotoOffset.

/**
 * Saves the editor and sets the selection to the offset insertOffset
 * @param editor
 * @param insertOffset
 */
protected static void saveEditorAndGotoOffset(ABSEditor editor, int insertOffset) {
    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().saveEditor(editor, false);
    editor.getSelectionProvider().setSelection(new TextSelection(insertOffset, 0));
}
Also used : TextSelection(org.eclipse.jface.text.TextSelection)

Aggregations

TextSelection (org.eclipse.jface.text.TextSelection)105 IFile (org.eclipse.core.resources.IFile)35 ITextSelection (org.eclipse.jface.text.ITextSelection)24 ISelection (org.eclipse.jface.viewers.ISelection)24 Test (org.junit.Test)23 IDocument (org.eclipse.jface.text.IDocument)21 IEditorPart (org.eclipse.ui.IEditorPart)19 InputStream (java.io.InputStream)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 Path (org.eclipse.core.runtime.Path)13 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)11 BadLocationException (org.eclipse.jface.text.BadLocationException)10 IRegion (org.eclipse.jface.text.IRegion)10 XtextResource (org.eclipse.xtext.resource.XtextResource)9 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)8 Module (org.eclipse.titan.designer.AST.Module)8 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)8 XExpression (org.eclipse.xtext.xbase.XExpression)8 TTCN3Editor (org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor)7 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)7