public void execute(final SNode node, final EditorContext editorContext) {
   EditorCell selectedCell = editorContext.getSelectedCell();
   if (!(selectedCell.isReferenceCell())) {
     return;
   }
   SNode contextNode =
       SNodeOperations.cast(
           selectedCell.getSNode(), "jetbrains.mps.lang.core.structure.BaseConcept");
   if (contextNode == null) {
     return;
   }
   String role = selectedCell.getRole();
   if (SNodeOperations.isInstanceOf(
       contextNode, "jetbrains.mps.lang.quotation.structure.ReferenceAntiquotation")) {
     SNode attributedNode =
         SNodeOperations.cast(
             SNodeOperations.getParent(contextNode),
             "jetbrains.mps.lang.core.structure.BaseConcept");
     assert attributedNode != null;
     AttributeOperations.setAttribute(
         attributedNode,
         new IAttributeDescriptor.LinkAttribute(
             SConceptOperations.findConceptDeclaration(
                 "jetbrains.mps.lang.quotation.structure.ReferenceAntiquotation"),
             role),
         null);
     return;
   }
   if (AttributeOperations.getAttribute(
           contextNode,
           new IAttributeDescriptor.LinkAttribute(
               SConceptOperations.findConceptDeclaration(
                   "jetbrains.mps.lang.quotation.structure.ReferenceAntiquotation"),
               role))
       != null) {
     AttributeOperations.setAttribute(
         contextNode,
         new IAttributeDescriptor.LinkAttribute(
             SConceptOperations.findConceptDeclaration(
                 "jetbrains.mps.lang.quotation.structure.ReferenceAntiquotation"),
             role),
         null);
   } else {
     SNode referenceAntiquotation =
         SNodeFactoryOperations.setNewAttribute(
             contextNode,
             new IAttributeDescriptor.LinkAttribute(
                 SConceptOperations.findConceptDeclaration(
                     "jetbrains.mps.lang.quotation.structure.ReferenceAntiquotation"),
                 role),
             "jetbrains.mps.lang.quotation.structure.ReferenceAntiquotation");
     if (selectedCell.isSingleNodeCell()) {
       SPropertyOperations.set(
           referenceAntiquotation,
           "label",
           SPropertyOperations.getString(
               SNodeOperations.getConceptDeclaration(contextNode), "name"));
     }
   }
 }
예제 #2
0
 public static String getText(jetbrains.mps.openapi.editor.EditorContext editorContext) {
   EditorCell cell = editorContext.getSelectedCell();
   if (cell instanceof EditorCell_Label) {
     return ((EditorCell_Label) cell).getText();
   }
   return null;
 }
    private boolean canExecute_internal(
        final KeyEvent keyEvent,
        final EditorContext editorContext,
        final SNode node,
        final List<SNode> selectedNodes) {
      if (ListSequence.fromList(selectedNodes).count() != 1) {
        return false;
      }

      // Selected node should be within TypeVariableDeclaration
      SNode selectedNode = ListSequence.fromList(selectedNodes).first();
      SNode typeVarDeclaration =
          SNodeOperations.getAncestor(
              selectedNode,
              "jetbrains.mps.baseLanguage.structure.TypeVariableDeclaration",
              true,
              false);
      if (typeVarDeclaration == null) {
        return false;
      }

      // Next cell should belong to some other SNode, not our typeVarDeclaration
      jetbrains.mps.nodeEditor.cells.EditorCell selectedCell =
          (jetbrains.mps.nodeEditor.cells.EditorCell) editorContext.getSelectedCell();
      jetbrains.mps.nodeEditor.cells.EditorCell nextLeaf = selectedCell.getNextLeaf();
      if (nextLeaf == null) {
        return false;
      }
      SNode nextCellNode = (SNode) nextLeaf.getSNode();
      return nextCellNode != null && nextCellNode != typeVarDeclaration;
    }
 public void execute_internal(EditorContext editorContext, SNode node) {
   jetbrains.mps.nodeEditor.cells.EditorCell current =
       (jetbrains.mps.nodeEditor.cells.EditorCell) editorContext.getSelectedCell();
   jetbrains.mps.nodeEditor.cells.EditorCell toSelect =
       current.getPrevLeaf(CellConditions.SELECTABLE);
   SPropertyOperations.set(node, "caseInsensitive", "" + (false));
   editorContext.getEditorComponent().changeSelection(toSelect);
 }
