package jetbrains.mps.lang.generator.editor;
/*Generated by MPS */
import jetbrains.mps.editor.runtime.cells.KeyMapImpl;
import jetbrains.mps.openapi.editor.cells.KeyMapAction;
import jetbrains.mps.editor.runtime.cells.KeyMapActionImpl;
import jetbrains.mps.openapi.editor.EditorContext;
import jetbrains.mps.openapi.editor.cells.EditorCell;
import org.jetbrains.mps.openapi.model.SNode;
import java.util.List;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import org.jetbrains.mps.openapi.language.SAbstractConcept;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import jetbrains.mps.internal.collections.runtime.IWhereFilter;
import jetbrains.mps.lang.generator.helper.EditingUtil;
import jetbrains.mps.editor.runtime.selection.SelectionUtil;
import jetbrains.mps.openapi.editor.selection.SelectionManager;
import jetbrains.mps.openapi.editor.EditorInspector;
public class MacrosSwitch_KeyMap extends KeyMapImpl {
public MacrosSwitch_KeyMap() {
this.setApplicableToEveryModel(true);
KeyMapAction action;
action = new MacrosSwitch_KeyMap.MacrosSwitch_KeyMap_Action0();
this.putAction("ctrl+shift", "VK_F", action);
action = new MacrosSwitch_KeyMap.MacrosSwitch_KeyMap_Action1();
this.putAction("ctrl+shift", "VK_M", action);
action = new MacrosSwitch_KeyMap.MacrosSwitch_KeyMap_Action2();
this.putAction("ctrl+shift", "VK_M", action);
action = new MacrosSwitch_KeyMap.MacrosSwitch_KeyMap_Action3();
this.putAction("ctrl+shift", "VK_M", action);
}
public static class MacrosSwitch_KeyMap_Action0 extends KeyMapActionImpl {
public MacrosSwitch_KeyMap_Action0() {
this.setShownInPopupMenu(true);
}
public String getDescriptionText() {
return "create template fragmet";
}
public boolean isMenuAlwaysShown() {
return false;
}
public boolean canExecute(final EditorContext editorContext) {
EditorCell contextCell = editorContext.getContextCell();
if ((contextCell == null)) {
return false;
}
SNode contextNode = contextCell.getSNode();
if (contextNode == null) {
return false;
}
return this.canExecute_internal(editorContext, contextNode, this.getSelectedNodes(editorContext));
}
public void execute(final EditorContext editorContext) {
EditorCell contextCell = editorContext.getContextCell();
this.execute_internal(editorContext, contextCell.getSNode(), this.getSelectedNodes(editorContext));
}
private boolean canExecute_internal(final EditorContext editorContext, final SNode node, final List<SNode> selectedNodes) {
if (ListSequence.fromList(selectedNodes).count() != 1) {
return false;
}
if (SNodeOperations.getNodeAncestorWhereConceptInList(node, new SAbstractConcept[]{MetaAdapterFactory.getConcept(0xb401a68083254110L, 0x8fd384331ff25befL, 0xfe43cb41d0L, "jetbrains.mps.lang.generator.structure.TemplateDeclaration"), MetaAdapterFactory.getConcept(0xb401a68083254110L, 0x8fd384331ff25befL, 0x7b85dded0be53d6cL, "jetbrains.mps.lang.generator.structure.InlineTemplateWithContext_RuleConsequence")}, false, false) == null) {
return false;
}
if (ListSequence.fromList(SNodeOperations.getNodeAncestors(node, null, false)).where(new IWhereFilter<SNode>() {
public boolean accept(SNode it) {
return SNodeOperations.isAttribute(it);
}
}).isNotEmpty()) {
return false;
}
if (EditingUtil.isInsideTemplateFragment(node)) {
return false;
}
return true;
}
private void execute_internal(final EditorContext editorContext, final SNode node, final List<SNode> selectedNodes) {
// do not hang <TF> on other attributes
SNode applyToNode = ListSequence.fromList(SNodeOperations.getNodeAncestors(node, null, true)).where(new IWhereFilter<SNode>() {
public boolean accept(SNode it) {
return !(SNodeOperations.isAttribute(it));
}
}).first();
EditingUtil.createTemplateFragment(applyToNode);
}
public String getKeyStroke() {
return "ctrl shift F";
}
}
public static class MacrosSwitch_KeyMap_Action1 extends KeyMapActionImpl {
public MacrosSwitch_KeyMap_Action1() {
this.setShownInPopupMenu(true);
}
public String getDescriptionText() {
return "add node macro";
}
public boolean isMenuAlwaysShown() {
return false;
}
public boolean canExecute(final EditorContext editorContext) {
EditorCell contextCell = editorContext.getContextCell();
if ((contextCell == null)) {
return false;
}
SNode contextNode = contextCell.getSNode();
if (contextNode == null) {
return false;
}
return this.canExecute_internal(editorContext, contextNode, this.getSelectedNodes(editorContext));
}
public void execute(final EditorContext editorContext) {
EditorCell contextCell = editorContext.getContextCell();
this.execute_internal(editorContext, contextCell.getSNode(), this.getSelectedNodes(editorContext));
}
private boolean canExecute_internal(final EditorContext editorContext, final SNode node, final List<SNode> selectedNodes) {
if (ListSequence.fromList(selectedNodes).count() != 1) {
return false;
}
return EditingUtil.isNodeMacroApplicable(node);
}
private void execute_internal(final EditorContext editorContext, final SNode node, final List<SNode> selectedNodes) {
SNode nodeMacro = EditingUtil.addNodeMacro(node);
// set caret
SelectionUtil.selectLabelCellAnSetCaret(editorContext, nodeMacro, SelectionManager.FIRST_CELL, 1);
}
public String getKeyStroke() {
return "ctrl shift M";
}
}
public static class MacrosSwitch_KeyMap_Action2 extends KeyMapActionImpl {
public MacrosSwitch_KeyMap_Action2() {
this.setShownInPopupMenu(true);
}
public String getDescriptionText() {
return "add property macro";
}
public boolean isMenuAlwaysShown() {
return false;
}
public boolean canExecute(final EditorContext editorContext) {
EditorCell contextCell = editorContext.getContextCell();
if ((contextCell == null)) {
return false;
}
SNode contextNode = contextCell.getSNode();
if (contextNode == null) {
return false;
}
return this.canExecute_internal(editorContext, contextNode, this.getSelectedNodes(editorContext));
}
public void execute(final EditorContext editorContext) {
EditorCell contextCell = editorContext.getContextCell();
this.execute_internal(editorContext, contextCell.getSNode(), this.getSelectedNodes(editorContext));
}
private boolean canExecute_internal(final EditorContext editorContext, final SNode node, final List<SNode> selectedNodes) {
if (ListSequence.fromList(selectedNodes).count() != 1) {
return false;
}
return EditingUtil.isPropertyMacroApplicable(node, editorContext.getSelectedCell());
}
private void execute_internal(final EditorContext editorContext, final SNode node, final List<SNode> selectedNodes) {
SNode propertyMacro = EditingUtil.addPropertyMacro(node, editorContext.getSelectedCell());
// set caret
SelectionUtil.selectCell(editorContext, propertyMacro, SelectionManager.FIRST_CELL);
EditorInspector inspector = editorContext.getInspector();
assert inspector != null;
inspector.activate();
}
public String getKeyStroke() {
return "ctrl shift M";
}
}
public static class MacrosSwitch_KeyMap_Action3 extends KeyMapActionImpl {
public MacrosSwitch_KeyMap_Action3() {
this.setShownInPopupMenu(true);
}
public String getDescriptionText() {
return "add reference macro";
}
public boolean isMenuAlwaysShown() {
return false;
}
public boolean canExecute(final EditorContext editorContext) {
EditorCell contextCell = editorContext.getContextCell();
if ((contextCell == null)) {
return false;
}
SNode contextNode = contextCell.getSNode();
if (contextNode == null) {
return false;
}
return this.canExecute_internal(editorContext, contextNode, this.getSelectedNodes(editorContext));
}
public void execute(final EditorContext editorContext) {
EditorCell contextCell = editorContext.getContextCell();
this.execute_internal(editorContext, contextCell.getSNode(), this.getSelectedNodes(editorContext));
}
private boolean canExecute_internal(final EditorContext editorContext, final SNode node, final List<SNode> selectedNodes) {
if (ListSequence.fromList(selectedNodes).count() != 1) {
return false;
}
return EditingUtil.isReferenceMacroApplicable(node, editorContext.getSelectedCell());
}
private void execute_internal(final EditorContext editorContext, final SNode node, final List<SNode> selectedNodes) {
SNode referenceMacro = EditingUtil.addReferenceMacro(node, editorContext.getSelectedCell());
// set caret
SelectionUtil.selectLabelCellAnSetCaret(editorContext, referenceMacro, SelectionManager.FIRST_CELL, 2);
EditorInspector inspector = editorContext.getInspector();
assert inspector != null;
inspector.activate();
}
public String getKeyStroke() {
return "ctrl shift M";
}
}
}