Search in sources :

Example 6 with ITextualEntityPart

use of org.whole.lang.ui.editparts.ITextualEntityPart in project whole by wholeplatform.

the class TextualDragTracker method handleButtonDown.

@Override
protected boolean handleButtonDown(int button) {
    ITextualEntityPart textualEntityPart = getTextualEntityPart();
    if (button != 1 || textualEntityPart == null) {
        beginPart = endPart = null;
        start = end = 0;
        setState(STATE_INVALID);
        return handleInvalidInput();
    } else {
        beginPart = endPart = textualEntityPart;
        CaretUpdater.sheduleSyncUpdate(getCurrentViewer(), beginPart.getModelEntity(), getLocation(), true);
        start = textualEntityPart.getCaretPosition();
        return stateTransition(STATE_INITIAL, STATE_SELECT);
    }
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart)

Example 7 with ITextualEntityPart

use of org.whole.lang.ui.editparts.ITextualEntityPart in project whole by wholeplatform.

the class TextualDragTracker method handleTripleClick.

protected boolean handleTripleClick(int button) {
    ITextualEntityPart textualEntityPart = getTextualEntityPart();
    if (button == 1 && textualEntityPart != null) {
        IGEFEditorKit editorkit = (IGEFEditorKit) textualEntityPart.getModelEntity().wGetEditorKit();
        EditPoint editPoint = new EditPoint(textualEntityPart, textualEntityPart.getCaretPosition());
        IKeyHandler keyHandler = editorkit.getKeyHandler();
        IWholeSelection selection = keyHandler.calculateTripleClickSelection(editPoint);
        performSelectionUpdate(selection, true);
        return true;
    }
    return false;
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) IGEFEditorKit(org.whole.lang.ui.editor.IGEFEditorKit) IKeyHandler(org.whole.lang.ui.keys.IKeyHandler)

Example 8 with ITextualEntityPart

use of org.whole.lang.ui.editparts.ITextualEntityPart in project whole by wholeplatform.

the class ActivateToolAction method run.

