package jetbrains.mps.ide.editor.actions; /*Generated by MPS */ import jetbrains.mps.workbench.action.BaseAction; import javax.swing.Icon; import com.intellij.openapi.actionSystem.AnActionEvent; import java.util.Map; import com.intellij.openapi.actionSystem.ActionGroup; import com.intellij.openapi.actionSystem.ActionManager; import com.intellij.openapi.actionSystem.ActionGroupUtil; import org.jetbrains.annotations.NotNull; import jetbrains.mps.openapi.editor.EditorContext; import jetbrains.mps.ide.editor.MPSEditorDataKeys; import jetbrains.mps.internal.collections.runtime.MapSequence; import jetbrains.mps.openapi.editor.cells.EditorCell; import jetbrains.mps.baseLanguage.closures.runtime.Wrappers; import com.intellij.openapi.ui.popup.ListPopup; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.ui.awt.RelativePoint; import jetbrains.mps.nodeEditor.EditorComponent; import java.awt.Point; public class ShowGenerationActions_Action extends BaseAction { private static final Icon ICON = null; public ShowGenerationActions_Action() { super("Insert...", "", ICON); this.setIsAlwaysVisible(true); this.setExecuteOutsideCommand(true); } @Override public boolean isDumbAware() { return true; } @Override public boolean isApplicable(AnActionEvent event, final Map<String, Object> _params) { ActionGroup group = ((ActionGroup) ActionManager.getInstance().getAction("jetbrains.mps.ide.editor.actions.GenerationActions_ActionGroup")); group.update(event); return !(ActionGroupUtil.isGroupEmpty(group, event)); } @Override public void doUpdate(@NotNull AnActionEvent event, final Map<String, Object> _params) { this.setEnabledState(event.getPresentation(), this.isApplicable(event, _params)); } @Override protected boolean collectActionData(AnActionEvent event, final Map<String, Object> _params) { if (!(super.collectActionData(event, _params))) { return false; } { EditorContext p = event.getData(MPSEditorDataKeys.EDITOR_CONTEXT); MapSequence.fromMap(_params).put("editorContext", p); if (p == null) { return false; } } { EditorCell p = event.getData(MPSEditorDataKeys.EDITOR_CELL); MapSequence.fromMap(_params).put("selectedCell", p); if (p == null) { return false; } } return true; } @Override public void doExecute(@NotNull final AnActionEvent event, final Map<String, Object> _params) { int x = ((EditorCell) MapSequence.fromMap(_params).get("selectedCell")).getX(); int y = ((EditorCell) MapSequence.fromMap(_params).get("selectedCell")).getY() + ((EditorCell) MapSequence.fromMap(_params).get("selectedCell")).getHeight(); final Wrappers._T<ListPopup> popup = new Wrappers._T<ListPopup>(null); ((EditorContext) MapSequence.fromMap(_params).get("editorContext")).getRepository().getModelAccess().runReadAction(new Runnable() { public void run() { ActionGroup group = ((ActionGroup) ActionManager.getInstance().getAction("jetbrains.mps.ide.editor.actions.GenerationActions_ActionGroup")); group.update(event); if (group.getChildren(event).length == 0) { return; } popup.value = JBPopupFactory.getInstance().createActionGroupPopup("Generate", group, event.getDataContext(), JBPopupFactory.ActionSelectionAid.NUMBERING, false); } }); if (popup.value == null) { return; } RelativePoint relativePoint = new RelativePoint((EditorComponent) ((EditorContext) MapSequence.fromMap(_params).get("editorContext")).getEditorComponent(), new Point(x, y)); popup.value.show(relativePoint); } }