Esempio n. 1
0
 private boolean needToComment(EditorContext editorContext) {
   if (SNodeOperations.isInstanceOf(
       SNodeOperations.getParent(myNode),
       MetaAdapterFactory.getConcept(
           0xceab519525ea4f22L,
           0x9b92103b95ca8c0cL,
           0x3dcc194340c24debL,
           "jetbrains.mps.lang.core.structure.BaseCommentAttribute"))) {
     return false;
   } else if ((SNodeOperations.getNodeAncestor(
           myNode,
           MetaAdapterFactory.getConcept(
               0xceab519525ea4f22L,
               0x9b92103b95ca8c0cL,
               0x3dcc194340c24debL,
               "jetbrains.mps.lang.core.structure.BaseCommentAttribute"),
           false,
           false)
       == null)) {
     return true;
   } else {
     Selection selection = editorContext.getSelectionManager().getSelection();
     if ((selection instanceof EditorCellLabelSelection
         && !(((EditorCellLabelSelection) selection).hasNonTrivialSelection()))) {
       return false;
     } else {
       return true;
     }
   }
 }
Esempio n. 2
0
 @Override
 public boolean canExecute(EditorContext editorContext) {
   Selection selection = editorContext.getSelectionManager().getSelection();
   return SNodeOperations.getParent(myNode) != null
       && selection != null
       && selection instanceof SingularSelection
       && needToComment(editorContext);
 }
Esempio n. 3
0
 @Override
 public boolean canExecute(EditorContext context) {
   if (!super.canExecute(context)) {
     return false;
   }
   SNode node = context.getSelectionManager().getSelection().getSelectedNodes().get(0);
   if (SNodeOperations.getParent(node) == null) {
     return false;
   }
   return true;
   // todo: what about read-only models?
 }
Esempio n. 4
0
  public void execute(EditorContext editorContext) {
    EditorCell selectedCell = editorContext.getSelectedCell();
    if (selectedCell == null) {
      return;
    }
    final String cellId = selectedCell.getCellId();
    SNode actualSelectedNode = selectedCell.getSNode();
    boolean isLabel = selectedCell instanceof EditorCell_Label;
    int startPosition = (isLabel ? ((EditorCell_Label) selectedCell).getSelectionStart() : -1);
    int endPosition = (isLabel ? ((EditorCell_Label) selectedCell).getSelectionEnd() : -1);
    SNode nodeToSelect = CommentUtil.commentOut(myNode);
    editorContext.flushEvents();
    if (cellId != null) {
      EditorCell newNodeCell = editorContext.getEditorComponent().findNodeCell(actualSelectedNode);
      if (newNodeCell != null) {
        EditorCell cellToSelect =
            CellFinderUtil.findChildByCondition(
                newNodeCell,
                new Condition<EditorCell>() {
                  public boolean met(EditorCell cell) {
                    return eq_9lx3n0_a0a0a0a1a0a0b0j0h(cell.getCellId(), cellId);
                  }
                },
                true,
                true);
        if (cellToSelect != null) {
          if (isLabel) {
            editorContext
                .getSelectionManager()
                .setSelection(actualSelectedNode, cellId, startPosition, endPosition);
          } else {
            editorContext.getSelectionManager().setSelection(actualSelectedNode, cellId);
          }

          return;
        }
      }
    }
    SelectionUtil.selectCell(editorContext, nodeToSelect, SelectionManager.LAST_EDITABLE_CELL);
  }
Esempio n. 5
0
  @Override
  public boolean canExecute(EditorContext context) {
    Selection selection = context.getSelectionManager().getSelection();
    List<SNode> pasteNodes =
        CopyPasteUtil.getNodesFromClipboard(selection.getSelectedNodes().get(0).getModel());

    if (pasteNodes == null || pasteNodes.isEmpty()) {
      // it used to be ok because conversion would be invoked in this case
      return false;
    }

    boolean disposed = false;
    for (SNode node : selection.getSelectedNodes()) {
      if (!SNodeUtil.isAccessible(node, MPSModuleRepository.getInstance())) {
        disposed = true;
        break;
      }
    }

    boolean canPasteWithRemove =
        !disposed && canPasteViaNodePasterWithRemove(selection.getSelectedNodes(), pasteNodes);
    if (selection instanceof SingularSelection
        && (selection instanceof EditorCellLabelSelection
                && !isCompletelySelected((EditorCellLabelSelection) selection)
            || (selection instanceof EditorCellSelection && !canPasteWithRemove))) {
      EditorCell selectedCell = getCellToPasteTo(context.getSelectedCell());
      if (selectedCell == null) {
        return false;
      }
      SNode selectedNode = selectedCell.getSNode();
      if (selectedNode == null
          || !(SNodeUtil.isAccessible(selectedNode, MPSModuleRepository.getInstance()))) {
        return false;
      }

      return canPasteViaNodePaster(selectedCell, pasteNodes);

    } else if ((selection instanceof MultipleSelection || selection instanceof EditorCellSelection)
        && canPasteWithRemove) {
      return true;
    }
    return false;
  }
Esempio n. 6
0
 protected boolean isNonTrivialSingleSelection(EditorContext editorContext) {
   Selection selection = editorContext.getSelectionManager().getSelection();
   return (selection instanceof EditorCellLabelSelection
       ? ((EditorCellLabelSelection) selection).hasNonTrivialSelection()
       : selection instanceof SingularSelection);
 }