/// <summary> /// OperationManagerのUndoStackとマージします。 /// 統合されたOperationはUndoStackから除外されます。 /// Operationが統合された場合OperationManagerのRedoStackはクリアされます。 /// </summary> public IOperation Merge(IOperationController operationController) { if (operationController.CanUndo is false) { return(this); } if (MergeJudge is null) { return(this); } var topCommand = operationController.Peek(); var mergeInfo = MergeJudge; while (topCommand is MergeableOperation mergeableOperation) { if (MergeJudge.CanMerge(mergeableOperation.MergeJudge) is false) { break; } mergeInfo = mergeableOperation.MergeJudge; _rollBack = mergeableOperation._rollBack; operationController.Pop(); topCommand = operationController.Peek(); } MergeJudge = MergeJudge.Update(mergeInfo); return(this); }
public MergeableOperation(NamedAction invoke, NamedAction rollback, IMergeJudge mergeJudge = null) { Debug.Assert(invoke != null); Debug.Assert(rollback != null); _rollForward = invoke; _rollBack = rollback; MergeJudge = mergeJudge; }
public MergeableOperation(Action invoke, Action rollback, IMergeJudge mergeJudge = null) { Debug.Assert(invoke != null); Debug.Assert(rollback != null); _rollForward = new NamedAction() { Action = invoke }; _rollBack = new NamedAction() { Action = rollback }; MergeJudge = mergeJudge; }