Transaction(ActionManager actionManager, bool delayed) { Actions = new List<IAction>(); ActionManager = actionManager; actionManager.OpenTransaction(this); IsDelayed = delayed; }
public static Transaction Create(ActionManager actionManager, bool delayed) { if (actionManager == null) { throw new ArgumentNullException("actionManager"); } return new Transaction(actionManager, delayed); }
public void SetPropertyActionWorks() { var instance = new Exception(); SetPropertyAction action = new SetPropertyAction(instance, "Source", "foo"); ActionManager am = new ActionManager(); am.RecordAction(action); Assert.AreEqual("foo", instance.Source); am.Undo(); Assert.AreEqual(null, instance.Source); am.Redo(); Assert.AreEqual("foo", instance.Source); }
public void AddItemActionWorks() { List<string> list = new List<string>(); AddItemAction<string> action = new AddItemAction<string>(list.Add, s => list.Remove(s), "foo"); ActionManager am = new ActionManager(); am.RecordAction(action); Assert.AreEqual("foo", list[0]); am.Undo(); Assert.AreEqual(0, list.Count); am.Redo(); Assert.AreEqual("foo", list[0]); }
public void CallMethodActionWorks() { bool capturedFlag = false; ActionManager am = new ActionManager(); CallMethodAction action = new CallMethodAction( () => capturedFlag = true, () => capturedFlag = false); am.RecordAction(action); Assert.IsTrue(capturedFlag); am.Undo(); Assert.IsFalse(capturedFlag); am.Redo(); Assert.IsTrue(capturedFlag); }
public Drawing(Canvas canvas) { Check.NotNull(canvas, "canvas"); ActionManager = new ActionManager(); StyleManager = new StyleManager(this); Figures = new RootFigureList(this); OnAttachToCanvas += Drawing_OnAttachToCanvas; OnDetachFromCanvas += Drawing_OnDetachFromCanvas; Canvas = canvas; CoordinateSystem = new CoordinateSystem(this); CoordinateGrid = new CartesianGrid() { Drawing = this, Visible = Settings.Instance.ShowGrid }; Figures.Add(CoordinateGrid); Version = Settings.CurrentDrawingVersion; }
private void InitActionManager() { mActionManager = new ActionManager(); mActionManager.CollectionChanged += RaiseUndoBufferChanged; }
public static void SetFocus(this Block toFocus, SetFocusOptions options, ActionManager actionManager) { SetFocusAction action = new SetFocusAction(toFocus, options); actionManager.RecordAction(action); }
/// <summary> /// By default, the actions are delayed and executed only after /// the top-level transaction commits. /// </summary> /// <remarks> /// Make sure to dispose of the transaction once you're done - it will actually call Commit for you /// </remarks> /// <example> /// Recommended usage: using (Transaction.Create(actionManager)) { DoStuff(); } /// </example> public static Transaction Create(ActionManager actionManager) { return Create(actionManager, true); }
public void ThrowingActionInsideTransactionWillRollback() { ActionManager am = new ActionManager(); var log = new LogAction(); var throwing = new ThrowingAction(); try { using (Transaction.Create(am)) { am.RecordAction(log); am.RecordAction(throwing); } } catch (NotImplementedException) { } Assert.AreEqual(0, log.ExecutesCount); Assert.AreEqual(0, log.UnexecutesCount); Assert.AreEqual(0, am.TransactionStack.Count); Assert.AreEqual(false, am.ActionIsExecuting); }
public void Transactions() { var instance = new Exception(); instance.Source = "green"; ActionManager am = new ActionManager(); am.SetProperty(instance, "Source", "blue"); Assert.AreEqual("blue", instance.Source); am.Undo(); Assert.AreEqual("green", instance.Source); using (Transaction.Create(am)) { am.SetProperty(instance, "Source", "red"); Assert.AreEqual("green", instance.Source); } Assert.AreEqual(instance.Source, "red"); am.Undo(); Assert.AreEqual("green", instance.Source); am.Redo(); Assert.AreEqual(instance.Source, "red"); }
private void OnScreenRealParamsSet(DependencyPropertyChangedEventArgs e,ScreenPropertyPanel ctrl) { if (e.Property == ScreenRealParamsProperty) { ScreenRealParameters oldParams = e.OldValue as ScreenRealParameters; ScreenRealParameters newParams = e.NewValue as ScreenRealParameters; if (oldParams != null && oldParams.ScreenLayer != null && oldParams.ScreenLayer.ElementCollection != null) { oldParams.ScreenLayer.ElementCollection.CollectionChanged -= new NotifyCollectionChangedEventHandler(OnScreenElementCollectionChanged); } if (newParams != null && newParams.ScreenLayer != null && newParams.ScreenLayer.ElementCollection != null) { newParams.ScreenLayer.ElementCollection.CollectionChanged += new NotifyCollectionChangedEventHandler(OnScreenElementCollectionChanged); OnScreenElementCollectionChanged(null, null); } //if (newParams != null && // newParams.PortLayer != null && // newParams.PortLayer.ParentElement != null) //{ // MaxPortHeight = ((RectLayer)newParams.PortLayer.ParentElement).Height; // MaxPortWidth = ((RectLayer)newParams.PortLayer.ParentElement).Width; //} // ctrl.Cursor = Cursors.Arrow; if(newParams!=null && newParams.ScreenLayer != null) { IRectLayer parentLayer = (IRectLayer)newParams.ScreenLayer.ParentElement; while (parentLayer != null && parentLayer.EleType != ElementType.baselayer) { parentLayer = (IRectLayer)parentLayer.ParentElement; } if (parentLayer != null && parentLayer.EleType == ElementType.baselayer) { SmartLCTActionManager = parentLayer.MyActionManager; } } } //if (ScannerCofigCollection == null || // ScannerCofigCollection.Count == 0) //{ // ScannerCofigInfo customScannerConfigInfo = new ScannerCofigInfo(); // string strCustom = ""; // CommonStaticMethod.GetLanguageString("自定义", "Lang_Global_Custom", out strCustom); // customScannerConfigInfo.DisplayName = strCustom; // customScannerConfigInfo.ScanBdSizeType = ScannerSizeType.Custom; // ScannerCofigCollection = new ObservableCollection<ScannerCofigInfo>(); // ScannerCofigCollection.Add(customScannerConfigInfo); //} //else //{ // bool isHaveCustom = false; // for (int i = 0; i < ScannerCofigCollection.Count; i++) // { // if (ScannerCofigCollection[i].ScanBdSizeType == ScannerSizeType.Custom) // { // isHaveCustom = true; // break; // } // } // if (!isHaveCustom) // { // ScannerCofigInfo customScannerConfigInfo = new ScannerCofigInfo(); // string strCustom = ""; // CommonStaticMethod.GetLanguageString("自定义", "Lang_Global_Custom", out strCustom); // customScannerConfigInfo.DisplayName = strCustom; // customScannerConfigInfo.ScanBdSizeType = ScannerSizeType.Custom; // ScannerCofigCollection.Insert(ScannerCofigCollection.Count,customScannerConfigInfo); // } //} //if (ScannerCofigCollection != null && ScannerCofigCollection.Count == 1) //{ // SelectedScannerConfig = null; //} //else if (ScannerCofigCollection != null && ScannerCofigCollection.Count>1 && // SelectedScannerConfig.ScanBdSizeType == ScannerSizeType.Custom) //{ // SelectedScannerConfig = ScannerCofigCollection[0]; //} // ctrl.DragOver += new DragEventHandler(ctrl_DragOver); // ctrl.Drop += new DragEventHandler(ctrl_Drop); }