Search in sources :

Example 41 with ITextSelection

use of org.eclipse.jface.text.ITextSelection in project linuxtools by eclipse.

the class STPToggleCommentTest method getTextBlockFromSelectionTest.

@Test
public void getTextBlockFromSelectionTest() throws BadLocationException {
    int i = 0;
    int curPos = 0;
    for (String scriptLine : PARTITIONED_SCRIPT) {
        int lineLength = scriptLine.length();
        int offset = stpScript.indexOf(scriptLine, curPos);
        ITextSelection selection = new MockTextSelection(offset, lineLength, i, i, scriptLine);
        IRegion actualRegion = cmdHandler.getTextBlockFromSelection(selection, document);
        IRegion expectedRegion = new Region(offset, lineLength);
        assertEquals(scriptLine + " :", expectedRegion, actualRegion);
        curPos = offset + lineLength;
        i++;
    }
}
Also used : Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) ITextSelection(org.eclipse.jface.text.ITextSelection) IRegion(org.eclipse.jface.text.IRegion) Test(org.junit.Test)

Example 42 with ITextSelection

use of org.eclipse.jface.text.ITextSelection in project linuxtools by eclipse.

the class CParser method parseCurrentFunction.

@Override
public String parseCurrentFunction(IEditorPart editor) throws CoreException {
    // Check for correct editor type
    if (!(editor instanceof AbstractTextEditor))
        return "";
    // Get the editor, test selection and input.
    AbstractTextEditor a_editor = (AbstractTextEditor) editor;
    ITextSelection selection = (ITextSelection) (a_editor).getSelectionProvider().getSelection();
    IEditorInput input = a_editor.getEditorInput();
    // Parse it and return the function.
    return parseCurrentFunction(input, selection.getOffset());
}
Also used : AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) ITextSelection(org.eclipse.jface.text.ITextSelection) IEditorInput(org.eclipse.ui.IEditorInput)

Example 43 with ITextSelection

use of org.eclipse.jface.text.ITextSelection in project linuxtools by eclipse.

the class JavaParser method parseCurrentFunction.

@Override
public String parseCurrentFunction(IEditorPart editor) throws CoreException {
    // Check for correct editor type
    if (!(editor instanceof AbstractDecoratedTextEditor)) {
        return "";
    }
    // Get the editor, test selection and input.
    AbstractDecoratedTextEditor java_editor = (AbstractDecoratedTextEditor) editor;
    ITextSelection selection = (ITextSelection) (java_editor.getSelectionProvider().getSelection());
    IEditorInput input = java_editor.getEditorInput();
    // Parse it and return the function.
    return parseCurrentFunction(input, selection.getOffset());
}
Also used : ITextSelection(org.eclipse.jface.text.ITextSelection) IEditorInput(org.eclipse.ui.IEditorInput) AbstractDecoratedTextEditor(org.eclipse.ui.texteditor.AbstractDecoratedTextEditor)

Example 44 with ITextSelection

use of org.eclipse.jface.text.ITextSelection in project dbeaver by dbeaver.

the class SQLEditorSourceViewer method refreshTextSelection.

void refreshTextSelection() {
    ITextSelection selection = (ITextSelection) getSelection();
    fireSelectionChanged(selection.getOffset(), selection.getLength());
}
Also used : ITextSelection(org.eclipse.jface.text.ITextSelection)

Example 45 with ITextSelection

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

the class MarkOccurencesSupport method installOccurrencesFinder.

protected void installOccurrencesFinder(final boolean forceUpdate) {
    fMarkOccurrenceAnnotations = true;
    fPostSelectionListener = new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            final ISelection selection = event.getSelection();
            editor.markOccurencesHandler.updateOccurrenceAnnotations((ITextSelection) selection, editor.getModule());
        }
    };
    final ISelectionProvider selectionProvider = editor.getSelectionProvider();
    if (selectionProvider != null) {
        ((IPostSelectionProvider) selectionProvider).addPostSelectionChangedListener(fPostSelectionListener);
        if (forceUpdate) {
            fForcedMarkOccurrencesSelection = selectionProvider.getSelection();
            final IErlModule module = editor.getModule();
            if (module != null) {
                editor.markOccurencesHandler.updateOccurrenceAnnotations((ITextSelection) fForcedMarkOccurrencesSelection, module);
            }
        }
    }
    if (fOccurrencesFinderJobCanceler == null) {
        fOccurrencesFinderJobCanceler = new OccurrencesFinderJobCanceler();
        fOccurrencesFinderJobCanceler.install();
    }
}
Also used : IPostSelectionProvider(org.eclipse.jface.viewers.IPostSelectionProvider) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ISelection(org.eclipse.jface.viewers.ISelection) IErlModule(org.erlide.engine.model.root.IErlModule) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ITextSelection(org.eclipse.jface.text.ITextSelection)

Aggregations

ITextSelection (org.eclipse.jface.text.ITextSelection)200 ISelection (org.eclipse.jface.viewers.ISelection)64 IDocument (org.eclipse.jface.text.IDocument)50 BadLocationException (org.eclipse.jface.text.BadLocationException)45 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)34 IRegion (org.eclipse.jface.text.IRegion)33 Region (org.eclipse.jface.text.Region)29 IEditorPart (org.eclipse.ui.IEditorPart)29 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)26 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)20 ArrayList (java.util.ArrayList)18 TextSelection (org.eclipse.jface.text.TextSelection)16 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)14 IResource (org.eclipse.core.resources.IResource)12 IFile (org.eclipse.core.resources.IFile)11 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)11 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)11 Template (org.eclipse.jface.text.templates.Template)10 TemplateContext (org.eclipse.jface.text.templates.TemplateContext)10 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)10