예제 #5
0
 public static boolean isApplicable(jetbrains.mps.openapi.editor.EditorContext editorContext) {
   boolean applicable = false;
   EditorCell selectedCell = editorContext.getSelectedCell();
   if (selectedCell instanceof EditorCell_Error) {
     EditorCell_Label editorCell_Label = (EditorCell_Label) selectedCell;
     applicable = editorCell_Label.getText().length() > 0;
   }
   return applicable;
 }
예제 #6
0
 public void execute(jetbrains.mps.openapi.editor.EditorContext context) {
   EditorCell selection = (EditorCell) context.getSelectedCell();
   ((EditorComponent) context.getEditorComponent())
       .activateNodeSubstituteChooser(
           selection,
           ((selection instanceof EditorCell_Label)
               && ((EditorCell_Label) selection).isEverythingSelected()),
           true);
 }
예제 #7
0
 private boolean canExecute_internal(
     final KeyEvent keyEvent,
     final EditorContext editorContext,
     final SNode node,
     final List<SNode> selectedNodes) {
   if (ListSequence.fromList(selectedNodes).count() != 1) {
     return false;
   }
   return QueriesUtil.isPropertyMacroApplicable(node, editorContext.getSelectedCell());
 }
예제 #8
0
 private boolean canExecute_internal(
     final KeyEvent keyEvent,
     final EditorContext editorContext,
     final SNode node,
     final List<SNode> selectedNodes) {
   if (ListSequence.fromList(selectedNodes).count() != 1) {
     return false;
   }
   return QueriesUtil.isReferenceMacroApplicable(
       node, (jetbrains.mps.nodeEditor.cells.EditorCell) editorContext.getSelectedCell());
 }
예제 #9
0
 private void execute_internal(
     final KeyEvent keyEvent,
     final EditorContext editorContext,
     final SNode node,
     final List<SNode> selectedNodes) {
   SNode propertyMacro = QueriesUtil.addPropertyMacro(node, editorContext.getSelectedCell());
   // set caret
   editorContext.selectAndSetCaret(propertyMacro, 0);
   EditorInspector inspector = editorContext.getInspector();
   assert inspector != null;
   inspector.activate();
 }
