Search in sources :

Example 1 with PairMatcher

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

the class GotoMatchingBracketAction method run.

@Override
public final 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.asn1editor.PairMatcher) TextSelection(org.eclipse.jface.text.TextSelection) IDocument(org.eclipse.jface.text.IDocument) IRegion(org.eclipse.jface.text.IRegion)

Example 2 with PairMatcher

use of org.eclipse.titan.designer.editors.asn1editor.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 ASN1Editor) {
        this.targetEditor = (ASN1Editor) 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 : ASN1Editor(org.eclipse.titan.designer.editors.asn1editor.ASN1Editor) PairMatcher(org.eclipse.titan.designer.editors.asn1editor.PairMatcher) TextSelection(org.eclipse.jface.text.TextSelection) IEditorPart(org.eclipse.ui.IEditorPart) 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.asn1editor.PairMatcher)2 ASN1Editor (org.eclipse.titan.designer.editors.asn1editor.ASN1Editor)1 IEditorPart (org.eclipse.ui.IEditorPart)1