Search in sources :

Example 1 with PairMatcher

use of org.eclipse.titan.designer.editors.ttcnppeditor.PairMatcher in project titan.EclipsePlug-ins by eclipse.

the class GotoMatchingBracketAction method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (activeEditor instanceof TTCNPPEditor) {
        this.targetEditor = (TTCNPPEditor) activeEditor;
    } else {
        this.targetEditor = null;
    }
    if (activeEditor == null) {
        return null;
    }
    if (!selection.isEmpty()) {
        if (selection instanceof TextSelection) {
            TextSelection tSelection = (TextSelection) selection;
            if (tSelection.getLength() != 0) {
                return null;
            }
        }
    }
    IDocument document = this.targetEditor.getDocument();
    int carretOffset = this.targetEditor.getCarretOffset();
    PairMatcher pairMatcher = new PairMatcher();
    IRegion region = pairMatcher.match(document, carretOffset);
    if (region == null) {
        return null;
    }
    int targetOffset;
    if (region.getOffset() + 1 == carretOffset) {
        targetOffset = region.getOffset() + region.getLength();
    } else {
        targetOffset = region.getOffset() + 1;
    }
    this.targetEditor.setCarretOffset(targetOffset);
    this.targetEditor.selectAndReveal(targetOffset, 0);
    return null;
}
Also used : TTCNPPEditor(org.eclipse.titan.designer.editors.ttcnppeditor.TTCNPPEditor) PairMatcher(org.eclipse.titan.designer.editors.ttcnppeditor.PairMatcher) TextSelection(org.eclipse.jface.text.TextSelection) IEditorPart(org.eclipse.ui.IEditorPart) IDocument(org.eclipse.jface.text.IDocument) IRegion(org.eclipse.jface.text.IRegion)

Example 2 with PairMatcher

use of org.eclipse.titan.designer.editors.ttcnppeditor.PairMatcher in project titan.EclipsePlug-ins by eclipse.

the class GotoMatchingBracketAction method run.

@Override
public void run(final IAction action) {
    if (targetEditor == null) {
        return;
    }
    if (!selection.isEmpty()) {
        if (selection instanceof TextSelection) {
            TextSelection tSelection = (TextSelection) selection;
            if (tSelection.getLength() != 0) {
                return;
            }
        }
    }
    IDocument document = targetEditor.getDocument();
    int carretOffset = targetEditor.getCarretOffset();
    PairMatcher pairMatcher = new PairMatcher();
    IRegion region = pairMatcher.match(document, carretOffset);
    if (region == null) {
        return;
    }
    int targetOffset;
    if (region.getOffset() + 1 == carretOffset) {
        targetOffset = region.getOffset() + region.getLength();
    } else {
        targetOffset = region.getOffset() + 1;
    }
    targetEditor.setCarretOffset(targetOffset);
    targetEditor.selectAndReveal(targetOffset, 0);
}
Also used : PairMatcher(org.eclipse.titan.designer.editors.ttcnppeditor.PairMatcher) TextSelection(org.eclipse.jface.text.TextSelection) IDocument(org.eclipse.jface.text.IDocument) IRegion(org.eclipse.jface.text.IRegion)

Aggregations

IDocument (org.eclipse.jface.text.IDocument)2 IRegion (org.eclipse.jface.text.IRegion)2 TextSelection (org.eclipse.jface.text.TextSelection)2 PairMatcher (org.eclipse.titan.designer.editors.ttcnppeditor.PairMatcher)2 TTCNPPEditor (org.eclipse.titan.designer.editors.ttcnppeditor.TTCNPPEditor)1 IEditorPart (org.eclipse.ui.IEditorPart)1