예제 #10
0
  public static void showCreateNewRootMenu(
      @NotNull jetbrains.mps.openapi.editor.EditorContext editorContext,
      @Nullable Setter<SNode> newRootHandler,
      @Nullable Condition<SConcept> conceptsFilter) {
    final EditorCell selectedCell = editorContext.getSelectedCell();
    int x = selectedCell.getX();
    int y = selectedCell.getY();
    if (selectedCell instanceof EditorCell_Label) {
      y += selectedCell.getHeight();
    }
    Component editorComponent = ((EditorContext) editorContext).getNodeEditorComponent();
    final DataContext dataContext = DataManager.getInstance().getDataContext(editorComponent, x, y);
    final SModel model = selectedCell.getSNode().getModel();

    if (conceptsFilter == null) {
      conceptsFilter = Condition.TRUE_CONDITION;
    }

    BaseGroup group = new BaseGroup("");
    Set<SLanguage> modelLanguages =
        new SLanguageHierarchy(SModelOperations.getAllLanguageImports(model)).getExtended();
    SLanguage[] languages = modelLanguages.toArray(new SLanguage[modelLanguages.size()]);
    Arrays.sort(languages, new ToStringComparator());
    for (SLanguage language : languages) {
      boolean hasChildren = false;
      for (SAbstractConcept ac : language.getConcepts()) {
        if (!(ac instanceof SConcept)) {
          continue;
        }
        final SConcept concept = (SConcept) ac;
        if (concept.isRootable() && conceptsFilter.met(concept)) {
          group.add(new AddNewRootAction(model, concept, newRootHandler));
          hasChildren = true;
        }
      }

      if (hasChildren) {
        group.addSeparator();
      }
    }

    ListPopup popup =
        JBPopupFactory.getInstance()
            .createActionGroupPopup(
                IdeBundle.message("title.popup.new.element"),
                group,
                dataContext,
                JBPopupFactory.ActionSelectionAid.SPEEDSEARCH,
                false);
    //    popup.showInBestPositionFor(dataContext);
    popup.show(new RelativePoint(editorComponent, new Point(x, y)));
  }
 private boolean isApplicableToNode(final SNode node, final EditorContext editorContext) {
   EditorCell selectedCell = editorContext.getSelectedCell();
   if (!(selectedCell.isReferenceCell())) {
     return false;
   }
   SNode contextNode =
       SNodeOperations.cast(
           selectedCell.getSNode(), "jetbrains.mps.lang.core.structure.BaseConcept");
   if (contextNode == null) {
     return false;
   }
   return true;
 }
 public void execute(final SNode node, final EditorContext editorContext) {
   EditorCell cell = editorContext.getSelectedCell();
   String linkRole = QueriesUtil.getEditedLinkRole(cell);
   SNode referentNode = QueriesUtil.getEditedLinkReferentNode(cell);
   SNode result =
       SNodeFactoryOperations.setNewAttribute(
           referentNode,
           new IAttributeDescriptor.LinkAttribute(
               SConceptOperations.findConceptDeclaration(
                   "jetbrains.mps.lang.editor.editorTest.structure.ReferenceAnnotataion"),
               linkRole),
           "jetbrains.mps.lang.editor.editorTest.structure.ReferenceAnnotataion");
 }
예제 #13
0
 private void execute_internal(
     final KeyEvent keyEvent,
     final EditorContext editorContext,
     final SNode node,
     final List<SNode> selectedNodes) {
   SNode referenceMacro =
       QueriesUtil.addReferenceMacro(
           node, (jetbrains.mps.nodeEditor.cells.EditorCell) editorContext.getSelectedCell());
   // set caret
   editorContext.selectAndSetCaret(referenceMacro, 2);
   EditorInspector inspector = editorContext.getInspector();
   assert inspector != null;
   inspector.activate();
 }
예제 #14
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;
  }
예제 #15
0
 protected RestorableSelection createRestorableSelection(EditorContext editorContext) {
   EditorCell selectedCell = editorContext.getSelectedCell();
   String cellId = check_j6szs9_a0b0a(selectedCell);
   SNode selectedNode = check_j6szs9_a0c0a(selectedCell);
   if (cellId == null || selectedNode == null) {
     return null;
   }
   CellIdLocator locator = new CellIdLocator(cellId, selectedNode);
   CellSelector selector;
   if (selectedCell instanceof EditorCell_Label) {
     EditorCell_Label label = ((EditorCell_Label) selectedCell);
     selector =
         new LabelCellSelector(
             label.getCaretPosition(), label.getSelectionStart(), label.getSelectionEnd());
   } else {
     selector = new WholeCellSelector();
   }
   return new RestorableSelectionByCell(locator, selector);
 }
예제 #16
0
  public boolean canExecute(EditorContext context) {
    EditorCell selectedCell = getCellToPasteTo((EditorCell) context.getSelectedCell());
    if (selectedCell == null) {
      return false;
    }
    SNode selectedNode = selectedCell.getSNode();
    if (selectedNode == null || jetbrains.mps.util.SNodeOperations.isDisposed(selectedNode)) {
      return false;
    }
    List<SNode> pasteNodes = CopyPasteUtil.getNodesFromClipboard(selectedNode.getModel());
    if (pasteNodes == null || pasteNodes.isEmpty()) {
      return CopyPasteUtil.isConversionAvailable(selectedNode.getModel(), selectedNode);
    }

    if (!new NodePaster(pasteNodes).canPaste(selectedCell)) {
      LOG.debug("Couldn't paste node here");
      return false;
    }
    return true;
  }
