public void Transact(IUITransactable context, UITransactionOp op, object[] elems) { if (!Enabled) { return; } checkRestart(); UITransaction tr = new UITransaction(); tr.op = op; tr.elems = elems; tr.context = context; trans.Add(tr); }
public void Commit() { if (!Enabled) { return; } checkRestart(); if (trans.Count > 0 && trans[trans.Count - 1].op == UITransactionOp.Checkpoint) { return; } UITransaction tr = new UITransaction(); tr.op = UITransactionOp.Checkpoint; trans.Add(tr); }
public void UndoTransaction(UITransaction tr) { int ix; switch (tr.op) { case UITransactionOp.SetAt: list[tr.i1] = (T)tr.elems[0]; break; case UITransactionOp.Add: list.RemoveAt(list.Count - 1); break; case UITransactionOp.AddRange: list.RemoveRange(list.Count - tr.i1, tr.i1); break; case UITransactionOp.RemoveAt: list.Insert(tr.i1, (T)tr.elems[0]); break; case UITransactionOp.RemoveRange: for (ix = 0; ix < tr.elems.Length; ix++) { list.Insert(tr.i1 + ix, (T)tr.elems[ix]); } break; case UITransactionOp.Clear: foreach (var obj in tr.elems) { list.Add((T)obj); } break; case UITransactionOp.InsertAt: list.RemoveAt(tr.i1); break; default: throw new NotImplementedException("undotrans Unsupported OP: " + tr.op); } }
public void PlayTransaction(UITransaction tr) { switch (tr.op) { case UITransactionOp.SetAt: list[tr.i1] = (T)tr.elems[1]; break; case UITransactionOp.Add: list.Add((T)tr.elems[0]); break; case UITransactionOp.AddRange: foreach (var obj in tr.elems) { list.Add((T)obj); } break; case UITransactionOp.RemoveAt: list.RemoveAt(tr.i1); break; case UITransactionOp.RemoveRange: list.RemoveRange(tr.i1, tr.i2); break; case UITransactionOp.Clear: list.Clear(); break; case UITransactionOp.InsertAt: list.Insert(tr.i1, (T)tr.elems[0]); break; default: throw new NotImplementedException("playtrans Unsupported OP: " + tr.op); } }