9d9a9c09724c871d2148cba1f7210cac8e2d910f
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Core.Presentation / System / ServiceModel / Activities / Presentation / CorrelatesOnValueEditor.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4
5 namespace System.ServiceModel.Activities.Presentation
6 {
7     using System.Activities.Core.Presentation.Themes;
8     using System.Activities.Presentation;
9     using System.Activities.Presentation.Converters;
10     using System.Activities.Presentation.Model;
11     using System.Activities.Presentation.PropertyEditing;
12     using System.Activities.Presentation.View;
13     using System.Windows;
14     using System.Runtime;
15     using System.Windows.Controls;
16
17     sealed class CorrelatesOnValueEditor : DialogPropertyValueEditor
18     {
19         public CorrelatesOnValueEditor()
20         {
21             this.InlineEditorTemplate = EditorCategoryTemplateDictionary.Instance.GetCategoryTemplate("CorrelatesOnDesigner_InlineTemplate");
22         }
23
24         public override void ShowDialog(PropertyValue propertyValue, IInputElement commandSource)
25         {
26             ModelPropertyEntryToOwnerActivityConverter propertyEntryConverter = new ModelPropertyEntryToOwnerActivityConverter();
27
28             ModelItem modelItem = (ModelItem)propertyEntryConverter.Convert(propertyValue.ParentProperty, typeof(ModelItem), false, null);
29             EditingContext context = modelItem.GetEditingContext();
30
31             this.ShowDialog(modelItem, context);
32         }
33
34         public void ShowDialog(ModelItem activity, EditingContext context)
35         {
36             Fx.Assert(activity != null, "Activity model item shouldn't be null!");
37             Fx.Assert(context != null, "EditingContext shouldn't be null!");
38
39
40             string bookmarkTitle = (string)this.InlineEditorTemplate.Resources["bookmarkTitle"];
41
42             UndoEngine undoEngine = context.Services.GetService<UndoEngine>();
43             Fx.Assert(null != undoEngine, "UndoEngine should be available");
44
45             using (EditingScope scope = context.Services.GetRequiredService<ModelTreeManager>().CreateEditingScope(bookmarkTitle, true))
46             {
47                 if ((new EditorWindow(activity, context)).ShowOkCancel())
48                 {
49                     scope.Complete();
50                 }
51             }
52         }
53
54         sealed class EditorWindow : WorkflowElementDialog
55         {
56             public EditorWindow(ModelItem activity, EditingContext context)
57             {
58                 this.ModelItem = activity;
59                 this.Context = context;
60                 this.Owner = activity.View;
61                 this.EnableMaximizeButton = false;
62                 this.EnableMinimizeButton = false;
63                 this.MinHeight = 250;
64                 this.MinWidth = 450;
65                 this.WindowResizeMode = ResizeMode.CanResize;
66                 this.WindowSizeToContent = SizeToContent.Manual;
67                 var template = EditorCategoryTemplateDictionary.Instance.GetCategoryTemplate("CorrelatesOnDesigner_DialogTemplate");
68
69                 var presenter = new ContentPresenter()
70                 {
71                     Content = activity,
72                     ContentTemplate = template
73                 };
74                 this.Title = (string)template.Resources["controlTitle"];
75                 this.Content = presenter;
76                 this.HelpKeyword = HelpKeywords.CorrelatesOnDefinitionDialog;
77             }
78
79             protected override void OnWorkflowElementDialogClosed(bool? dialogResult)
80             {
81                 if (dialogResult.HasValue && dialogResult.Value)
82                 {
83                     var correlatesOnProperty = this.ModelItem.Properties["CorrelatesOn"];
84
85                     if (correlatesOnProperty.IsSet && 0 == correlatesOnProperty.Dictionary.Count)
86                     {
87                         correlatesOnProperty.ClearValue();
88                     }
89                 }
90             }
91         }
92     }
93 }