Example #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);
       }
     }
   }
 }
Example #2
0
 static boolean substituteIfPossible(
     EditorCell cell,
     boolean canActivatePopup,
     final String pattern,
     List<SubstituteAction> matchingActions) {
   if (matchingActions.size() == 0 && canActivatePopup) {
     return false;
   }
   if (matchingActions.size() != 1) {
     if (canActivatePopup) {
       ((EditorComponent) cell.getEditorComponent()).activateNodeSubstituteChooser(cell, false);
     } else {
       return false;
     }
     return true;
   }
   final SubstituteAction action = matchingActions.get(0);
   Boolean canSubstitute =
       ModelAccess.instance()
           .runReadAction(
               new Computable<Boolean>() {
                 @Override
                 public Boolean compute() {
                   return action.canSubstitute(pattern);
                 }
               });
   if (canSubstitute) {
     action.substitute(cell.getContext(), pattern);
     return true;
   } else {
     return false;
   }
 }
Example #3
0
  private boolean canPasteBefore(EditorCell selectedCell, List<SNode> pasteNodes) {
    if (!APICellAdapter.isFirstPositionInBigCell(selectedCell)) return false;
    SNode anchor = selectedCell.getSNode();
    if (anchor.getParent() == null) return false;

    NodeAndRole nodeAndRole =
        new NodePaster(pasteNodes).getActualAnchorNode(anchor, anchor.getRoleInParent(), false);
    if (nodeAndRole == null) return false;

    EditorCell targetCell = selectedCell.getEditorComponent().findNodeCell(nodeAndRole.myNode);
    return targetCell != null
        && ((jetbrains.mps.nodeEditor.cells.EditorCell) targetCell)
                .getFirstLeaf(CellConditions.SELECTABLE)
            == selectedCell
        && new NodePaster(pasteNodes).canPasteRelative(nodeAndRole.myNode);
  }
 public void highlight(EditorCell cell, EditorCell cell2, Color c) {
   assert SwingUtilities.isEventDispatchThread()
       : "LeftEditorHighlighter.unHighlight() should be called in eventDispatchThread";
   assert cell.getEditorComponent() == myEditorComponent : "cell must be from my editor";
   myBracketsPainter.addBracket(cell, cell2, c);
 }