Search in sources :

Example 6 with TextSelection

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

the class AbstractMassifTest method checkLine.

protected void checkLine(MassifHeapTreeNode node) {
    IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    assertTrue(editor instanceof ITextEditor);
    ITextEditor textEditor = (ITextEditor) editor;
    ISelection selection = textEditor.getSelectionProvider().getSelection();
    assertTrue(selection instanceof TextSelection);
    TextSelection textSelection = (TextSelection) selection;
    // zero-indexed
    int line = textSelection.getStartLine() + 1;
    assertEquals(node.getLine(), line);
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) TextSelection(org.eclipse.jface.text.TextSelection) ISelection(org.eclipse.jface.viewers.ISelection) IEditorPart(org.eclipse.ui.IEditorPart)

Example 7 with TextSelection

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

the class DoubleClickTest method testDoubleClickLaunchRemoved.

@Test
public void testDoubleClickLaunchRemoved() throws Exception {
    ILaunchConfiguration config = createConfiguration(proj.getProject());
    // $NON-NLS-1$
    ILaunch launch = doLaunch(config, "testDoubleClickLine");
    // Remove launch - tests #284919
    DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
    doDoubleClick();
    IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    assertTrue("editor should be ITextEditor", editor instanceof ITextEditor);
    ITextEditor textEditor = (ITextEditor) editor;
    ISelection selection = textEditor.getSelectionProvider().getSelection();
    assertTrue("selection must be TextSelection", selection instanceof TextSelection);
    TextSelection textSelection = (TextSelection) selection;
    // zero-indexed
    int line = textSelection.getStartLine() + 1;
    assertEquals(frame.getLine(), line);
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) TextSelection(org.eclipse.jface.text.TextSelection) ILaunch(org.eclipse.debug.core.ILaunch) ISelection(org.eclipse.jface.viewers.ISelection) IEditorPart(org.eclipse.ui.IEditorPart) Test(org.junit.Test)

Example 8 with TextSelection

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

the class LinkedResourceDoubleClickTest method testLinkedDoubleClickLine.

@Test
public void testLinkedDoubleClickLine() throws Exception {
    ILaunchConfiguration config = createConfiguration(proj.getProject());
    // $NON-NLS-1$
    doLaunch(config, "testLinkedDoubleClickLine");
    doDoubleClick();
    IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    assertTrue("editor must be text editor", editor instanceof ITextEditor);
    ITextEditor textEditor = (ITextEditor) editor;
    ISelection selection = textEditor.getSelectionProvider().getSelection();
    assertTrue("selection must be text one", selection instanceof TextSelection);
    TextSelection textSelection = (TextSelection) selection;
    // zero-indexed
    int line = textSelection.getStartLine() + 1;
    assertEquals(frame.getLine(), line);
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) TextSelection(org.eclipse.jface.text.TextSelection) ISelection(org.eclipse.jface.viewers.ISelection) IEditorPart(org.eclipse.ui.IEditorPart) Test(org.junit.Test)

Example 9 with TextSelection

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

the class STPEditor method jumpToLocation.

/**
 * Jumps to the location in the IDocument.
 * @param line The line you wish to jump to.
 * @param character The character you wish to jump to.
 */
public void jumpToLocation(int line, int character) {
    IDocument doc = getSourceViewer().getDocument();
    try {
        int offset = doc.getLineOffset(line - 1) + character;
        this.getSelectionProvider().setSelection(new TextSelection(doc, offset, 0));
    } catch (BadLocationException boe) {
    // Pass
    }
}
Also used : ITextSelection(org.eclipse.jface.text.ITextSelection) TextSelection(org.eclipse.jface.text.TextSelection) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 10 with TextSelection

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

the class CParserTest method canParseCurrentFunctionInCppFile.

/**
 * Given an IEditorPart and current selection is inside a method,
 * CParser should be able to figure that out.
 *
 * @throws Exception
 */
@Test
public void canParseCurrentFunctionInCppFile() throws Exception {
    // make test project a C++ project
    project.addCCNature();
    final String expectedFunction = "main";
    final String cppSourceCode = "#include \"circle.h\"\n" + "#include <math.h>\n" + "float circle::area() {\n" + "return this->radius * this-> radius * M_PI\n" + "}\n" + "int " + expectedFunction + "() {\n" + "int some_var = 0;\n" + "// " + OFFSET_MARKER + "\n" + "return 0;\n" + "}\n";
    assertNull(project.getTestProject().findMember(new Path("/src/circle.cpp")));
    // Add shape.h to project
    InputStream newFileInputStream = new ByteArrayInputStream(cppSourceCode.getBytes());
    IFile cppSourceFile = project.addFileToProject("/src", "circle.cpp", newFileInputStream);
    assertNotNull(project.getTestProject().findMember(new Path("/src/circle.cpp")));
    // Open a source file and get the IEditorPart
    cppSourceEditorPart = openEditor(cppSourceFile);
    // make sure editor content is correct
    assertEquals(cppSourceCode, getContent(cppSourceEditorPart));
    // make sure we have the proper editor type
    assertTrue(cppSourceEditorPart instanceof AbstractTextEditor);
    // Select the snippet we want
    int selectionStart = cppSourceCode.indexOf(OFFSET_MARKER);
    assertTrue(selectionStart >= 0);
    int selectionLength = OFFSET_MARKER.length();
    AbstractTextEditor cppEditor = (AbstractTextEditor) cppSourceEditorPart;
    cppEditor.getSelectionProvider().setSelection(new TextSelection(selectionStart, selectionLength));
    final String actualFunction = cParser.parseCurrentFunction(cppSourceEditorPart);
    assertEquals(expectedFunction, actualFunction);
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TextSelection(org.eclipse.jface.text.TextSelection) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) Test(org.junit.Test)

Aggregations

TextSelection (org.eclipse.jface.text.TextSelection)28 Test (org.junit.Test)18 IFile (org.eclipse.core.resources.IFile)17 ByteArrayInputStream (java.io.ByteArrayInputStream)13 InputStream (java.io.InputStream)13 Path (org.eclipse.core.runtime.Path)13 IEditorPart (org.eclipse.ui.IEditorPart)8 ISelection (org.eclipse.jface.viewers.ISelection)7 AbstractDecoratedTextEditor (org.eclipse.ui.texteditor.AbstractDecoratedTextEditor)7 AbstractTextEditor (org.eclipse.ui.texteditor.AbstractTextEditor)6 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)6 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)5 XtextResource (org.eclipse.xtext.resource.XtextResource)4 XExpression (org.eclipse.xtext.xbase.XExpression)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 ITextSelection (org.eclipse.jface.text.ITextSelection)3 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)3 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)3 BadLocationException (org.eclipse.jface.text.BadLocationException)2 TreePath (org.eclipse.jface.viewers.TreePath)2