]> O.S.I.I.S - jp/crow.git/commitdiff
ensure template are loaded when created in code
authorjpbruyere <jp.bruyere@hotmail.com>
Mon, 29 Feb 2016 10:38:45 +0000 (11:38 +0100)
committerjpbruyere <jp.bruyere@hotmail.com>
Mon, 29 Feb 2016 10:38:45 +0000 (11:38 +0100)
src/GraphicObjects/TemplatedControl.cs
src/Interface.cs

index ad7c74fe9e8ff8ebdd33e6623d165eb7e397463a..bb2fbd28d6502d55be1f1869d7fe72187c5b4d90 100644 (file)
@@ -56,7 +56,12 @@ namespace Crow
        public abstract class TemplatedControl : PrivateContainer, IXmlSerializable
        {
                #region CTOR
-               public TemplatedControl () : base()     {}
+               public TemplatedControl () : base()
+               {
+                       if (Interface.XmlLoaderCount > 0)
+                               return;
+                       loadTemplate ();
+               }
                #endregion
 
                string _template;
@@ -91,10 +96,10 @@ namespace Crow
                                this.SetChild (Interface.Load (dt.Path, this));
                        }else
                                this.SetChild (template);
-                       
+
                        this.ResolveBindings ();
                }
-                       
+
                #region IXmlSerializable
                public override System.Xml.Schema.XmlSchema GetSchema(){ return null; }
                public override void ReadXml(System.Xml.XmlReader reader)
@@ -109,7 +114,7 @@ namespace Crow
                                string tmp = subTree.ReadOuterXml ();
 
                                //Load template from path set as attribute in templated control
-                               if (string.IsNullOrEmpty (template)) {                                  
+                               if (string.IsNullOrEmpty (template)) {
                                        //seek for template tag first
                                        using (XmlReader xr = new XmlTextReader (tmp, XmlNodeType.Element, null)) {
                                                //load template first if inlined
@@ -124,7 +129,7 @@ namespace Crow
                                                                xr.Read ();
 
                                                                Type t = Type.GetType ("Crow." + xr.Name);
-                                                               GraphicObject go = (GraphicObject)Activator.CreateInstance (t);                                
+                                                               GraphicObject go = (GraphicObject)Activator.CreateInstance (t);
                                                                (go as IXmlSerializable).ReadXml (xr);
 
                                                                loadTemplate (go);
@@ -133,16 +138,16 @@ namespace Crow
                                                                xr.Read ();//Template close tag
                                                                break;
                                                        } else
-                                                               xr.ReadInnerXml ();                                                     
+                                                               xr.ReadInnerXml ();
                                                }
-                                       }                               
+                                       }
                                } else
                                        loadTemplate (Interface.Load (template, this));
-                               
+
                                //if no template found, load default one
                                if (this.child == null)
                                        loadTemplate ();
-                               
+
                                //normal xml read
                                using (XmlReader xr = new XmlTextReader (tmp, XmlNodeType.Element, null)) {
                                        xr.Read ();
index 6e9fb8a87315056b59d1f1b47f0d95cf7533ae77..527e2f2809926e4aa92f420835283ed98611d900 100644 (file)
@@ -39,6 +39,7 @@ namespace Crow
                internal static bool XmlSerializerInit = false;
                /// <summary> keep ressource path for debug msg </summary>
                internal static string CurrentGOMLPath = "";
+               internal static int XmlLoaderCount = 0;
 
                public static int TabSize = 4;
                public static string LineBreak = "\r\n";
@@ -122,10 +123,12 @@ namespace Crow
 
                public static GraphicObject Load (string path, object hostClass = null)
                {
+                       Interface.XmlLoaderCount ++;
                        CurrentGOMLPath = path;
                        using (Stream stream = GetStreamFromPath (path)) {
                                return Load(stream, GetTopContainerOfGOMLStream(stream), hostClass);
                        }
+                       Interface.XmlLoaderCount --;
                }