public boolean processKeyPressed(final EditorContext editorContext, final KeyEvent keyEvent) { EditorComponent nodeEditor = editorContext.getNodeEditorComponent(); nodeEditor.hideMessageToolTip(); if (processKeyMaps(editorContext, keyEvent)) { return true; } jetbrains.mps.openapi.editor.cells.CellActionType actionType = editorContext.getNodeEditorComponent().getActionType(keyEvent, editorContext); EditorCell selectedCell = editorContext.getSelectedCell(); // process action if (selectedCell != null && actionType != null && editorContext .getEditorComponent() .getActionHandler() .executeAction(selectedCell, actionType)) { return true; } // special case - don't allow kbd focus to leave editor area if (keyEvent.getKeyCode() == KeyEvent.VK_UP && keyEvent.isControlDown() && !keyEvent.isAltDown() && !keyEvent.isShiftDown()) { keyEvent.consume(); } return false; }
@Override public void execute(final jetbrains.mps.openapi.editor.EditorContext context) { EditorComponent editorComponent = ((EditorComponent) context.getEditorComponent()); SelectionManager selectionManager = editorComponent.getSelectionManager(); Selection selection = selectionManager.getSelection(); if (selection instanceof SingularSelection) { EditorCell selectedCell = ((SingularSelection) selection).getEditorCell(); SNode selectedNode = selectedCell.getSNode(); SNode topMostNodeInSingularContainment = findTopMostNodeWithSingularContainment(selectedNode); if (topMostNodeInSingularContainment != selectedNode) { EditorCell nodeCell = editorComponent.findNodeCell(topMostNodeInSingularContainment); if (nodeCell != null) { editorComponent.pushSelection(nodeCell); editorComponent.scrollToCell(nodeCell); } } else { Selection newSelection = selectionManager.createRangeSelection(selectedNode, selectedNode); if (newSelection instanceof NodeRangeSelection && selectedCell.isBigCell()) { newSelection = ((NodeRangeSelection) newSelection).enlargeSelection(myUp); } if (newSelection != null) { selectionManager.pushSelection(newSelection); newSelection.ensureVisible(); } } } else if (selection instanceof NodeRangeSelection) { Selection newSelection = ((NodeRangeSelection) selection).enlargeSelection(myUp); if (newSelection != null) { selectionManager.pushSelection(newSelection); newSelection.ensureVisible(); } } }
public void execute(jetbrains.mps.openapi.editor.EditorContext context) { EditorComponent editorComponent = ((EditorComponent) context.getEditorComponent()); EditorCell target = findTarget(editorComponent); if (target instanceof EditorCell_Label) { EditorCell_Label label = (EditorCell_Label) target; label.end(); editorComponent.resetLastCaretX(); } editorComponent.changeSelection(target); }
public void execute(jetbrains.mps.openapi.editor.EditorContext context) { EditorCell selectedCell = getDeepestSelectedCell(context); int caretX = selectedCell.getCaretX(); EditorComponent editorComponent = (EditorComponent) context.getEditorComponent(); if (editorComponent.hasLastCaretX()) { caretX = editorComponent.getLastCaretX(); } editorComponent.saveLastCaretX(caretX); EditorCell target = findTarget(selectedCell, caretX); target.setCaretX(caretX); editorComponent.changeSelection(target, false); }
public boolean processKeyTyped(EditorContext editorContext, final KeyEvent keyEvent) { EditorComponent nodeEditor = editorContext.getNodeEditorComponent(); nodeEditor.hideMessageToolTip(); if (processKeyMaps(editorContext, keyEvent)) { return true; } final EditorCell selectedCell = editorContext.getSelectedCell(); if (selectedCell != null && ((jetbrains.mps.nodeEditor.cells.EditorCell) selectedCell) .processKeyTyped(keyEvent, false)) { keyEvent.consume(); return true; } jetbrains.mps.openapi.editor.cells.CellActionType actionType = editorContext.getNodeEditorComponent().getActionType(keyEvent, editorContext); if (selectedCell != null) { boolean strictMatching = jetbrains.mps.openapi.editor.cells.CellActionType.RIGHT_TRANSFORM.equals(actionType) || jetbrains.mps.openapi.editor.cells.CellActionType.LEFT_TRANSFORM.equals( actionType); if (selectedCell.isErrorState() && strictMatching) { if (APICellAdapter.validate(selectedCell, strictMatching, false)) { return true; } } if (actionType != null) { if (editorContext .getEditorComponent() .getActionHandler() .executeAction(selectedCell, actionType)) { return true; } } } if (selectedCell != null && ((jetbrains.mps.nodeEditor.cells.EditorCell) selectedCell) .processKeyTyped(keyEvent, true)) { keyEvent.consume(); return true; } return false; }
@Override public boolean acceptCell(EditorCell cell, EditorComponent editor) { if (cell == null) { return false; } return cell.isBig() && editor.isValid(cell) && cell.getSNode() == getNode(); }
@Override public EditorCell getCell(EditorComponent editor) { if (editor == null) { return null; } return editor.getBigValidCellForNode(getNode()); }
public void actionPerformed(ActionEvent e) { int i = pane.indexOfTabComponent(ButtonTabComponent.this); if (i != -1) { // check for EditorComponent and ask questions Component c = pane.getComponentAt(i); if (c instanceof EditorComponent) { EditorComponent editorComponent = (EditorComponent) c; if (editorComponent.needsSaving()) { if (editorComponent.attemptClose()) { pane.remove(i); } } } else { pane.remove(i); } } }
private void clearBracesSelection() { for (EditorCell editorCell : myHighlightedCellStyles.keySet()) { Style originalStyle = myHighlightedCellStyles.get(editorCell); copyStyleAttributes(originalStyle, editorCell.getStyle()); myEditorComponent.leftUnhighlightCell((jetbrains.mps.nodeEditor.cells.EditorCell) editorCell); } myHighlightedCellStyles.clear(); }
private EditorCell findTarget(EditorComponent editorComponent) { Selection selection = editorComponent.getSelectionManager().getSelection(); if (selection == null) { return null; } List<EditorCell> selectedCells = selection.getSelectedCells(); EditorCell cell = selectedCells.get(selectedCells.size() - 1); return cell.getEndCell(CellConditions.SELECTABLE); }
protected EditorCell getCellInBothWays(final EditorComponent editor) { return new ModelAccessHelper(editor.getRepository()) .runReadAction( () -> { EditorCell editorCell = getCell(editor); if (editorCell != null) { return editorCell; } return getCellForParentNodeInMainEditor(editor); }); }
@Override public void dispose() { notifyDisposal(); InspectorTool inspectorTool = getInspectorTool(); if (inspectorTool != null) { if (inspectorTool.getInspector().getEditedNode() == this.getLastInspectedNode()) { inspectorTool.inspect(null, null, null, null); } } myLastInspectedNode = null; super.dispose(); }
@Override public EditorCell getCellForParentNodeInMainEditor(final EditorComponent editor) { return new ModelAccessHelper(editor.getRepository()) .runReadAction( () -> { if (getNode() == null) { return null; } if (editor instanceof InspectorEditorComponent) { return null; } SNode parent = getNode().getParent(); while (parent != null) { EditorCell result = editor.getBigValidCellForNode(parent); if (result != null) { return result; } parent = parent.getParent(); } return null; }); }
private static void navigatePage( jetbrains.mps.openapi.editor.EditorContext context, boolean isDown) { EditorComponent editor = (EditorComponent) context.getEditorComponent(); jetbrains.mps.openapi.editor.cells.EditorCell selection = editor.getSelectedCell(); Rectangle rect = editor.getVisibleRect(); int height = (int) rect.getHeight(); height = isDown ? height : -height; int caretX = selection.getCaretX(); int y = selection.getY() + (selection.getHeight() / 2); int newY = y + height; jetbrains.mps.openapi.editor.cells.EditorCell target = editor.findCellWeak(caretX, newY); if (target == null) { target = isDown ? editor.myRootCell.findChild(CellFinders.LAST_SELECTABLE_LEAF) : editor.myRootCell.findChild(CellFinders.FIRST_SELECTABLE_LEAF); editor.changeSelection(target); } else { target.setCaretX(caretX); editor.changeSelection(target); } }
@Override public void rebuildEditorContent() { if (isValidEditor()) { super.rebuildEditorContent(); } }
public BracesHighlighter(EditorComponent editorComponent) { this.myEditorComponent = editorComponent; myEditorComponent.getSelectionManager().addSelectionListener(mySelectionListener); }
public void execute(jetbrains.mps.openapi.editor.EditorContext context) { EditorComponent editorComponent = (EditorComponent) context.getEditorComponent(); EditorCell selection = editorComponent.getSelectedCell(); editorComponent.changeSelection(selection.getPrevLeaf(CellConditions.EDITABLE)); }
@Override public void doNavigate(EditorComponent editorComponent) { editorComponent.changeSelection(getCellInBothWays(editorComponent)); }