Search in sources :

Example 1 with EditPoint

use of org.whole.lang.ui.tools.EditPoint in project whole by wholeplatform.

the class TextualKeyHandler method calculateDoubleClickSelection.

public IWholeSelection calculateDoubleClickSelection(EditPoint editPoint) {
    ITextualEntityPart targetPart = (ITextualEntityPart) editPoint.focus;
    IEntity targetEntity = targetPart.getModelEntity();
    int endPosition = -1, startPosition = -1;
    if (enableSmartSelection(targetEntity)) {
        String text = targetEntity.wStringValue();
        int position = targetPart.getCaretPosition();
        int positions = targetPart.getCaretPositions();
        Matcher matcher;
        if (position == 0) {
            matcher = RIGHT_PATTERN.matcher(text);
            if (matcher.find()) {
                startPosition = 0;
                endPosition = matcher.end();
            }
        } else if (position == positions) {
            matcher = LEFT_PATTERN.matcher(text);
            if (matcher.find()) {
                startPosition = matcher.start();
                endPosition = positions;
            }
        } else {
            if (Character.isLetterOrDigit(text.charAt(position))) {
                if (Character.isLetterOrDigit(text.charAt(position - 1))) {
                    // XX
                    String substring = text.substring(0, position);
                    matcher = LEFT_PATTERN.matcher(substring);
                    if (matcher.find())
                        startPosition = matcher.start();
                    matcher = RIGHT_PATTERN.matcher(text.substring(position));
                    if (matcher.find())
                        endPosition = position + matcher.end();
                } else {
                    // .X
                    matcher = RIGHT_PATTERN.matcher(text.substring(position));
                    if (matcher.find()) {
                        startPosition = position + matcher.start();
                        endPosition = position + matcher.end();
                    }
                }
            } else {
                if (Character.isLetterOrDigit(text.charAt(position - 1))) {
                    // X.
                    matcher = LEFT_PATTERN.matcher(text.substring(0, position));
                    if (matcher.find()) {
                        startPosition = matcher.start();
                        endPosition = position;
                    }
                } else {
                    // ..
                    startPosition = position - 1;
                    endPosition = position;
                }
            }
        }
    }
    if (endPosition >= 0 && startPosition >= 0)
        return new SelectionRange(editPoint.focus, startPosition, endPosition);
    else
        return super.calculateDoubleClickSelection(editPoint);
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) IEntity(org.whole.lang.model.IEntity) Matcher(java.util.regex.Matcher) SelectionRange(org.whole.lang.ui.tools.SelectionRange) EditPoint(org.whole.lang.ui.tools.EditPoint)

Example 2 with EditPoint

use of org.whole.lang.ui.tools.EditPoint in project whole by wholeplatform.

the class E4NavigationKeyHandler method getEditPoint.

public EditPoint getEditPoint() {
    if (editPoint == null)
        editPoint = new EditPoint((IEntityPart) getFocusEntityPart(), 0);
    else {
        IEntityPart focusPart = (IEntityPart) getFocusEntityPart();
        if (editPoint.focus != focusPart) {
            editPoint.focus = focusPart;
            editPoint.caret = 0;
        }
    }
    return editPoint;
}
Also used : EditPoint(org.whole.lang.ui.tools.EditPoint) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Example 3 with EditPoint

use of org.whole.lang.ui.tools.EditPoint in project whole by wholeplatform.

the class E4NavigationKeyHandler method navigateView.

public boolean navigateView(KeyEvent event, int direction) {
    EditPoint focusPoint = getEditPoint();
    IGEFEditorKit editorKit = (IGEFEditorKit) focusPoint.focus.getModelEntity().wGetEditorKit();
    IKeyHandler keyHandler = editorKit.getKeyHandler();
    // FIXME workaround for a bug in navigation actions
    if (focusPoint.focus instanceof ITextualEntityPart) {
        ITextualEntityPart part = (ITextualEntityPart) focusPoint.focus;
        int start = part.getSelectionStart();
        int end = part.getSelectionEnd();
        if (start != -1 && end != -1) {
            CaretUpdater.sheduleSyncUpdate(part.getViewer(), part.getModelTextEntity(), direction == PositionConstants.WEST ? start : end, true);
            return true;
        } else {
            CaretUpdater.sheduleSyncUpdate(part.getViewer(), part.getModelTextEntity(), part.getCaretPosition(), true);
        }
    }
    editPoint = keyHandler.findNeighbour(this, focusPoint, direction);
    if (editPoint == null)
        return navigateNextSibling(event, direction);
    navigateTo(editPoint.focus, event);
    return true;
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) EditPoint(org.whole.lang.ui.tools.EditPoint) IGEFEditorKit(org.whole.lang.ui.editor.IGEFEditorKit) IKeyHandler(org.whole.lang.ui.keys.IKeyHandler) Point(org.eclipse.draw2d.geometry.Point) EditPoint(org.whole.lang.ui.tools.EditPoint)

