1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
5 namespace System.Activities.Presentation
7 using System.Activities.Presentation.Model;
10 internal class EditingScopeUndoUnit : UndoUnit
12 private ModelTreeManager modelTreeManager;
13 private EditingScope editingScope;
14 private EditingContext context;
16 public EditingScopeUndoUnit(EditingContext context, ModelTreeManager modelTreeManager, EditingScope editingScope)
19 Fx.Assert(context != null, "context cannot be null");
20 Fx.Assert(modelTreeManager != null, "modelTreeManager cannot be null");
21 Fx.Assert(editingScope != null, "editingScope cannot be null");
23 this.context = context;
24 this.modelTreeManager = modelTreeManager;
25 this.editingScope = editingScope;
26 this.Description = this.editingScope.Description;
31 public override void Redo()
33 this.modelTreeManager.StopTracking();
36 EditingScope redoEditingScope = this.modelTreeManager.CreateEditingScope(this.editingScope.Description);
37 redoEditingScope.Changes.AddRange(editingScope.Changes);
38 redoEditingScope.Complete();
42 this.modelTreeManager.StartTracking();
47 public override void Undo()
49 this.modelTreeManager.StopTracking();
52 EditingScope undoEditingScope = this.modelTreeManager.CreateEditingScope(this.editingScope.Description);
53 foreach (Change change in editingScope.Changes)
55 Change inverseChange = change.GetInverse();
56 if (inverseChange != null)
58 undoEditingScope.Changes.Add(inverseChange);
61 undoEditingScope.Changes.Reverse();
62 undoEditingScope.Complete();
66 this.modelTreeManager.StartTracking();