Search in sources :

Example 1 with TreeKeyEventListener

use of org.terasology.rendering.nui.widgets.treeView.TreeKeyEventListener in project Terasology by MovingBlocks.

the class UITreeView method onKeyEvent.

@Override
public boolean onKeyEvent(NUIKeyEvent event) {
    for (TreeKeyEventListener listener : keyEventListeners) {
        listener.onKeyEvent(event);
    }
    if (event.isDown()) {
        int id = event.getKey().getId();
        KeyboardDevice keyboard = event.getKeyboard();
        boolean ctrlDown = keyboard.isKeyDown(Keyboard.KeyId.RIGHT_CTRL) || keyboard.isKeyDown(Keyboard.KeyId.LEFT_CTRL);
        if (id == Keyboard.KeyId.UP || id == Keyboard.KeyId.DOWN) {
            // Up/Down: change a node's position within the parent node.
            return moveSelected(id);
        } else if (id == Keyboard.KeyId.DELETE) {
            // Delete: remove a node (and all its' children).
            return removeSelected();
        } else if (ctrlDown && id == Keyboard.KeyId.C) {
            // Ctrl+C: copy a selected node.
            if (state.getSelectedIndex() != null) {
                copy(model.get().getNode(state.getSelectedIndex()));
                return true;
            }
            return false;
        } else if (ctrlDown && id == Keyboard.KeyId.V) {
            // Ctrl+V: paste the copied node as a child of the currently selected node.
            if (state.getSelectedIndex() != null) {
                paste(model.get().getNode(state.getSelectedIndex()));
                return true;
            }
            return false;
        } else {
            return false;
        }
    }
    return false;
}
Also used : KeyboardDevice(org.terasology.input.device.KeyboardDevice) TreeKeyEventListener(org.terasology.rendering.nui.widgets.treeView.TreeKeyEventListener)

Aggregations

KeyboardDevice (org.terasology.input.device.KeyboardDevice)1 TreeKeyEventListener (org.terasology.rendering.nui.widgets.treeView.TreeKeyEventListener)1