ebdb78274560b294dbc2c67f829a8458282fc1cf
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / UndoUnit.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4
5 namespace System.Activities.Presentation
6 {
7     using System;
8     using System.Collections.Generic;
9     using System.Text;
10     using System.Activities.Presentation.View;
11     using System.Activities.Presentation.Model;
12
13     public abstract class UndoUnit
14     {
15         EditingContext context;
16         ModelItem designerRoot;
17
18         public string Description { get; set; }
19         public abstract void Redo();
20         public abstract void Undo();
21
22         protected UndoUnit(EditingContext context)
23         {
24             if (context == null)
25             {
26                 throw FxTrace.Exception.AsError(new ArgumentNullException("context"));
27             }
28             this.context = context;
29         }
30         protected void SaveGlobalState()
31         {
32             DesignerView designerView = context.Services.GetService<DesignerView>();
33             if (designerView != null && designerView.RootDesigner != null)
34             {
35                 designerRoot = ((WorkflowViewElement)designerView.RootDesigner).ModelItem;
36             }
37         }
38
39         protected void ApplyGlobalState()
40         {
41             DesignerView designerView = context.Services.GetService<DesignerView>();
42             if (designerView != null && designerView.RootDesigner != null)
43             {
44                 ModelItem currentDesignerRoot = ((WorkflowViewElement)designerView.RootDesigner).ModelItem;
45                 if (currentDesignerRoot != designerRoot)
46                 {
47                     designerView.MakeRootDesigner(designerRoot);
48                 }
49             }
50         }
51     }
52 }