예제 #17
0
  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));
  }
예제 #18
0
  @Override
  public boolean canExecute(EditorContext context) {
    EditorCell selectedCell = (EditorCell) context.getSelectedCell();
    if (selectedCell == null) {
      return false;
    }
    SNode anchorNode = selectedCell.getSNode();
    if (anchorNode == null) {
      return false;
    }
    List<SNode> pasteNodes = CopyPasteUtil.getNodesFromClipboard(anchorNode.getModel());
    if (pasteNodes == null || pasteNodes.isEmpty()) {
      return CopyPasteUtil.isConversionAvailable(anchorNode.getModel(), anchorNode);
    }

    if (!new NodePaster(pasteNodes).canPasteRelative(anchorNode)) {
      LOG.debug("Couldn't paste node relative");
      return false;
    }
    return true;
  }
 @Override
 public void execute(final SNode node, final EditorContext editorContext) {
   EditorCell_Property cell = (EditorCell_Property) editorContext.getSelectedCell();
   String propertyName = ((PropertyAccessor) cell.getModelAccessor()).getPropertyName();
   SNode cellNode = cell.getSNode();
   SNodeFactoryOperations.setNewAttribute(
       cellNode,
       new IAttributeDescriptor.PropertyAttribute(
           MetaAdapterFactory.getConcept(
               0xd4615e3bd6714ba9L,
               0xaf012b78369b0ba7L,
               0x108a9cb4795L,
               "jetbrains.mps.lang.pattern.structure.PropertyPatternVariableDeclaration"),
           propertyName),
       SNodeFactoryOperations.asInstanceConcept(
           MetaAdapterFactory.getConcept(
               0xd4615e3bd6714ba9L,
               0xaf012b78369b0ba7L,
               0x108a9cb4795L,
               "jetbrains.mps.lang.pattern.structure.PropertyPatternVariableDeclaration")));
 }
예제 #20
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);
  }
 private boolean isApplicableToNode(final SNode node, final EditorContext editorContext) {
   EditorCell selectedCell = editorContext.getSelectedCell();
   return selectedCell instanceof EditorCell_Property
       && ((EditorCell_Property) selectedCell).getModelAccessor() instanceof PropertyAccessor
       && PatternAddingUtil.isPatternApplicable(editorContext);
 }
예제 #22
0
 public boolean canExecute(jetbrains.mps.openapi.editor.EditorContext context) {
   EditorCell selection = (EditorCell) context.getSelectedCell();
   return selection != null && selection.getSubstituteInfo() != null;
 }
