package jetbrains.mps.console.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.PlatformDataKeys; import jetbrains.mps.nodeEditor.EditorComponent; import jetbrains.mps.internal.collections.runtime.MapSequence; import jetbrains.mps.console.tool.BaseConsoleTab; import jetbrains.mps.editor.runtime.cells.ReadOnlyUtil; import jetbrains.mps.openapi.editor.cells.EditorCell; import org.jetbrains.annotations.NotNull; import jetbrains.mps.ide.editor.MPSEditorDataKeys; import com.intellij.openapi.project.Project; import com.intellij.openapi.actionSystem.CommonDataKeys; import jetbrains.mps.console.tool.ConsoleTool; import jetbrains.mps.workbench.action.ActionUtils; import com.intellij.openapi.actionSystem.ActionManager; import com.intellij.openapi.actionSystem.IdeActions; public class PasteOriginalNode_Action extends BaseAction { private static final Icon ICON = null; public PasteOriginalNode_Action() { super("Paste Original Node", "", ICON); this.setIsAlwaysVisible(false); this.setExecuteOutsideCommand(true); } @Override public boolean isDumbAware() { return true; } @Override public boolean isApplicable(AnActionEvent event, final Map<String, Object> _params) { return PlatformDataKeys.PASTE_PROVIDER.getData(((EditorComponent) MapSequence.fromMap(_params).get("editor"))) instanceof BaseConsoleTab.MyPasteProvider && !(ReadOnlyUtil.isCellOrSelectionReadOnlyInEditor(((EditorComponent) MapSequence.fromMap(_params).get("editor")), ((EditorCell) MapSequence.fromMap(_params).get("cell")))); } @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; } { EditorComponent editorComponent = event.getData(MPSEditorDataKeys.EDITOR_COMPONENT); if (editorComponent != null && editorComponent.isInvalid()) { editorComponent = null; } MapSequence.fromMap(_params).put("editor", editorComponent); if (editorComponent == null) { return false; } } { EditorCell p = event.getData(MPSEditorDataKeys.EDITOR_CELL); MapSequence.fromMap(_params).put("cell", p); if (p == null) { return false; } } { Project p = event.getData(CommonDataKeys.PROJECT); MapSequence.fromMap(_params).put("project", p); if (p == null) { return false; } } return true; } @Override public void doExecute(@NotNull final AnActionEvent event, final Map<String, Object> _params) { ((Project) MapSequence.fromMap(_params).get("project")).getComponent(ConsoleTool.class).runWithoutPasteAsRef(new Runnable() { public void run() { ActionUtils.updateAndPerformAction(ActionManager.getInstance().getAction(IdeActions.ACTION_PASTE), event); } }); } }