コード例 #1
0
            public TransactionCommand(
                HistoryContext context,
                string name,
                TransactionContext.Operation[] operations,
                SetSelectionCommand setSelectionCommand)

                : base(name)
            {
                m_context             = context;
                m_operations          = operations;
                m_setSelectionCommand = setSelectionCommand;
            }
コード例 #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 <TransactionContext.Operation> operations = TransactionOperations;
            int i = 0;

            while (i < operations.Count)
            {
                TransactionContext.Operation operation             = operations[i];
                TransactionContext.AttributeChangedOperation setOp = operation as TransactionContext.AttributeChangedOperation;
                if (setOp != null)
                {
                    Pair <DomNode, AttributeInfo> id = new Pair <DomNode, AttributeInfo>(setOp.DomNode, setOp.AttributeInfo);
                    TransactionContext.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();
        }