Example #1
0
    private EditorCell findTarget(SelectionManager selectionManager) {
      Selection selection = selectionManager.getSelection();
      if (selection == null) {
        return null;
      }

      jetbrains.mps.openapi.editor.cells.EditorCell cell = selection.getSelectedCells().get(0);
      if (cell instanceof EditorCell_Label && !((EditorCell_Label) cell).isEverythingSelected()) {
        return (EditorCell) cell;
      }

      if (cell.getParent() == null) {
        return null;
      }

      while (cell.getParent() != null && cell.getParent().isTransparentCollection()) {
        cell = cell.getParent();
      }
      jetbrains.mps.openapi.editor.cells.EditorCell_Collection parent = cell.getParent();
      while (parent != null) {
        if (parent.isSelectable()) {
          while (parent.getParent() != null
              && parent.getParent().isTransparentCollection()
              && parent.getParent().isSelectable()) {
            parent = parent.getParent();
          }
          return (EditorCell) parent;
        }
        parent = parent.getParent();
      }
      return null;
    }
Example #2
0
  /**
   * We can use this method to determine if we should redispatch insert event to the corresponding
   * child collection below the cell returned from cell.getPrevLeaf() or we should go on and insert
   * prev. child into a collection containing cell itself
   *
   * @return true if we should redispatch insert event to the prev. leaft cell
   */
  private static boolean hasSingleRolesAtLeftBoundary(EditorCell cell) {
    if (!(hasSingleRole(cell))) {
      return false;
    }

    if (isOnLeftBoundary(cell)) {
      final EditorCell_Collection parentCell = cell.getParent();
      if (parentCell != null) {
        final EditorCell prevLeaf = APICellAdapter.getPrevLeaf(cell);
        if (prevLeaf != null) {
          final Wrappers._boolean ancestor = new Wrappers._boolean(false);
          ModelAccess.instance()
              .runReadAction(
                  new Runnable() {
                    public void run() {
                      ancestor.value =
                          SNodeOperations.isAncestor(parentCell.getSNode(), prevLeaf.getSNode());
                    }
                  });
          if (ancestor.value) {
            return true;
          }
        }
        return hasSingleRolesAtLeftBoundary((jetbrains.mps.nodeEditor.cells.EditorCell) parentCell);
      }
    }
    return true;
  }
 @Override
 public boolean isAncestorOf(EditorCell cell) {
   while (cell != null) {
     cell = cell.getParent();
     if (cell == this) return true;
   }
   return false;
 }
 @Override
 public boolean canExecute(EditorContext context) {
   jetbrains.mps.openapi.editor.cells.EditorCell cell =
       context.getEditorComponent().findNodeCell(mySemanticNode);
   return cell != null
       && cell.getParent() != null
       && !ReadOnlyUtil.isCellOrSelectionReadOnlyInEditor(context.getEditorComponent(), cell);
 }
Example #5
0
 public static boolean isUnderFolded(EditorCell cell) {
   for (EditorCell_Collection parent = cell.getParent();
       parent != null;
       parent = parent.getParent()) {
     if (parent.isCollapsed()) return true;
   }
   return false;
 }
Example #6
0
 private Pair<EditorCell, String> getMatchingLabelAndCell(EditorCell editorCell) {
   SNode node = editorCell.getSNode();
   while (editorCell != null && editorCell.getSNode() == node) {
     if (editorCell.getStyle().get(StyleAttributes.MATCHING_LABEL) != null) {
       return new Pair(editorCell, editorCell.getStyle().get(StyleAttributes.MATCHING_LABEL));
     }
     editorCell = editorCell.getParent();
   }
   return null;
 }
 @Override
 public void selectionChanged(
     jetbrains.mps.openapi.editor.EditorComponent editorComponent,
     Selection oldSelection,
     Selection newSelection) {
   if (oldSelection == newSelection) {
     return;
   }
   if (myClosingBrace.isSelected() || myOpeningBrace.isSelected()) {
     enableBraces();
     return;
   }
   EditorCell deepestSelection = editorComponent.getDeepestSelectedCell();
   EditorCell lastSelectableLeaf =
       CellFinderUtil.findChildByCondition(
           EditorCell_Collection.this, LAST_SELECTABLE_LEAF_EXCLUDING_BRACE, false);
   EditorCell firstSelectableLeaf =
       CellFinderUtil.findChildByCondition(
           EditorCell_Collection.this, FIRST_SELECTABLE_LEAF_EXCLUDING_BRACE, true);
   if (deepestSelection instanceof EditorCell_Brace) {
     EditorCell_Collection braceOwner = (EditorCell_Collection) deepestSelection.getParent();
     if (braceOwner.myClosingBrace == deepestSelection
         && CellFinderUtil.findChildByCondition(
                 braceOwner, LAST_SELECTABLE_LEAF_EXCLUDING_BRACE, false)
             == lastSelectableLeaf) {
       enableBraces();
       return;
     }
     if (braceOwner.myOpeningBrace == deepestSelection
         && CellFinderUtil.findChildByCondition(
                 braceOwner, FIRST_SELECTABLE_LEAF_EXCLUDING_BRACE, true)
             == firstSelectableLeaf) {
       enableBraces();
       return;
     }
   }
   if (lastSelectableLeaf == deepestSelection || firstSelectableLeaf == deepestSelection) {
     enableBraces();
   } else {
     disableBraces();
   }
 }
  private RestorableSelection saveSelection(EditorContext editorContext) {
    EditorCell selectedCell = editorContext.getSelectedCell();

    if (selectedCell == null || selectedCell instanceof EditorCell_Collection) {
      // No need to save selection, it will be restored by normal means
      return null;
    }

    EditorCell_Collection parent = selectedCell.getParent();
    if (parent.getCellsCount() < EXPECTED_CHILD_INDEX + 1
        || parent.getCellAt(EXPECTED_CHILD_INDEX) != selectedCell) {
      // No need to save selection, it will be restored by normal means
      return null;
    }

    return new RestorableSelectionByCell(
        new ChildCellLocator(
            new CellIdLocator(parent.getCellId(), parent.getSNode()), EXPECTED_CHILD_INDEX),
        createCellSelector(selectedCell));
  }
Example #9
0
    private EditorCell getCommonSelectableAncestor(
        jetbrains.mps.openapi.editor.cells.EditorCell first,
        jetbrains.mps.openapi.editor.cells.EditorCell... cells) {
      jetbrains.mps.openapi.editor.cells.EditorCell_Collection result =
          first instanceof jetbrains.mps.openapi.editor.cells.EditorCell_Collection
              ? (jetbrains.mps.openapi.editor.cells.EditorCell_Collection) first
              : first.getParent();
      while (result != null) {
        if (result.isSelectable()) {
          boolean common = true;
          for (jetbrains.mps.openapi.editor.cells.EditorCell cell : cells) {
            if (!result.isAncestorOf(cell) && result != cell) {
              common = false;
              break;
            }
          }
          if (common) return (EditorCell) result;
        }

        result = result.getParent();
      }
      return null;
    }