Merge pull request #3622 from rolfbjarne/remove-stray-file
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Annotations / WorkflowAnnotationAdornerService.cs
1 //----------------------------------------------------------------
2 // <copyright company="Microsoft Corporation">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //----------------------------------------------------------------
6
7 namespace System.Activities.Presentation.Annotations
8 {
9     using System.Activities.Presentation.Model;
10     using System.Windows.Controls;
11     using System.Windows.Documents;
12     using System.Xaml;
13
14     internal class WorkflowAnnotationAdornerService : AnnotationAdornerService
15     {
16         private ScrollViewer scrollViewer;
17         private bool enabled;
18
19         internal WorkflowAnnotationAdornerService()
20         {
21         }
22
23         public override void Show(AnnotationAdorner adorner)
24         {
25             if (!this.enabled)
26             {
27                 return;
28             }
29
30             AnnotationAdorner.SetAnchor(adorner, AdornerLocation.None);
31             adorner.ScrollViewer = this.scrollViewer;
32
33             AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(adorner.AdornedElement);
34             if (adornerLayer != null)
35             {
36                 adornerLayer.Add(adorner);
37             }
38
39             return;
40         }
41
42         public override void Hide(AnnotationAdorner adorner)
43         {
44             if (!this.enabled)
45             {
46                 return;
47             }
48
49             AnnotationAdorner.SetAnchor(adorner, AdornerLocation.None);
50
51             AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(adorner.AdornedElement);
52             if (adornerLayer != null)
53             {
54                 adornerLayer.Remove(adorner);
55             }
56             
57             return;
58         }
59
60         internal void Initialize(EditingContext editingContext, ScrollViewer scrollViewer)
61         {
62             this.scrollViewer = scrollViewer;
63             this.enabled = editingContext.Services.GetService<DesignerConfigurationService>().AnnotationEnabled;
64
65             if (!this.enabled)
66             {
67                 return;
68             }
69
70             AttachedPropertiesService attachedPropertiesService = editingContext.Services.GetService<AttachedPropertiesService>();
71             AttachedProperty<string> attachedProperty = new AttachedProperty<string>
72             {
73                 IsBrowsable = false,
74                 IsVisibleToModelItem = true,
75                 Name = Annotation.AnnotationTextPropertyName,
76                 OwnerType = typeof(object),
77                 Getter = (modelItem) =>
78                 {
79                     string annotation = null;
80                     AttachablePropertyServices.TryGetProperty<string>(modelItem.GetCurrentValue(), Annotation.AnnotationTextProperty, out annotation);
81                     return annotation;
82                 },
83                 Setter = (modelItem, value) =>
84                 {
85                     string oldValue = null;
86                     AttachablePropertyServices.TryGetProperty<string>(modelItem.GetCurrentValue(), Annotation.AnnotationTextProperty, out oldValue);
87                     if (oldValue == value)
88                     {
89                         return;
90                     }
91
92                     ModelTreeManager treeManager = modelItem.GetEditingContext().Services.GetService<ModelTreeManager>();
93
94                     AttachablePropertyChange change = new AttachablePropertyChange()
95                     {
96                         Owner = modelItem,
97                         AttachablePropertyIdentifier = Annotation.AnnotationTextProperty,
98                         OldValue = oldValue,
99                         NewValue = value,
100                         PropertyName = Annotation.AnnotationTextPropertyName
101                     };
102
103                     treeManager.AddToCurrentEditingScope(change);
104                 }
105             };
106
107             attachedPropertiesService.AddProperty(attachedProperty);
108         }
109     }
110 }