public void DoValueChange <T>(object keyObj, T prevValue, object prevData, T newValue, object newData, Action <T, object> setter, string valueName) { ValueChangeAction <T> desc = null; if (enableUndoRedo != 0) { desc = new ValueChangeAction <T>(prevValue, newValue, setter, DateTime.Now, valueName); desc.oldData = prevData; desc.newData = newData; desc.Do(); return; } // collapse into existing var collapsed = false; if (UndoStack.Count > 0) { var lastGroup = UndoStack.Peek(); var currentTime = DateTime.Now; var diff = (currentTime - lastGroup.LastActionTime).TotalMilliseconds; if (diff <= GroupingMS) { foreach (var action in lastGroup.Actions) { var valueChange = action as ValueChangeAction <T>; if (valueChange != null) { if (valueChange.KeyObj == keyObj && valueChange.ValueName == valueName) { valueChange.newVal = newValue; valueChange.newData = newData; valueChange.Do(); lastGroup.LastActionTime = currentTime; collapsed = true; } } } } } if (!collapsed) { desc = new ValueChangeAction <T>(prevValue, newValue, setter, keyObj, valueName); desc.oldData = prevData; desc.newData = newData; AddUndoRedoAction(desc); } }
public void DoValueChange <T>(object keyObj, T prevValue, object prevData, T newValue, object newData, Action <T, object> setter, string valueName) { ValueChangeAction <T> desc = null; if (enableUndoRedo != 0) { desc = new ValueChangeAction <T>(prevValue, newValue, setter, DateTime.Now, valueName); desc.oldData = prevData; desc.newData = newData; desc.Do(); return; } string key = keyObj.GetHashCode().ToString() + valueName; if (ValueChangeDict.ContainsKey(key)) { desc = ValueChangeDict[key] as ValueChangeAction <T>; desc.newVal = newValue; desc.newData = newData; desc.timeStamp = DateTime.Now; } else { desc = new ValueChangeAction <T>(prevValue, newValue, setter, DateTime.Now, valueName); desc.oldData = prevData; desc.newData = newData; ValueChangeDict[key] = desc; } desc.Do(); if (!valueTimer.Enabled) { valueTimer.Start(); } }