Example #1
0
            public TransactionCommand(
                HistoryContext context,
                string name,
                Operation[] operations,
                SetSelectionCommand setSelectionCommand)

                : base(name)
            {
                m_context = context;
                m_operations = operations;
                m_setSelectionCommand = setSelectionCommand;
            }
Example #2
0
        /// <summary>
        /// Performs custom actions after a transaction ends</summary>
        protected override void  OnEnded()
        {
            if (m_undoingOrRedoing)
                return;
            if (!m_recording)
                return;

            DateTime now = DateTime.UtcNow;
            TimeSpan elapsed = now.Subtract(m_lastSetOperationTime);
            m_lastSetOperationTime = now;

            // remove pending set operations if too much time has elapsed
            if (elapsed > PendingSetOperationLifetime)
            {
                m_pendingChanges.Clear();
            }

            // if operations can be combined with pending set operations, combine and remove them
            IList<Operation> operations = TransactionOperations;
            int i = 0;
            while (i < operations.Count)
            {
                Operation operation = operations[i];
                var setOp = operation as AttributeChangedOperation;
                if (setOp != null)
                {
                    var id = new Pair<DomNode, AttributeInfo>(setOp.DomNode, setOp.AttributeInfo);
                    AttributeChangedOperation pendingSetOp;
                    if (m_pendingChanges.TryGetValue(id, out pendingSetOp))
                    {
                        pendingSetOp.NewValue = setOp.NewValue;
                        operations.RemoveAt(i);
                        continue; // don't increment i
                    }
                    else
                    {
                        m_pendingChanges.Add(id, setOp);
                    }
                }

                i++;
            }

            if (operations.Count > 0)
            {
                SetSelectionCommand setSelectionCommand = null;
                if (m_selectionContext != null)
                {
                    setSelectionCommand = new SetSelectionCommand(
                        m_selectionContext,
                        m_lastSelection,
                        SnapshotSelection());
                }

                m_history.Add(new TransactionCommand(this, TransactionName, operations.ToArray(), setSelectionCommand));
            }

            m_lastSelection = null;

            base.OnEnded();
        }