package jetbrains.mps.smodel.undo; /*Generated by MPS */ import org.jetbrains.mps.openapi.model.SNode; import java.util.List; import jetbrains.mps.smodel.SNodeUndoableAction; import jetbrains.mps.internal.collections.runtime.ListSequence; import jetbrains.mps.internal.collections.runtime.IWhereFilter; import jetbrains.mps.internal.collections.runtime.ISelector; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations; public class DefaultUndoContext implements UndoContext { @Override public Iterable<SNode> getVirtualFileNodes(List<SNodeUndoableAction> actions) { // There is a chance that so-called SNodeUndoableAction#isGlobal() actions may // return null from SNodeUndoableAction#getRoot() method (e.g. if the root was deleted). // In this case such actions does not have any influence on VirtualFiles collection associated // with the currently executed command within Undo subsystem. // // Such actions (delete node) are always global and can be undone either from the project pane // (in global context) or together with other actions executed in same command and associated // with different VirtualFiles (as a part of undo called on another editor). // // We do not use SNodeUndoableAction#isGlobal() as a condition here because other "global" // actions (add root) should probably be undoable within the current editor context (in case of // multi-tabbed editors / adding new aspect node and immediately undoing that command). return ListSequence.fromList(actions).where(new IWhereFilter<SNodeUndoableAction>() { public boolean accept(SNodeUndoableAction it) { return it.hasVirtualFile(); } }).select(new ISelector<SNodeUndoableAction, SNode>() { public SNode select(SNodeUndoableAction it) { return SNodeOperations.getContainingRoot(((SNode) it.getAffectedNode())); } }).where(new IWhereFilter<SNode>() { public boolean accept(SNode it) { return (it != null); } }); } }