示例#1
0
 public int getIconCoordinate(EditorMessageIconRenderer renderer) {
   jetbrains.mps.openapi.editor.cells.EditorCell anchorCell = getAnchorCell(renderer);
   if (anchorCell == null || APICellAdapter.isUnderFolded(anchorCell)) {
     // no anchorCell
     return -1;
   }
   if (renderer.getIcon() == null) {
     LOG.error("null icon was returned by renderer: " + renderer);
     return -1;
   }
   return anchorCell.getY() + anchorCell.getHeight() / 2 - renderer.getIcon().getIconHeight() / 2;
 }
示例#2
0
 @Override
 public int compare(
     IconRendererLayoutConstraint constraint1, IconRendererLayoutConstraint constraint2) {
   if (constraint1 == constraint2) {
     return 0;
   }
   EditorMessageIconRenderer renderer1 = constraint1.getIconRenderer();
   EditorMessageIconRenderer renderer2 = constraint2.getIconRenderer();
   if (renderer1.getType() != renderer2.getType()) {
     return renderer1.getType().getWeight() - renderer2.getType().getWeight();
   }
   jetbrains.mps.openapi.editor.cells.EditorCell anchorCell1 = getAnchorCell(renderer1);
   jetbrains.mps.openapi.editor.cells.EditorCell anchorCell2 = getAnchorCell(renderer2);
   // [++] Debugging assertion
   if (anchorCell1 == anchorCell2
       && renderer1 instanceof EditorMessage
       && renderer2 instanceof EditorMessage) {
     EditorMessage editorMessage1 = (EditorMessage) renderer1;
     EditorMessage editorMessage2 = (EditorMessage) renderer2;
     assert false
         : "Two EditorMessages with same type are attached to the same EditorCell: m1 = "
             + editorMessage1
             + ", m2 = "
             + editorMessage2
             + "; owner1 = "
             + editorMessage1.getOwner()
             + ", owner2 = "
             + editorMessage2.getOwner();
   }
   // [--] Debugging assertion
   if (anchorCell1 != null) {
     if (anchorCell2 == null) {
       return 1;
     } else {
       return anchorCell1.getX() - anchorCell2.getX();
     }
   } else if (anchorCell2 != null) {
     return -1;
   }
   return 0;
 }
示例#3
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;
    }
示例#4
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;
    }
示例#5
0
 private static void navigatePage(
     jetbrains.mps.openapi.editor.EditorContext context, boolean isDown) {
   EditorComponent editor = (EditorComponent) context.getEditorComponent();
   jetbrains.mps.openapi.editor.cells.EditorCell selection = editor.getSelectedCell();
   Rectangle rect = editor.getVisibleRect();
   int height = (int) rect.getHeight();
   height = isDown ? height : -height;
   int caretX = selection.getCaretX();
   int y = selection.getY() + (selection.getHeight() / 2);
   int newY = y + height;
   jetbrains.mps.openapi.editor.cells.EditorCell target = editor.findCellWeak(caretX, newY);
   if (target == null) {
     target =
         isDown
             ? editor.myRootCell.findChild(CellFinders.LAST_SELECTABLE_LEAF)
             : editor.myRootCell.findChild(CellFinders.FIRST_SELECTABLE_LEAF);
     editor.changeSelection(target);
   } else {
     target.setCaretX(caretX);
     editor.changeSelection(target);
   }
 }