1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
5 namespace System.Activities.Presentation.Model
8 using System.Activities.Presentation.Services;
9 using System.Collections.Generic;
13 class DictionaryChange : ModelChange
15 public ModelItemDictionary Dictionary { get; set; }
17 public OperationType Operation { get; set; }
19 public ModelItem Key { get; set; }
21 public ModelItem Value { get; set; }
23 public ModelTreeManager ModelTreeManager { get; set; }
25 public override string Description
29 return this.Operation == OperationType.Insert ? SR.DictionaryAddEditingScopeDescription : SR.DictionaryRemoveEditingScopeDescription;
33 public override bool Apply()
35 switch (this.Operation)
37 case OperationType.Insert:
40 case OperationType.Delete:
44 Fx.Assert("Operation should be Insert or Delete");
50 private void ApplyDelete()
52 ((ModelItemDictionaryImpl)this.Dictionary).RemoveCore(this.Key);
54 ModelChangeInfo changeInfo = ModelChangeInfoImpl.CreateDictionaryKeyValueRemoved(this.Dictionary, this.Key, this.Value);
58 this.ModelTreeManager.modelService.OnModelItemRemoved(this.Key, changeInfo);
62 if (this.Value != null)
64 this.ModelTreeManager.modelService.OnModelItemRemoved(this.Value, changeInfo);
68 if (changeInfo != null)
70 this.ModelTreeManager.modelService.EmitModelChangeInfo(changeInfo);
74 private void ApplyInsert()
76 ((ModelItemDictionaryImpl)this.Dictionary).AddCore(this.Key, this.Value);
78 ModelChangeInfo changeInfo = ModelChangeInfoImpl.CreateDictionaryKeyValueAdded(this.Dictionary, this.Key, this.Value);
82 this.ModelTreeManager.modelService.OnModelItemAdded(this.Key, changeInfo);
86 if (this.Value != null)
88 this.ModelTreeManager.modelService.OnModelItemAdded(this.Value, changeInfo);
92 if (changeInfo != null)
94 this.ModelTreeManager.modelService.EmitModelChangeInfo(changeInfo);
98 public override Change GetInverse()
100 OperationType reverseOperation = this.Operation == OperationType.Insert ? OperationType.Delete : OperationType.Insert;
101 return new DictionaryChange()
103 Dictionary = this.Dictionary,
104 Operation = reverseOperation,
107 ModelTreeManager = this.ModelTreeManager,
111 public enum OperationType