Example 4 with EditPoint

use of org.whole.lang.ui.tools.EditPoint in project whole by wholeplatform.

the class GrammarsKeyHandler method findNeighbour.

public EditPoint findNeighbour(IEditPointProvider editPointProvider, EditPoint editPoint, int direction) {
    int caret = editPoint.caret;
    IEntityPart focusPart = editPoint.focus;
    IEntity focusEntity = focusPart.getModelEntity();
    switch(focusEntity.wGetEntityOrd()) {
        case GrammarsEntityDescriptorEnum.DataTerminal_ord:
        case GrammarsEntityDescriptorEnum.LiteralTerminal_ord:
        case GrammarsEntityDescriptorEnum.As_ord:
            switch(direction) {
                case NORTH:
                    switch(caret) {
                        case 0:
                        case 1:
                            return findInParent(editPointProvider, editPoint, focusEntity, direction);
                        case 2:
                        case 3:
                            return editPoint.caret(caret - 2);
                    }
                case SOUTH:
                    switch(caret) {
                        case 2:
                        case 3:
                            return findInParent(editPointProvider, editPoint, focusEntity, direction);
                        case 0:
                        case 1:
                            return editPoint.caret(caret + 2);
                    }
                case EAST:
                    switch(caret) {
                        case 0:
                            return findInChild(editPointProvider, editPoint, focusEntity.wGet(0), direction);
                        case 2:
                            return findInChild(editPointProvider, editPoint, focusEntity.wGet(1), direction);
                        case 1:
                        case 3:
                            return findInParent(editPointProvider, editPoint, focusEntity, direction);
                    }
                case WEST:
                    switch(caret) {
                        case 1:
                            return findInChild(editPointProvider, editPoint, focusEntity.wGet(0), direction);
                        case 3:
                            return findInChild(editPointProvider, editPoint, focusEntity.wGet(1), direction);
                        case 0:
                        case 2:
                            return findInParent(editPointProvider, editPoint, focusEntity, direction);
                    }
            }
    }
    return null;
}
Also used : IEntity(org.whole.lang.model.IEntity) EditPoint(org.whole.lang.ui.tools.EditPoint) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Example 5 with EditPoint

use of org.whole.lang.ui.tools.EditPoint in project whole by wholeplatform.

the class E4NavigationKeyHandler method navigateModel.

public boolean navigateModel(KeyEvent event, int direction) {
    EditPoint focusPoint = getEditPoint();
    if (!(focusPoint.focus.getParent() instanceof IEntityPart))
        return false;
    switch(direction) {
        case NORTH:
            IEntityPart parentPart = (IEntityPart) focusPoint.focus.getParent();
            if (isRootPart(parentPart))
                return false;
            editPoint.focus = parentPart;
            break;
        case SOUTH:
            List<?> children = focusPoint.focus.getChildren();
            if (children.isEmpty())
                return false;
            editPoint.focus = (IEntityPart) children.get(0);
            break;
        case EAST:
            parentPart = (IEntityPart) focusPoint.focus.getParent();
            if (isRootPart(parentPart))
                return false;
            List<?> siblings = parentPart.getChildren();
            int index = siblings.indexOf(editPoint.focus);
            if (index < siblings.size() - 1)
                editPoint.focus = findModelFirstChild((IEntityPart) siblings.get(index + 1));
            else
                editPoint.focus = parentPart;
            break;
        case WEST:
            parentPart = (IEntityPart) focusPoint.focus.getParent();
            if (isRootPart(parentPart))
                return false;
            siblings = parentPart.getChildren();
            index = siblings.indexOf(editPoint.focus);
            if (index > 0)
                editPoint.focus = findModelLastChild((IEntityPart) siblings.get(index - 1));
            else
                editPoint.focus = parentPart;
            break;
    }
    editPoint.caret = 0;
    navigateTo(editPoint.focus, event);
    return true;
}
Also used : EditPoint(org.whole.lang.ui.tools.EditPoint) IEntityPart(org.whole.lang.ui.editparts.IEntityPart) Point(org.eclipse.draw2d.geometry.Point) EditPoint(org.whole.lang.ui.tools.EditPoint)

Aggregations

EditPoint (org.whole.lang.ui.tools.EditPoint)5 IEntityPart (org.whole.lang.ui.editparts.IEntityPart)3 Point (org.eclipse.draw2d.geometry.Point)2 IEntity (org.whole.lang.model.IEntity)2 ITextualEntityPart (org.whole.lang.ui.editparts.ITextualEntityPart)2 Matcher (java.util.regex.Matcher)1 IGEFEditorKit (org.whole.lang.ui.editor.IGEFEditorKit)1 IKeyHandler (org.whole.lang.ui.keys.IKeyHandler)1 SelectionRange (org.whole.lang.ui.tools.SelectionRange)1