[reflection] Coop handles icalls in System.Reflection and System.RuntimeTypeHandle...
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / WorkflowDesigner.Helpers.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4
5
6 namespace System.Activities.Presentation
7 {
8     using System;
9     using System.Activities.Presentation.Documents;
10     using System.Activities.Presentation.Hosting;
11     using System.Activities.Presentation.Internal.PropertyEditing.Resources;
12     using System.Activities.Presentation.Model;
13     using System.Activities.Presentation.Validation;
14     using System.Activities.Presentation.View;
15     using System.ComponentModel;
16     using System.Runtime;
17     using System.Runtime.Versioning;
18     using System.Windows;
19
20     public partial class WorkflowDesigner
21     {
22         static internal FrameworkName GetTargetFramework(EditingContext context)
23         {
24             if (context != null)
25             {
26                 DesignerConfigurationService designerConfigurationService = context.Services.GetService<DesignerConfigurationService>();
27                 if (designerConfigurationService != null)
28                 {
29                     return designerConfigurationService.TargetFrameworkName;
30                 }
31             }
32
33             return DesignerConfigurationService.DefaultTargetFrameworkName;
34         }
35
36
37         string GetLocalAssemblyName()
38         {
39             AssemblyContextControlItem assemblyItem = this.Context.Items.GetValue<AssemblyContextControlItem>();
40             return assemblyItem != null && assemblyItem.LocalAssemblyName != null ? assemblyItem.LocalAssemblyName.Name : null;
41         }
42
43
44         ViewManager GetViewManager(ModelItem modelItem)
45         {
46             Fx.Assert(modelItem != null, "modelItem cannot be null");
47             ViewManager viewManager = null;
48             // First we look for a ViewManagerAttribute. for example a ServiceContractRoot tag, could use
49             // use its own view manager if it wanted to .
50             ViewManagerAttribute viewManagerAttribute = TypeDescriptor.GetAttributes(modelItem.ItemType)[typeof(ViewManagerAttribute)] as ViewManagerAttribute;
51             if (viewManagerAttribute != null && viewManagerAttribute.ViewManagerType != null)
52             {
53                 viewManager = (ViewManager)Activator.CreateInstance(viewManagerAttribute.ViewManagerType);
54
55             }
56             // If no viewmanager attribute is found we default to the workflowviewmanager
57             if (viewManager == null)
58             {
59                 viewManager = new WorkflowViewManager();
60             }
61             viewManager.Initialize(this.context);
62             return viewManager;
63         }
64
65
66         object GetRootInstance()
67         {
68             return this.modelTreeManager.Root.GetCurrentValue();
69         }
70
71
72         void InitializePropertyInspectorCommandHandling()
73         {
74         }
75
76         void InitializePropertyInspectorResources()
77         {
78             this.propertyInspector.Resources.MergedDictionaries.Add(PropertyInspectorResources.GetResources());
79         }
80
81         //This is to notify VS that the WF Designer is in Modal state (eg. when a modal dialog is shown).
82         void ComponentDispatcher_EnterThreadModal(object sender, EventArgs e)
83         {
84             IModalService modalService = Context.Services.GetService<IModalService>();
85             if (modalService != null)
86             {
87                 modalService.SetModalState(true);
88             }
89         }
90
91         void ComponentDispatcher_LeaveThreadModal(object sender, EventArgs e)
92         {
93             IModalService modalService = Context.Services.GetService<IModalService>();
94             if (modalService != null)
95             {
96                 modalService.SetModalState(false);
97             }
98         }
99
100         void OnUndoCompleted(object sender, UndoUnitEventArgs e)
101         {
102             // If an action had caused the errorview to be shown, and undo was executed after that 
103             // try to put back the viewmanagerview back as the rootview of the designer.
104             // may be the undo might help recover from the problem.
105             if (!this.view.Children.Contains((UIElement)this.viewManager.View))
106             {
107                 this.view.Children.Clear();
108                 this.view.Children.Add((UIElement)this.viewManager.View);
109
110                 if (this.outlineView != null)
111                 {
112                     this.outlineView.Children.Clear();
113                     this.AddOutlineView();
114                 }
115
116                 // Clear out the error condition
117                 ErrorItem errorItem = this.context.Items.GetValue<ErrorItem>();
118                 errorItem.Message = null;
119                 errorItem.Details = null;
120             }
121         }
122
123
124         void OnViewStateChanged(object sender, ViewStateChangedEventArgs e)
125         {
126             NotifyModelChanged();
127         }
128
129         void OnEditingScopeCompleted(object sender, EditingScopeEventArgs e)
130         {
131             if (e.EditingScope.HasEffectiveChanges)
132             {
133                 NotifyModelChanged();
134
135                 // The undo unit of an ImmediateEditingScope is added into undo engine in ImmediateEditingScope.Complete
136                 // so we only handle non ImmediateEditingScope here
137                 if (!this.modelTreeManager.RedoUndoInProgress
138                     && !(e.EditingScope is ImmediateEditingScope)
139                     && undoEngine != null
140                     && !e.EditingScope.SuppressUndo)
141                 {
142                     undoEngine.AddUndoUnit(new EditingScopeUndoUnit(this.Context, this.modelTreeManager, e.EditingScope));
143                 }
144             }
145         }
146
147
148         void NotifyModelChanged()   // Notify text is going to changed
149         {
150             IDocumentPersistenceService documentPersistenceService = this.Context.Services.GetService<IDocumentPersistenceService>();
151             if (documentPersistenceService != null)
152             {
153                 documentPersistenceService.OnModelChanged(this.modelTreeManager.Root.GetCurrentValue());
154             }
155             else
156             {
157                 this.isModelChanged = true;
158                 if (this.ModelChanged != null)
159                 {
160                     this.ModelChanged.Invoke(this, null);
161                 }
162             }
163         }
164
165
166         void OnReadonlyStateChanged(ReadOnlyState state)
167         {
168             if (null != this.propertyInspector)
169             {
170                 this.propertyInspector.IsReadOnly = state.IsReadOnly;
171             }
172         }
173     }
174 }