예제 #23
0
  @Override
  public void execute(final EditorContext context) {
    LOG.assertLog(
        context.getRepository().getModelAccess().isCommandAction(),
        "This action must be performed in command");
    final EditorComponent editorComponent = (EditorComponent) context.getEditorComponent();
    final Selection selection = editorComponent.getSelectionManager().getSelection();
    final List<SNode> selectedNodes = selection.getSelectedNodes();

    // this is used in case node is in repo to pass it into invokeLater
    final List<SNodeReference> selectedReferences = new ArrayList<SNodeReference>();
    for (SNode node : selectedNodes) {
      selectedReferences.add(node.getReference());
    }

    final CellInfo pasteTargetCellInfo;
    final SNode cellNodeSelected;
    final SNodeReference selectedCellReference;
    if (selection instanceof SingularSelection) {
      EditorCell pasteTargetCell = getCellToPasteTo(context.getSelectedCell());
      if (pasteTargetCell == null) {
        return;
      }
      pasteTargetCellInfo = APICellAdapter.getCellInfo(pasteTargetCell);
      cellNodeSelected = pasteTargetCell.getSNode();
      selectedCellReference = cellNodeSelected.getReference();
    } else {
      pasteTargetCellInfo = null;
      cellNodeSelected = null;
      selectedCellReference = null;
    }

    final SModel modelToPaste = selectedNodes.get(0).getModel();

    // sometimes model is not in repository (paste in merge dialog)
    final boolean inRepository =
        modelToPaste.getReference().resolve(context.getRepository()) != null;

    // FIXME relationship between Project and Editor needs attention, it's bad to extract
    final Project mpsProject = ProjectHelper.getProject(context.getRepository());
    if (mpsProject == null) {
      LOG.warning("Paste needs a project to show a dialog for additional imports");
      return;
    }

    final PasteNodeData pasteNodeData = CopyPasteUtil.getPasteNodeDataFromClipboard(modelToPaste);

    // FIXME why SwingUtlities? Is it necessary to execute in EDT thread? If yes, use ThreadUtils.
    // If not, use any other thread than UI, e.g. app's pooled one.
    SwingUtilities.invokeLater(
        new Runnable() {
          @Override
          public void run() {
            final Runnable addImportsRunnable =
                CopyPasteUtil.addImportsWithDialog(pasteNodeData, modelToPaste, mpsProject);
            context
                .getRepository()
                .getModelAccess()
                .executeCommandInEDT(
                    new Runnable() {
                      @Override
                      public void run() {
                        if (addImportsRunnable != null) {
                          addImportsRunnable.run();
                        }

                        List<SNode> pasteNodes = pasteNodeData.getNodes();
                        List<SNode> currentSelectedNodes;
                        if (!inRepository) {
                          currentSelectedNodes = selectedNodes;
                        } else {
                          currentSelectedNodes = new ArrayList<SNode>();
                          for (SNodeReference ref : selectedReferences) {
                            currentSelectedNodes.add(
                                ref.resolve(MPSModuleRepository.getInstance()));
                          }
                        }

                        NodePaster nodePaster = new NodePaster(pasteNodes);
                        boolean disposed =
                            checkDisposedSelectedNodes(currentSelectedNodes, selectedReferences);
                        boolean canPasteWithRemove =
                            !disposed && nodePaster.canPasteWithRemove(currentSelectedNodes);
                        if (selection instanceof SingularSelection
                            && (selection instanceof EditorCellLabelSelection
                                    && !isCompletelySelected((EditorCellLabelSelection) selection)
                                || (selection instanceof EditorCellSelection
                                    && !canPasteWithRemove))) {
                          EditorCell selectedCell = pasteTargetCellInfo.findCell(editorComponent);
                          assert selectedCell != null;

                          if (canPasteBefore(selectedCell, pasteNodes)) {
                            SNode selectedNode =
                                inRepository
                                    ? selectedCellReference.resolve(
                                        MPSModuleRepository.getInstance())
                                    : cellNodeSelected;
                            if (checkDisposed(selectedCellReference, cellNodeSelected)) {
                              return;
                            }
                            new NodePaster(pasteNodes)
                                .pasteRelative(selectedNode, PastePlaceHint.BEFORE_ANCHOR);
                          } else {
                            new NodePaster(pasteNodes).paste(selectedCell);
                          }
                        } else if ((selection instanceof MultipleSelection
                                || selection instanceof EditorCellSelection)
                            && canPasteWithRemove) {
                          nodePaster.pasteWithRemove(currentSelectedNodes);
                        } else {
                          return;
                        }

                        Set<SReference> requireResolveReferences = new HashSet<SReference>();
                        for (SReference ref : pasteNodeData.getRequireResolveReferences()) {
                          // ref can be detached from modeltoPaste while using copy/paste handlers
                          if (ref.getSourceNode() == null || ref.getSourceNode().getModel() == null)
                            continue;
                          requireResolveReferences.add(ref);
                        }

                        ResolverComponent.getInstance()
                            .resolveScopesOnly(requireResolveReferences, context.getRepository());

                        // set selection
                        editorComponent.getUpdater().flushModelEvents();
                        SNode lastNode = pasteNodes.get(pasteNodes.size() - 1);
                        editorComponent
                            .getSelectionManager()
                            .setSelection(lastNode, SelectionManager.LAST_CELL, -1);
                      }
                    });
          }
        });
  }