コード例 #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;
    }
コード例 #2
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;
    }