package jetbrains.mps.baseLanguage.editor; /*Generated by MPS */ import jetbrains.mps.openapi.editor.cells.EditorCell; import org.jetbrains.mps.openapi.model.SNode; import jetbrains.mps.openapi.editor.EditorContext; import jetbrains.mps.openapi.editor.cells.CellActionType; import jetbrains.mps.editor.runtime.cells.AbstractCellAction; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations; import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory; import jetbrains.mps.internal.collections.runtime.ListSequence; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations; import jetbrains.mps.smodel.action.SNodeFactoryOperations; public class SingleLineCommentActions { public static void setCellActions(EditorCell editorCell, SNode node, EditorContext context) { editorCell.setAction(CellActionType.INSERT, new SingleLineCommentActions.SingleLineCommentActions_INSERT(node)); } public static class SingleLineCommentActions_INSERT extends AbstractCellAction { /*package*/ SNode myNode; public SingleLineCommentActions_INSERT(SNode node) { this.myNode = node; } public String getDescriptionText() { return "Facilitate familiar comment editing experience: add newline if enter in the end of comment line"; } public void execute(EditorContext editorContext) { this.execute_internal(editorContext, this.myNode); } public void execute_internal(EditorContext editorContext, SNode node) { SNode selectedNode = editorContext.getSelectedNode(); SNode selectedPart; if (SNodeOperations.isInstanceOf(selectedNode, MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x57d533a7af15ed3bL, "jetbrains.mps.baseLanguage.structure.CommentPart"))) { selectedPart = SNodeOperations.cast(selectedNode, MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x57d533a7af15ed3bL, "jetbrains.mps.baseLanguage.structure.CommentPart")); } else if (SNodeOperations.isInstanceOf(SNodeOperations.getParent(selectedNode), MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x57d533a7af15ed3bL, "jetbrains.mps.baseLanguage.structure.CommentPart"))) { // commented statement comes in selection selectedPart = SNodeOperations.cast(SNodeOperations.getParent(selectedNode), MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x57d533a7af15ed3bL, "jetbrains.mps.baseLanguage.structure.CommentPart")); } else { return; } if (ListSequence.fromList(SLinkOperations.getChildren(node, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x57d533a7af15ed3aL, 0x57d533a7af16ff73L, "commentPart"))).last() == selectedPart) { if (SNodeOperations.isInstanceOf(selectedPart, MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x57d533a7af15ed3dL, "jetbrains.mps.baseLanguage.structure.TextCommentPart"))) { SingleLineCommentUtil.divideSingleLineCommentText((SNode) selectedPart, editorContext); } else { SNodeOperations.insertNextSiblingChild(node, SNodeFactoryOperations.createNewNode(SNodeFactoryOperations.asInstanceConcept(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b215L, "jetbrains.mps.baseLanguage.structure.Statement")), null)); } } else { SNodeOperations.insertNextSiblingChild(selectedPart, SNodeFactoryOperations.createNewNode(SNodeFactoryOperations.asInstanceConcept(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x57d533a7af15ed3bL, "jetbrains.mps.baseLanguage.structure.CommentPart")), null)); } } } }