From a891a19a979cbbdbe86cc4ec74ca593423ff2e59 Mon Sep 17 00:00:00 2001 From: Russell Wilkins Date: Tue, 20 Feb 2007 08:39:30 +0000 Subject: [PATCH] Loader updates git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2390 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Loaders/BasicWorkflowDesignerLoader.cs | 2 - .../Project/Src/Loaders/CodeDesignerLoader.cs | 66 ++++++++++--------- .../Project/Src/Loaders/XomlDesignerLoader.cs | 2 +- .../EventPropertyDescriptor.cs | 10 +-- 4 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/AddIns/DisplayBindings/WorkflowDesigner/Project/Src/Loaders/BasicWorkflowDesignerLoader.cs b/src/AddIns/DisplayBindings/WorkflowDesigner/Project/Src/Loaders/BasicWorkflowDesignerLoader.cs index 729e51c988..ce3c71b938 100644 --- a/src/AddIns/DisplayBindings/WorkflowDesigner/Project/Src/Loaders/BasicWorkflowDesignerLoader.cs +++ b/src/AddIns/DisplayBindings/WorkflowDesigner/Project/Src/Loaders/BasicWorkflowDesignerLoader.cs @@ -135,10 +135,8 @@ namespace WorkflowDesigner.Loaders protected override void PerformLoad(IDesignerSerializationManager serializationManager) { - base.PerformLoad(serializationManager); DoPerformLoad(serializationManager); LoadRules(); - LoaderHost.Activate(); } protected abstract void DoPerformLoad(IDesignerSerializationManager serializationManager); diff --git a/src/AddIns/DisplayBindings/WorkflowDesigner/Project/Src/Loaders/CodeDesignerLoader.cs b/src/AddIns/DisplayBindings/WorkflowDesigner/Project/Src/Loaders/CodeDesignerLoader.cs index 681f11c8cd..5ba0fa4007 100644 --- a/src/AddIns/DisplayBindings/WorkflowDesigner/Project/Src/Loaders/CodeDesignerLoader.cs +++ b/src/AddIns/DisplayBindings/WorkflowDesigner/Project/Src/Loaders/CodeDesignerLoader.cs @@ -8,7 +8,9 @@ #region Using using System; using System.CodeDom; +using System.CodeDom.Compiler; using System.Collections.Generic; +using System.ComponentModel; using System.ComponentModel.Design; using System.ComponentModel.Design.Serialization; using System.IO; @@ -22,24 +24,10 @@ using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.NRefactory; using ICSharpCode.NRefactory.Ast; using ICSharpCode.NRefactory.Visitors; -#endregion +#endregion namespace WorkflowDesigner.Loaders { - public class IdentifierCreationService : IIdentifierCreationService - { - public void EnsureUniqueIdentifiers(CompositeActivity parentActivity, System.Collections.ICollection childActivities) - { - // throw new NotImplementedException(); - } - - public void ValidateIdentifier(Activity activity, string identifier) - { - // throw new NotImplementedException(); - } - - } - /// /// Description of CodeDesignerLoader. @@ -49,15 +37,14 @@ namespace WorkflowDesigner.Loaders public CodeDesignerLoader(IViewContent viewContent) : base(viewContent) { } - + protected override void Initialize() { base.Initialize(); LoaderHost.AddService(typeof(IMemberCreationService), new MemberCreationService(LoaderHost)); - //LoaderHost.AddService(typeof(IEventBindingService), new CSharpWorkflowDesignerEventBindingService(LoaderHost, ViewContent.PrimaryFileName)); - //LoaderHost.RemoveService(typeof(IIdentifierCreationService)); - //LoaderHost.AddService(typeof(IIdentifierCreationService), new IdentifierCreationService()); + LoaderHost.AddService(typeof(CodeDomProvider), Project.LanguageProperties.CodeDomProvider); + LoaderHost.AddService(typeof(IEventBindingService), new CSharpWorkflowDesignerEventBindingService(LoaderHost, ViewContent.PrimaryFileName)); } protected override void DoPerformLoad(IDesignerSerializationManager serializationManager) @@ -67,25 +54,40 @@ namespace WorkflowDesigner.Loaders CodeCompileUnit ccu = Parse(); // Step 2, Find the first class - CodeTypeDeclaration cdt = ccu.Namespaces[0].Types[0]; + CodeTypeDeclaration codeTypeDeclaration = ccu.Namespaces[0].Types[0]; + + TypeResolutionService typeResolutionService = GetService(typeof(ITypeResolutionService)) as TypeResolutionService; + Type baseType = typeResolutionService.GetType(codeTypeDeclaration.BaseTypes[0].BaseType); + if (baseType == null) + throw new WorkflowDesignerLoadException("Unable to resolve type " + codeTypeDeclaration.BaseTypes[0].BaseType); - TypeResolutionService srv = GetService(typeof(ITypeResolutionService)) as TypeResolutionService; - Type t = srv.GetType(cdt.BaseTypes[0].BaseType); - if (t == null) - throw new WorkflowDesignerLoadException("Unable to resolve type " + cdt.BaseTypes[0].BaseType); - // Step 3, Deserialize it! - TypeCodeDomSerializer cds = serializationManager.GetSerializer(t, typeof(TypeCodeDomSerializer)) as TypeCodeDomSerializer; + TypeCodeDomSerializer serializer = serializationManager.GetSerializer(baseType, typeof(TypeCodeDomSerializer)) as TypeCodeDomSerializer; - // Step 4, load up the designer. - Activity rootActivity = null; - rootActivity = cds.Deserialize(serializationManager, cdt) as Activity; - rootActivity.Name = cdt.Name; + #if DEBUG + Project.LanguageProperties.CodeDomProvider.GenerateCodeFromType(codeTypeDeclaration, Console.Out, null); + #endif - LoaderHost.Container.Add(rootActivity, rootActivity.QualifiedName); + + // Step 4, load up the designer. + Activity rootActivity = serializer.Deserialize(serializationManager, codeTypeDeclaration) as Activity; - SetBaseComponentClassName(ccu.Namespaces[0].Name + "." + cdt.Name); + // FIXME: This is a workaraound as the deserializer does not appear to add the + // components to the container with the activity.name so + // the designer complains the name is already used when the + // name of an activity is the same as a field name in the workflow! + // When I work out how the IMemberCreationService fits into + // the scheme of things this will probably go away! + // (Worth noting CodeDomDesignerLoader has the same problem!) + //int i = 0; + foreach(IComponent c in LoaderHost.Container.Components) { + if (c is Activity) { + LoaderHost.Container.Remove(c); + LoaderHost.Container.Add(c, ((Activity)c).Name); + } + } + SetBaseComponentClassName(ccu.Namespaces[0].Name + "." + codeTypeDeclaration.Name); } protected override void DoPerformFlush(IDesignerSerializationManager serializationManager) diff --git a/src/AddIns/DisplayBindings/WorkflowDesigner/Project/Src/Loaders/XomlDesignerLoader.cs b/src/AddIns/DisplayBindings/WorkflowDesigner/Project/Src/Loaders/XomlDesignerLoader.cs index 880de08fef..2b46a64791 100644 --- a/src/AddIns/DisplayBindings/WorkflowDesigner/Project/Src/Loaders/XomlDesignerLoader.cs +++ b/src/AddIns/DisplayBindings/WorkflowDesigner/Project/Src/Loaders/XomlDesignerLoader.cs @@ -46,7 +46,7 @@ namespace WorkflowDesigner.Loaders public XomlDesignerLoader(IViewContent viewContent) : base(viewContent) { - // Loock for a code beside file for CodeSeparation mode. + // Look for a code beside file for CodeSeparation mode. if (Project != null) { FileProjectItem fpi = Project.FindFile(FileName); string codeFileName = FileName + "." + Project.LanguageProperties.CodeDomProvider.FileExtension; diff --git a/src/AddIns/DisplayBindings/WorkflowDesigner/Project/Src/Services/EventBindingService/EventPropertyDescriptor.cs b/src/AddIns/DisplayBindings/WorkflowDesigner/Project/Src/Services/EventBindingService/EventPropertyDescriptor.cs index c764765da6..13d1c01207 100644 --- a/src/AddIns/DisplayBindings/WorkflowDesigner/Project/Src/Services/EventBindingService/EventPropertyDescriptor.cs +++ b/src/AddIns/DisplayBindings/WorkflowDesigner/Project/Src/Services/EventBindingService/EventPropertyDescriptor.cs @@ -94,16 +94,16 @@ namespace WorkflowDesigner public override void SetValue(object component, object value) { // Validate the parameters. - Activity activity = component as Activity; - if (component == null) - throw new ArgumentException("component must be derived from Activity"); + DependencyObject dependencyObject = component as DependencyObject; + if (dependencyObject == null) + throw new ArgumentException(component.ToString() + " must be derived from DependencyObject", "component"); // Get the event list form the dependency object. - Hashtable events = activity.GetValue(WorkflowMarkupSerializer.EventsProperty) as Hashtable; + Hashtable events = dependencyObject.GetValue(WorkflowMarkupSerializer.EventsProperty) as Hashtable; if (events == null) { events = new Hashtable(); - activity.SetValue(WorkflowMarkupSerializer.EventsProperty, events); + dependencyObject.SetValue(WorkflowMarkupSerializer.EventsProperty, events); } string oldValue = events[this.eventDescriptor.Name] as string;