Search in sources :

Example 71 with TextSelection

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

the class UtilityFunctions method jumpToPosition.

public static boolean jumpToPosition(IProject project, EditorPosition pos) {
    ABSEditor targeteditor = UtilityFunctions.openABSEditorForFile(pos.getPath(), project);
    if (targeteditor == null) {
        return false;
    }
    IDocument doc = targeteditor.getDocumentProvider().getDocument(targeteditor.getEditorInput());
    try {
        int startoff = doc.getLineOffset(pos.getLinestart() - 1) + pos.getColstart() - 1;
        targeteditor.getSelectionProvider().setSelection(new TextSelection(startoff, 0));
        return true;
    } catch (BadLocationException ex) {
        Activator.logException(ex);
        return false;
    }
}
Also used : TextSelection(org.eclipse.jface.text.TextSelection) ABSEditor(org.absmodels.abs.plugin.editor.ABSEditor) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 72 with TextSelection

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

the class NewABSFileWizard method insertModuleDeclaration.

/**
 * If the original selection
 * @param targeteditor
 * @throws BadLocationException
 */
private void insertModuleDeclaration(ABSEditor targeteditor) throws BadLocationException {
    IDocument doc = targeteditor.getDocumentProvider().getDocument(targeteditor.getEditorInput());
    ModulePath mp = getLastModulePathElement(selection);
    if (mp != null) {
        doc.replace(0, 0, "module " + mp.getModulePath() + ".");
        targeteditor.getSelectionProvider().setSelection(new TextSelection(8 + mp.getModulePath().length(), 0));
    } else {
        doc.replace(0, 0, "module ");
        targeteditor.getSelectionProvider().setSelection(new TextSelection(7, 0));
    }
}
Also used : ModulePath(org.absmodels.abs.plugin.navigator.ModulePath) TextSelection(org.eclipse.jface.text.TextSelection) IDocument(org.eclipse.jface.text.IDocument)

Example 73 with TextSelection

use of org.eclipse.jface.text.TextSelection in project ch.hsr.ifs.cdttesting by IFS-HSR.

the class Select method setInput.

@Override
public void setInput(final int from, final int to) {
    boolean editorAreaVisible = window.getActivePage().isEditorAreaVisible();
    IEditorPart activeEditor = window.getActivePage().getActiveEditor();
    if (editorAreaVisible && activeEditor instanceof ITextEditor) {
        ITextEditor editor = (ITextEditor) activeEditor;
        editor.getSelectionProvider().setSelection(new TextSelection(from, to - from));
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) TextSelection(org.eclipse.jface.text.TextSelection) IEditorPart(org.eclipse.ui.IEditorPart)

Example 74 with TextSelection

use of org.eclipse.jface.text.TextSelection in project ch.hsr.ifs.cdttesting by IFS-HSR.

the class ASTWidget method createNode.

private Node<Pair<Button, IASTNode>> createNode(final Button button, final IASTNode astNode) {
    final Node<Pair<Button, IASTNode>> node = new Node<>(new Pair<>(button, astNode));
    final Point minButtonSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    nodeHeight = Math.max(nodeHeight, minButtonSize.y);
    node.setWidth(minButtonSize.x);
    node.treatAsLeaf(true);
    if (astNode instanceof ICPPASTTranslationUnit) {
        button.setBackground(GOLDEN_YELLOW);
        button.getFont().getFontData()[0].setStyle(SWT.BOLD);
    }
    button.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(final MouseEvent e) {
            int selectKey = 0;
            if (prefStore.getString(PreferenceConstants.P_HOW_TO_SELECT).equals(PreferenceConstants.P_SELECT_BY_RIGHT_CLICK)) {
                selectKey = 3;
            } else if (prefStore.getString(PreferenceConstants.P_HOW_TO_SELECT).equals(PreferenceConstants.P_SELECT_BY_LEFT_CLICK)) {
                selectKey = 1;
            }
            if (e.button == selectKey) {
                setNodeInNodeView(astNode);
            }
            if (e.button == 1) {
                buildChildrenAndRefresh(node);
            }
        }
    });
    button.addMouseTrackListener(new MouseTrackListener() {

        @Override
        public void mouseHover(final MouseEvent e) {
            if (prefStore.getString(PreferenceConstants.P_HOW_TO_SELECT).equals(PreferenceConstants.P_SELECT_BY_MOUSE_OVER)) {
                setNodeInNodeView(astNode);
            }
            IASTFileLocation fileLocation = astNode.getFileLocation();
            while (fileLocation.getContextInclusionStatement() != null) {
                final IASTPreprocessorIncludeStatement contextInclusionStatement = fileLocation.getContextInclusionStatement();
                fileLocation = contextInclusionStatement.getFileLocation();
            }
            final TextSelection textSelection = new TextSelection(fileLocation.getNodeOffset(), fileLocation.getNodeLength());
            CUIPlugin.getActivePage().getActiveEditor().getEditorSite().getSelectionProvider().setSelection(textSelection);
        }

        @Override
        public void mouseExit(final MouseEvent e) {
        }

        @Override
        public void mouseEnter(final MouseEvent e) {
        }
    });
    return node;
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) TextSelection(org.eclipse.jface.text.TextSelection) IASTNode(org.eclipse.cdt.core.dom.ast.IASTNode) Node(ch.hsr.ifs.pasta.tree.Node) MouseTrackListener(org.eclipse.swt.events.MouseTrackListener) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Point(org.eclipse.swt.graphics.Point) IASTFileLocation(org.eclipse.cdt.core.dom.ast.IASTFileLocation) IASTPreprocessorIncludeStatement(org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement) ICPPASTTranslationUnit(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit)

Example 75 with TextSelection

use of org.eclipse.jface.text.TextSelection in project webtools.sourceediting by eclipse.

the class StructuredSelectNextXMLHandler method getNewSelectionRegion2.

/**
 * This method was separated out from getNewSelectionRegion2 because the
 * code in here is allowed to be called recursively.
 *
 * @param indexedRegion
 * @param textSelection
 * @return new region to select or null if none
 */
private Region getNewSelectionRegion2(IndexedRegion indexedRegion, ITextSelection textSelection) {
    Region newRegion = null;
    if (indexedRegion instanceof Node) {
        Node node = (Node) indexedRegion;
        Node newNode = node.getNextSibling();
        if (newNode == null) {
            newNode = node.getParentNode();
            if (newNode instanceof IndexedRegion) {
                IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
                newRegion = new Region(newIndexedRegion.getStartOffset(), newIndexedRegion.getEndOffset() - newIndexedRegion.getStartOffset());
            }
        } else {
            if (newNode instanceof IndexedRegion) {
                IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
                newRegion = new Region(textSelection.getOffset(), newIndexedRegion.getEndOffset() - textSelection.getOffset());
                if (newNode.getNodeType() == Node.TEXT_NODE) {
                    newRegion = getNewSelectionRegion2(newIndexedRegion, new TextSelection(newRegion.getOffset(), newRegion.getLength()));
                }
            }
        }
    }
    return newRegion;
}
Also used : TextSelection(org.eclipse.jface.text.TextSelection) ITextSelection(org.eclipse.jface.text.ITextSelection) Node(org.w3c.dom.Node) Region(org.eclipse.jface.text.Region) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

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