示例#1
0
  private boolean processSideDeletes(CellActionType type) {
    // TODO: review this logic - it was originally copied from EditorComponentKeyboardHandler
    final EditorCell selectedCell = getEditorCell();
    if (type == CellActionType.DELETE
        && selectedCell.isLastPositionInBigCell()
        && !selectedCell.isFirstPositionInBigCell()) {
      final EditorCell target;
      if (selectedCell.isLastPositionInBigCell()
          && selectedCell.getContainingBigCell().getNextSibling() != null) {
        target = selectedCell.getContainingBigCell().getNextSibling();
      } else if (selectedCell.getNextSibling() != null) {
        target = selectedCell.getNextSibling();
      } else {
        target = selectedCell.getNextLeaf(CellConditions.SELECTABLE);
      }

      if (target == null
          || ModelAccess.instance()
              .runReadAction(
                  new Computable<Boolean>() {
                    public Boolean compute() {
                      return target.getSNode().isAncestorOf(selectedCell.getSNode());
                    }
                  })) return false;

      return target.executeAction(CellActionType.DELETE);
    }

    if (type == CellActionType.BACKSPACE
        && selectedCell.isFirstPositionInBigCell()
        && !selectedCell.isLastPositionInBigCell()) {
      final EditorCell target;
      if (selectedCell.isFirstPositionInBigCell()
          && selectedCell.getContainingBigCell().getPrevSibling() != null) {
        target = selectedCell.getContainingBigCell().getPrevSibling();
      } else if (selectedCell.getPrevSibling() != null) {
        target = selectedCell.getPrevSibling();
      } else {
        target = selectedCell.getPrevLeaf(CellConditions.SELECTABLE);
      }

      if (target == null) return false;
      /*
      if (ModelAccess.instance().runReadAction(new Computable<Boolean>() {
        public Boolean compute() {
          return target.getSNode().isAncestorOf(selectedCell.getSNode());
        }
      })) return false;
      */
      return target.executeAction(CellActionType.DELETE);
    }
    return false;
  }
示例#2
0
  public List<INodeSubstituteAction> createActions() {
    if (myLinkDeclaration == null) {
      return Collections.emptyList();
    }
    EditorComponent editor = mySubstituteInfo.getEditorContext().getNodeEditorComponent();
    EditorCell referenceCell =
        editor.findNodeCellWithRole(
            mySourceNode,
            ((String)
                BehaviorManager.getInstance()
                    .invoke(
                        Object.class,
                        SNodeOperations.cast(
                            myLinkDeclaration,
                            "jetbrains.mps.lang.structure.structure.LinkDeclaration"),
                        "call_getGenuineRole_1213877254542",
                        new Class[] {SNode.class})));

    if (referenceCell != null
        && referenceCell.getContainingBigCell().getFirstLeaf() == referenceCell
        && ReferenceConceptUtil.getCharacteristicReference(
                SNodeOperations.getConceptDeclaration(mySourceNode))
            == myLinkDeclaration
        && SNodeOperations.getParent(mySourceNode) != null
        && ListSequence.fromList(SNodeOperations.getChildren(mySourceNode)).isEmpty()) {
      SNode parent = SNodeOperations.getParent(mySourceNode);
      String role = SNodeOperations.getContainingLinkRole(mySourceNode);
      SNode roleLink =
          SNodeOperations.cast(
              parent.getLinkDeclaration(role),
              "jetbrains.mps.lang.structure.structure.LinkDeclaration");
      return ModelActions.createChildSubstituteActions(
          parent,
          mySourceNode,
          SLinkOperations.getTarget(roleLink, "target", false),
          new DefaultChildNodeSetter(roleLink),
          mySubstituteInfo.getOperationContext());
    }
    return ModelActions.createReferentSubstituteActions(
        mySourceNode, myCurrentReferent, myLinkDeclaration, mySubstituteInfo.getOperationContext());
  }