package jetbrains.mps.ide.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 java.util.List;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.internal.collections.runtime.MapSequence;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import java.util.ArrayList;
import org.jetbrains.annotations.NotNull;
import jetbrains.mps.util.NameUtil;
import jetbrains.mps.ide.datatransfer.CopyPasteUtil;
public class CopyNodeReference_Action extends BaseAction {
private static final Icon ICON = null;
public CopyNodeReference_Action() {
super("Copy Reference", "", ICON);
this.setIsAlwaysVisible(false);
this.setExecuteOutsideCommand(false);
}
@Override
public boolean isDumbAware() {
return true;
}
@Override
protected boolean collectActionData(AnActionEvent event, final Map<String, Object> _params) {
if (!(super.collectActionData(event, _params))) {
return false;
}
{
List<SNode> nodes = event.getData(MPSCommonDataKeys.NODES);
if (nodes == null) {
MapSequence.fromMap(_params).put("nodes", null);
} else {
MapSequence.fromMap(_params).put("nodes", ListSequence.fromListWithValues(new ArrayList<SNode>(), nodes));
}
if (nodes == null) {
return false;
}
}
return true;
}
@Override
public void doExecute(@NotNull final AnActionEvent event, final Map<String, Object> _params) {
StringBuilder builder = new StringBuilder();
for (SNode node : ListSequence.fromList(((List<SNode>) MapSequence.fromMap(_params).get("nodes")))) {
builder.append(NameUtil.nodeFQName(node)).append("\n");
}
builder.deleteCharAt(builder.length() - 1);
CopyPasteUtil.copyTextToClipboard(builder.toString());
}
}