Search in sources :

Example 1 with PairMatcher

use of org.eclipse.titan.designer.editors.configeditor.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 (targetEditor.getActiveEditor() != targetEditor.getEditor()) {
        return;
    }
    if (!selection.isEmpty()) {
        if (selection instanceof TextSelection) {
            TextSelection tSelection = (TextSelection) selection;
            if (tSelection.getLength() != 0) {
                return;
            }
        }
    }
    ConfigTextEditor textEditor = targetEditor.getEditor();
    IDocument document = textEditor.getDocument();
    int carretOffset = textEditor.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;
    }
    textEditor.setCarretOffset(targetOffset);
    textEditor.selectAndReveal(targetOffset, 0);
}
Also used : PairMatcher(org.eclipse.titan.designer.editors.configeditor.PairMatcher) TextSelection(org.eclipse.jface.text.TextSelection) ConfigTextEditor(org.eclipse.titan.designer.editors.configeditor.ConfigTextEditor) IDocument(org.eclipse.jface.text.IDocument) IRegion(org.eclipse.jface.text.IRegion)

Example 2 with PairMatcher

use of org.eclipse.titan.designer.editors.configeditor.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 ConfigEditor) {
        this.targetEditor = (ConfigEditor) activeEditor;
    } else {
        this.targetEditor = null;
    }
    if (activeEditor == null) {
        return null;
    }
    if (this.targetEditor.getActiveEditor() != this.targetEditor.getEditor()) {
        return null;
    }
    if (!selection.isEmpty()) {
        if (selection instanceof TextSelection) {
            TextSelection tSelection = (TextSelection) selection;
            if (tSelection.getLength() != 0) {
                return null;
            }
        }
    }
    ConfigTextEditor textEditor = this.targetEditor.getEditor();
    IDocument document = textEditor.getDocument();
    int carretOffset = textEditor.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;
    }
    textEditor.setCarretOffset(targetOffset);
    textEditor.selectAndReveal(targetOffset, 0);
    return null;
}
Also used : PairMatcher(org.eclipse.titan.designer.editors.configeditor.PairMatcher) TextSelection(org.eclipse.jface.text.TextSelection) ConfigEditor(org.eclipse.titan.designer.editors.configeditor.ConfigEditor) ConfigTextEditor(org.eclipse.titan.designer.editors.configeditor.ConfigTextEditor) 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 ConfigTextEditor (org.eclipse.titan.designer.editors.configeditor.ConfigTextEditor)2 PairMatcher (org.eclipse.titan.designer.editors.configeditor.PairMatcher)2 ConfigEditor (org.eclipse.titan.designer.editors.configeditor.ConfigEditor)1 IEditorPart (org.eclipse.ui.IEditorPart)1