Action Manager is a central class for the Undo Framework. Your domain model (business objects) will have an ActionManager reference that would take care of executing actions. Here's how it works: 1. You declare a class that implements IAction 2. You create an instance of it and give it all necessary info that it needs to know to apply or rollback a change 3. You call ActionManager.RecordAction(yourAction) Then you can also call ActionManager.Undo() or ActionManager.Redo()
Exemple #1
0
 Transaction(ActionManager actionManager, bool delayed)
 {
     Actions = new List<IAction>();
     ActionManager = actionManager;
     actionManager.OpenTransaction(this);
     IsDelayed = delayed;
 }
Exemple #2
0
 public static Transaction Create(ActionManager actionManager, bool delayed)
 {
     if (actionManager == null)
     {
         throw new ArgumentNullException("actionManager");
     }
     return new Transaction(actionManager, delayed);
 }
Exemple #3
0
 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);
 }
Exemple #4
0
 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]);
 }
Exemple #5
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);
 }
Exemple #6
0
        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;
        }
Exemple #7
0
 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);
 }
Exemple #9
0
 /// <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);
        }