@Override
public void run() {
    ESelectionService selectionService = getContext().get(ESelectionService.class);
    IBindingManager bm = (IBindingManager) selectionService.getSelection();
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    boolean clearCaret = Tools.TEXTUAL != tool && Tools.TEXTUAL.isActive(viewer);
    if (tool.ensureActive(viewer) && clearCaret) {
        IEntity focusEntity = bm.wGet("focusEntity");
        IEntityPart focusPart = viewer.getEditPartRegistry().get(focusEntity);
        if (focusPart instanceof ITextualEntityPart) {
            ITextualEntityPart textualPart = (ITextualEntityPart) focusPart;
            textualPart.setCaretVisible(false);
            viewer.setSelection(new StructuredSelection(textualPart));
        }
    }
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Example 9 with ITextualEntityPart

use of org.whole.lang.ui.editparts.ITextualEntityPart 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 10 with ITextualEntityPart

use of org.whole.lang.ui.editparts.ITextualEntityPart in project whole by wholeplatform.

the class E4NavigationKeyHandler method navigateNextSibling.

/**
 * Traverses to the closest EditPart in the given list that is also in the given direction.
 *
 * @param	event		the KeyEvent for the keys that were pressed to trigger this traversal
 * @param	direction	PositionConstants.* indicating the direction in which to traverse
 */
boolean navigateNextSibling(KeyEvent event, int direction, List<?> list) {
    IEntityPart epStart = getFocusEntityPart();
    if (epStart instanceof ITextualEntityPart) {
        ITextualEntityPart textualEntityPart = (ITextualEntityPart) epStart;
        ITextualFigure textualFigure = textualEntityPart.getTextualFigure();
        String text = textualFigure.getText();
        int line = CaretUtils.getLineFromPosition(text, textualEntityPart.getCaretPosition());
        int lines = CaretUtils.getCaretLines(text);
        if ((direction == PositionConstants.WEST && textualEntityPart.getCaretPosition() > 0) || (direction == PositionConstants.EAST && textualEntityPart.getCaretPosition() < textualEntityPart.getCaretPositions())) {
            int position = textualEntityPart.getCaretPosition() + (direction == PositionConstants.WEST ? -1 : 1);
            CaretUpdater.sheduleSyncUpdate(getViewer(), textualEntityPart.getModelEntity(), position, true);
            return true;
        } else if ((direction == PositionConstants.NORTH && line > 0) || (direction == PositionConstants.SOUTH && line < lines)) {
            int dy = FigureUtilities.getFontMetrics(textualFigure.getFont()).getHeight() * (direction == PositionConstants.NORTH ? -1 : 1);
            Point location = textualFigure.getCaretBounds().getCenter().translate(0, dy);
            CaretUpdater.sheduleSyncUpdate(getViewer(), textualEntityPart.getModelEntity(), location, true);
            textualEntityPart.updateCaret(location);
            return true;
        }
    }
    if (!(epStart instanceof IGraphicalEntityPart))
        return false;
    IFigure figure = ((IGraphicalEntityPart) epStart).getFigure();
    Point pStart = getNavigationPoint(figure);
    figure.translateToAbsolute(pStart);
    // parent.findSibling(pStart, direction, epStart);
    EditPart next = findSibling(list, pStart, direction, epStart);
    while (next == null) {
        if (!(epStart.getParent() instanceof IGraphicalEntityPart))
            return false;
        epStart = (IGraphicalEntityPart) epStart.getParent();
        if (epStart == getViewer().getContents() || epStart.getParent() == getViewer().getContents() || epStart.getParent() == null)
            return false;
        list = epStart.getParent().getChildren();
        next = findSibling(list, pStart, direction, epStart);
    }
    // next = next.enter(pStart, direction, epStart);1+2
    navigateTo(next, event);
    return true;
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) IGraphicalEntityPart(org.whole.lang.ui.editparts.IGraphicalEntityPart) ConnectionEditPart(org.eclipse.gef.ConnectionEditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) EditPart(org.eclipse.gef.EditPart) Point(org.eclipse.draw2d.geometry.Point) EditPoint(org.whole.lang.ui.tools.EditPoint) ITextualFigure(org.whole.lang.ui.figures.ITextualFigure) IEntityPart(org.whole.lang.ui.editparts.IEntityPart) Point(org.eclipse.draw2d.geometry.Point) EditPoint(org.whole.lang.ui.tools.EditPoint) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

ITextualEntityPart (org.whole.lang.ui.editparts.ITextualEntityPart)29 Point (org.eclipse.draw2d.geometry.Point)8 IEntity (org.whole.lang.model.IEntity)8 Command (org.eclipse.gef.commands.Command)6 ITextCommand (org.whole.lang.ui.commands.ITextCommand)5 TextTransactionCommand (org.whole.lang.ui.commands.TextTransactionCommand)5 IEntityPart (org.whole.lang.ui.editparts.IEntityPart)5 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)5 EditPart (org.eclipse.gef.EditPart)4 BackspaceTextCommand (org.whole.lang.ui.commands.BackspaceTextCommand)4 DeleteTextCommand (org.whole.lang.ui.commands.DeleteTextCommand)4 InsertTextCommand (org.whole.lang.ui.commands.InsertTextCommand)4 OverwriteTextCommand (org.whole.lang.ui.commands.OverwriteTextCommand)4 Rectangle (org.eclipse.draw2d.geometry.Rectangle)3 IGEFEditorKit (org.whole.lang.ui.editor.IGEFEditorKit)3 ITextualFigure (org.whole.lang.ui.figures.ITextualFigure)3 IKeyHandler (org.whole.lang.ui.keys.IKeyHandler)3 EditPoint (org.whole.lang.ui.tools.EditPoint)3 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)2 Execute (org.eclipse.e4.core.di.annotations.Execute)2