1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
6 namespace System.Activities.Presentation
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;
17 using System.Runtime.Versioning;
20 public partial class WorkflowDesigner
22 static internal FrameworkName GetTargetFramework(EditingContext context)
26 DesignerConfigurationService designerConfigurationService = context.Services.GetService<DesignerConfigurationService>();
27 if (designerConfigurationService != null)
29 return designerConfigurationService.TargetFrameworkName;
33 return DesignerConfigurationService.DefaultTargetFrameworkName;
37 string GetLocalAssemblyName()
39 AssemblyContextControlItem assemblyItem = this.Context.Items.GetValue<AssemblyContextControlItem>();
40 return assemblyItem != null && assemblyItem.LocalAssemblyName != null ? assemblyItem.LocalAssemblyName.Name : null;
44 ViewManager GetViewManager(ModelItem modelItem)
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)
53 viewManager = (ViewManager)Activator.CreateInstance(viewManagerAttribute.ViewManagerType);
56 // If no viewmanager attribute is found we default to the workflowviewmanager
57 if (viewManager == null)
59 viewManager = new WorkflowViewManager();
61 viewManager.Initialize(this.context);
66 object GetRootInstance()
68 return this.modelTreeManager.Root.GetCurrentValue();
72 void InitializePropertyInspectorCommandHandling()
76 void InitializePropertyInspectorResources()
78 this.propertyInspector.Resources.MergedDictionaries.Add(PropertyInspectorResources.GetResources());
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)
84 IModalService modalService = Context.Services.GetService<IModalService>();
85 if (modalService != null)
87 modalService.SetModalState(true);
91 void ComponentDispatcher_LeaveThreadModal(object sender, EventArgs e)
93 IModalService modalService = Context.Services.GetService<IModalService>();
94 if (modalService != null)
96 modalService.SetModalState(false);
100 void OnUndoCompleted(object sender, UndoUnitEventArgs e)
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))
107 this.view.Children.Clear();
108 this.view.Children.Add((UIElement)this.viewManager.View);
110 if (this.outlineView != null)
112 this.outlineView.Children.Clear();
113 this.AddOutlineView();
116 // Clear out the error condition
117 ErrorItem errorItem = this.context.Items.GetValue<ErrorItem>();
118 errorItem.Message = null;
119 errorItem.Details = null;
124 void OnViewStateChanged(object sender, ViewStateChangedEventArgs e)
126 NotifyModelChanged();
129 void OnEditingScopeCompleted(object sender, EditingScopeEventArgs e)
131 if (e.EditingScope.HasEffectiveChanges)
133 NotifyModelChanged();
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)
142 undoEngine.AddUndoUnit(new EditingScopeUndoUnit(this.Context, this.modelTreeManager, e.EditingScope));
148 void NotifyModelChanged() // Notify text is going to changed
150 IDocumentPersistenceService documentPersistenceService = this.Context.Services.GetService<IDocumentPersistenceService>();
151 if (documentPersistenceService != null)
153 documentPersistenceService.OnModelChanged(this.modelTreeManager.Root.GetCurrentValue());
157 this.isModelChanged = true;
158 if (this.ModelChanged != null)
160 this.ModelChanged.Invoke(this, null);
166 void OnReadonlyStateChanged(ReadOnlyState state)
168 if (null != this.propertyInspector)
170 this.propertyInspector.IsReadOnly = state.IsReadOnly;