示例#1
0
 private void selectBraces(final EditorCell selectedCell) {
   final Pair<EditorCell, String> pair = getMatchingLabelAndCell(selectedCell);
   if (pair != null) {
     final EditorCell matchigCell = pair.o1;
     EditorCell validCellForNode =
         ((EditorComponent) matchigCell.getEditorComponent())
             .getBigValidCellForNode(matchigCell.getSNode());
     if (validCellForNode != null) {
       EditorCell editorCell =
           CellFinderUtil.findChildByCondition(
               validCellForNode,
               new Condition<EditorCell>() {
                 @Override
                 public boolean met(EditorCell cell) {
                   return cell != matchigCell
                       && cell.getSNode() == matchigCell.getSNode()
                       && pair.o2.equals(cell.getStyle().get(StyleAttributes.MATCHING_LABEL));
                 }
               },
               true);
       if (editorCell != null) {
         if (editorCell.getY() != matchigCell.getY()) {
           ((EditorComponent) matchigCell.getEditorComponent())
               .leftHighlightCells(
                   (jetbrains.mps.nodeEditor.cells.EditorCell) matchigCell,
                   (jetbrains.mps.nodeEditor.cells.EditorCell) editorCell,
                   BRACES_LEFT_HIGHTLIGHT_COLOR);
         }
         hightlightCell(editorCell);
         hightlightCell(matchigCell);
       }
     }
   }
 }
示例#2
0
 @Override
 protected boolean suppressDelete(CellActionType type) {
   if (!super.suppressDelete(type)) {
     return false;
   }
   EditorCell_Label label = getEditorCellLabel();
   if (label.getText().length() == 0) {
     return false;
   }
   if (label instanceof EditorCell_Constant || label instanceof EditorCell_Property) {
     return label.isEditable()
         || CellFinderUtil.findLastSelectableLeaf(APICellAdapter.getContainingBigCell(label))
             != label;
   }
   return true;
 }
  @Override
  public void execute(EditorContext context) {
    LOG.assertInCommand();
    EditorComponent editorComponent = (EditorComponent) context.getEditorComponent();
    EditorCell selectedCell = editorComponent.getSelectedCell();
    SNode anchorNode = selectedCell.getSNode();

    PasteNodeData pasteNodeData =
        CopyPasteUtil.getPasteNodeDataFromClipboard(anchorNode.getModel());
    if (pasteNodeData == null || pasteNodeData.getNodes().isEmpty()) {
      pasteNodeData =
          CopyPasteUtil.getConvertedFromClipboard(
              anchorNode.getModel(), context.getOperationContext().getProject());
      if (pasteNodeData == null) return;
    }
    List<SNode> pasteNodes = pasteNodeData.getNodes();
    Set<SReference> requireResolveReferences = pasteNodeData.getRequireResolveReferences();

    new NodePaster(pasteNodes).pasteRelative(anchorNode, myPastePlaceHint);
    ResolverComponent.getInstance()
        .resolveScopesOnly(requireResolveReferences, context.getOperationContext());

    // set selection
    editorComponent.flushEvents();
    EditorCell nodeCell = editorComponent.findNodeCell(pasteNodes.get(0));
    if (nodeCell == null) return; // after 'set reference'?
    EditorCell_Label labelCell =
        CellFinderUtil.findChildByClass(nodeCell, EditorCell_Label.class, true);

    if (labelCell != null) {
      editorComponent.changeSelection(labelCell);
    }

    if (pasteNodes.size() == 1) {
      editorComponent.pushSelection(nodeCell);
    } else {
      SelectionManager selectionManager = editorComponent.getSelectionManager();
      selectionManager.pushSelection(
          selectionManager.createRangeSelection(
              pasteNodes.get(0), pasteNodes.get(pasteNodes.size() - 1)));
    }
  }
示例#4
0
  public void execute(EditorContext editorContext) {
    EditorCell selectedCell = editorContext.getSelectedCell();
    if (selectedCell == null) {
      return;
    }
    final String cellId = selectedCell.getCellId();
    SNode actualSelectedNode = selectedCell.getSNode();
    boolean isLabel = selectedCell instanceof EditorCell_Label;
    int startPosition = (isLabel ? ((EditorCell_Label) selectedCell).getSelectionStart() : -1);
    int endPosition = (isLabel ? ((EditorCell_Label) selectedCell).getSelectionEnd() : -1);
    SNode nodeToSelect = CommentUtil.commentOut(myNode);
    editorContext.flushEvents();
    if (cellId != null) {
      EditorCell newNodeCell = editorContext.getEditorComponent().findNodeCell(actualSelectedNode);
      if (newNodeCell != null) {
        EditorCell cellToSelect =
            CellFinderUtil.findChildByCondition(
                newNodeCell,
                new Condition<EditorCell>() {
                  public boolean met(EditorCell cell) {
                    return eq_9lx3n0_a0a0a0a1a0a0b0j0h(cell.getCellId(), cellId);
                  }
                },
                true,
                true);
        if (cellToSelect != null) {
          if (isLabel) {
            editorContext
                .getSelectionManager()
                .setSelection(actualSelectedNode, cellId, startPosition, endPosition);
          } else {
            editorContext.getSelectionManager().setSelection(actualSelectedNode, cellId);
          }

          return;
        }
      }
    }
    SelectionUtil.selectCell(editorContext, nodeToSelect, SelectionManager.LAST_EDITABLE_CELL);
  }