Пример #1
0
        /// <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);
        }
Пример #2
0
        /// <summary>
        /// OperationManagerのUndoStackとマージします。
        /// 統合されたOperationはUndoStackから除外されます。
        /// Operationが統合された場合OperationManagerのRedoStackはクリアされます。
        /// </summary>
        /// <param name="operationController"></param>
        /// <returns></returns>
        public IOperation Merge(IOperationController operationController)
        {
            if (operationController.CanUndo is false)
            {
                return(this);
            }

            if (MergeJudge is null)
            {
                return(this);
            }

            var topCommand = operationController.Peek();
            var prevValue  = PrevProperty;
            var mergeInfo  = MergeJudge;

            while (topCommand is MergeableOperation <T> propertyChangeOperation)
            {
                if (MergeJudge.CanMerge(propertyChangeOperation.MergeJudge) is false)
                {
                    break;
                }
                mergeInfo = propertyChangeOperation.MergeJudge;
                prevValue = propertyChangeOperation.PrevProperty;
                operationController.Pop();
                topCommand = operationController.Peek();
            }

            PrevProperty = prevValue;
            MergeJudge   = mergeInfo;
            return(this);
        }
Пример #3
0
        public static IOperation ExecuteAndCombineTop(this IOperation _this, IOperationController controller)
        {
            if (controller.Operations.Any())
            {
                var prev = controller.Pop();
                _this.RollForward();
                var newOperation = prev.CombineOperations(_this).ToCompositeOperation();
                newOperation.Messaage = _this.Messaage;
                return(controller.Push(newOperation));
            }

            return(controller.Execute(_this));
        }