From: jpbruyere Date: Wed, 10 Aug 2016 05:13:14 +0000 (+0200) Subject: ItemTemplate instantiator, basic listbox ok X-Git-Tag: v0.4~11^2~3 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=1b2e2794fc8c4c8c20ff50fd7fbe842908912d23;p=jp%2Fcrow.git ItemTemplate instantiator, basic listbox ok --- 1b2e2794fc8c4c8c20ff50fd7fbe842908912d23 diff --cc Tests/Interfaces/basicTests/8.crow index 00000000,00000000..a20e1ac5 new file mode 100755 --- /dev/null +++ b/Tests/Interfaces/basicTests/8.crow @@@ -1,0 -1,0 +1,34 @@@ ++ ++ ++ ++ ++ diff --cc src/CompilerServices/Bindings.cs index 953f1492,953f1492..64f412f6 --- a/src/CompilerServices/Bindings.cs +++ b/src/CompilerServices/Bindings.cs @@@ -128,10 -128,10 +128,12 @@@ namespace Cro //datasource binding object dataSource = (Source.Instance as GraphicObject).DataSource; if (dataSource == null) { ++ #if DEBUG_BINDING Debug.WriteLine ("\tDataSource is null => " + this.ToString()); ++ #endif return false; } -- ++ Target = new MemberReference (dataSource); memberName = bindingExp [0]; } else { @@@ -153,7 -153,7 +155,7 @@@ while (ptr < bindingExp.Length - 1) { if (tmpTarget == null) { #if DEBUG_BINDING -- Debug.WriteLine ("\tERROR: target not found => " + this.ToString()); ++ Debug.WriteLine ("\tTarget not found => " + this.ToString()); #endif return false; } @@@ -169,14 -169,14 +171,12 @@@ } if (tmpTarget == null) { --#if DEBUG_BINDING -- Debug.WriteLine ("\tERROR: Binding Target not found => " + this.ToString()); --#endif ++ #if DEBUG_BINDING ++ Debug.WriteLine ("\tBinding Target not found => " + this.ToString()); ++ #endif return false; } -- Target = new MemberReference (tmpTarget); -- string [] bindTrg = bindingExp [ptr].Split ('.'); if (bindTrg.Length == 1) @@@ -187,6 -187,6 +187,14 @@@ } else throw new Exception ("Syntax error in binding, expected 'go dot member'"); ++ if (tmpTarget == null) { ++ #if DEBUG_BINDING ++ Debug.WriteLine ("\tBinding Target not found => " + this.ToString()); ++ #endif ++ return false; ++ } ++ ++ Target = new MemberReference (tmpTarget); } if (Target.TryFindMember (memberName)) { diff --cc src/GraphicObjects/TemplatedControl.cs index b325a0d2,f78173d2..63bdbb21 --- a/src/GraphicObjects/TemplatedControl.cs +++ b/src/GraphicObjects/TemplatedControl.cs @@@ -65,8 -65,9 +65,8 @@@ namespace Cro string _template; string _itemTemplate; - public Dictionary ItemTemplates; - + public Dictionary ItemTemplates = new Dictionary();//TODO: dont instantiate if not used + //but then i should test if null in msil gen - [XmlAttributeAttribute][DefaultValue(null)] public string Template { get { return _template; } diff --cc src/IMLReader.cs index c1238081,0474fdc0..7792de4d --- a/src/IMLReader.cs +++ b/src/IMLReader.cs @@@ -92,58 -108,69 +108,71 @@@ namespace Cro //if its a template, first read template elements using (IMLReader reader = new IMLReader (il, tmpXml)) { - string template = reader.GetAttribute ("Template"); + string templatePath = reader.GetAttribute ("Template"); + //string itemTemplatePath = reader.GetAttribute ("ItemTemplate"); bool inlineTemplate = false; - if (string.IsNullOrEmpty (template)) { - if (string.IsNullOrEmpty (templatePath)) { -- reader.Read (); -- -- while (reader.Read ()) { -- if (!reader.IsStartElement ()) -- continue; -- if (reader.Name == "Template") { -- inlineTemplate = true; -- reader.Read (); -- -- readChildren (reader, crowType); -- continue; - }else if (reader.Name == "ItemTemplate") { - } else if (reader.Name == "ItemTemplate") { -- reader.Skip (); - // string dataType = "default", datas = "", itemTmp; - // while (reader.MoveToNextAttribute ()) { - // if (reader.Name == "DataType") - // dataType = reader.Value; - // else if (reader.Name == "Data") - // datas = reader.Value; - // } - // - // reader.Read(); - // itemTmp = .ReadInnerXml (); - // - // if (ItemTemplates == null) - // ItemTemplates = new Dictionary (); - // //TODO:check encoding - // ItemTemplates[dataType] = new ItemTemplate (Encoding.UTF8.GetBytes(itemTmp)); - // if (!string.IsNullOrEmpty (datas)) - // ItemTemplates [dataType].CreateExpandDelegate(this, dataType, datas); - -- continue; - - string dataType = "default", datas = "", path = ""; - while (reader.MoveToNextAttribute ()) { - if (reader.Name == "DataType") - dataType = reader.Value; - else if (reader.Name == "Data") - datas = reader.Value; - else if (reader.Name == "Path") - path = reader.Value; - } - - using (IMLReader iTmp = new IMLReader (null, reader.ReadInnerXml ())) { - string uid = Guid.NewGuid ().ToString (); - Interface.Instantiators [uid] = - new ItemTemplate (iTmp.RootType, iTmp.GetLoader ()); - reader.il.Emit (OpCodes.Ldstr, dataType); - reader.il.Emit (OpCodes.Ldstr, uid); - reader.il.Emit (OpCodes.Callvirt, - typeof(Interface).GetMethod ("GetItemTemplate")); - reader.il.Emit (OpCodes.Callvirt, - typeof(Dictionary).GetMethod ("Add", - new Type[] { typeof(string), typeof(ItemTemplate) })); - } -// if (!string.IsNullOrEmpty (datas)) -// ItemTemplates [dataType].CreateExpandDelegate(this, dataType, datas); ++ reader.Read (); + - continue; ++ while (reader.Read ()) { ++ if (!reader.IsStartElement ()) ++ continue; ++ if (reader.Name == "Template") { ++ inlineTemplate = true; ++ reader.Read (); ++ ++ readChildren (reader, crowType); ++ continue; ++ } else if (reader.Name == "ItemTemplate") { ++ string dataType = "default", datas = "", path = ""; ++ while (reader.MoveToNextAttribute ()) { ++ if (reader.Name == "DataType") ++ dataType = reader.Value; ++ else if (reader.Name == "Data") ++ datas = reader.Value; ++ else if (reader.Name == "Path") ++ path = reader.Value; } - } - if (!inlineTemplate) { - DefaultTemplate dt = (DefaultTemplate)crowType.GetCustomAttributes (typeof(DefaultTemplate), true).FirstOrDefault(); - template = dt.Path; + - if (!inlineTemplate) { - DefaultTemplate dt = (DefaultTemplate)crowType.GetCustomAttributes (typeof(DefaultTemplate), true).FirstOrDefault (); - templatePath = dt.Path; ++ using (IMLReader iTmp = new IMLReader (null, reader.ReadInnerXml ())) { ++ string uid = Guid.NewGuid ().ToString (); ++ Interface.Instantiators [uid] = ++ new ItemTemplate (iTmp.RootType, iTmp.GetLoader ()); ++ reader.il.Emit (OpCodes.Ldloc_0);//load TempControl ref ++ reader.il.Emit (OpCodes.Ldfld,//load ItemTemplates dic field ++ typeof(TemplatedControl).GetField("ItemTemplates")); ++ reader.il.Emit (OpCodes.Ldstr, dataType);//load key ++ reader.il.Emit (OpCodes.Ldstr, uid);//load value ++ reader.il.Emit (OpCodes.Callvirt, ++ typeof(Interface).GetMethod ("GetItemTemplate")); ++ reader.il.Emit (OpCodes.Callvirt, ++ typeof(Dictionary).GetMethod ("set_Item", ++ new Type[] { typeof(string), typeof(ItemTemplate) })); + } ++// if (!string.IsNullOrEmpty (datas)) ++// ItemTemplates [dataType].CreateExpandDelegate(this, dataType, datas); ++ ++ continue; } } ++ if (!inlineTemplate) { -- reader.il.Emit (OpCodes.Ldloc_0);//Load this templateControl ref ++ if (string.IsNullOrEmpty (templatePath)) { ++ DefaultTemplate dt = (DefaultTemplate)crowType.GetCustomAttributes (typeof(DefaultTemplate), true).FirstOrDefault (); ++ if (dt!=null) ++ templatePath = dt.Path; ++ } + - reader.il.Emit (OpCodes.Ldstr, templatePath); //Load template path string - reader.il.Emit (OpCodes.Callvirt,//call Interface.Load(path) - typeof(Interface).GetMethod ("Load", BindingFlags.Static | BindingFlags.Public)); ++ if (!string.IsNullOrEmpty (templatePath)) { ++ reader.il.Emit (OpCodes.Ldloc_0);//Load this templateControl ref + - reader.il.Emit (OpCodes.Ldstr, template); //Load template path string - reader.il.Emit (OpCodes.Callvirt,//call Interface.Load(path) - typeof(Interface).GetMethod ("Load", BindingFlags.Static | BindingFlags.Public)); ++ reader.il.Emit (OpCodes.Ldstr, templatePath); //Load template path string ++ reader.il.Emit (OpCodes.Callvirt,//call Interface.Load(path) ++ typeof(Interface).GetMethod ("Load", BindingFlags.Static | BindingFlags.Public)); ++ reader.il.Emit (OpCodes.Callvirt,//add child ++ crowType.GetMethod ("loadTemplate", BindingFlags.Instance | BindingFlags.NonPublic)); ++ } } -- reader.il.Emit (OpCodes.Callvirt,//add child -- crowType.GetMethod ("loadTemplate", BindingFlags.Instance | BindingFlags.NonPublic)); } } @@@ -157,9 -184,9 +186,10 @@@ CompilerServices.EmitSetValue (reader.il, pi, style); } } ++ reader.il.Emit (OpCodes.Ldloc_0); ++ reader.il.Emit (OpCodes.Callvirt, typeof(GraphicObject).GetMethod ("loadDefaultValues")); ++ if (reader.HasAttributes) { -- reader.il.Emit (OpCodes.Ldloc_0); -- reader.il.Emit (OpCodes.Callvirt, typeof(GraphicObject).GetMethod ("loadDefaultValues")); MethodInfo miAddBinding = typeof(GraphicObject).GetMethod ("BindMember"); @@@ -222,6 -249,6 +252,9 @@@ miAddChild = typeof(Container).GetMethod ("SetChild"); else if (typeof(TemplatedContainer).IsAssignableFrom (crowType)) miAddChild = typeof(TemplatedContainer).GetProperty("Content").GetSetMethod(); ++ else if (typeof(TemplatedControl).IsAssignableFrom (crowType)) ++ miAddChild = typeof(TemplatedControl).GetMethod ("loadTemplate", ++ BindingFlags.Instance | BindingFlags.NonPublic); else if (typeof(PrivateContainer).IsAssignableFrom (crowType)) miAddChild = typeof(PrivateContainer).GetMethod ("SetChild", BindingFlags.Instance | BindingFlags.NonPublic); diff --cc src/Interface.cs index f3d8c73b,517d481a..ba9769b1 --- a/src/Interface.cs +++ b/src/Interface.cs @@@ -82,7 -84,7 +84,7 @@@ namespace Cro public static FontOptions FontRenderingOptions; #endregion -- internal bool XmlLoading = false; ++ internal bool XmlLoading = true; public Dictionary Ressources = new Dictionary(); public Queue LayoutingQueue = new Queue (); diff --cc src/LayoutingQueueItem.cs index b2a5f3ca,b2a5f3ca..a7909022 --- a/src/LayoutingQueueItem.cs +++ b/src/LayoutingQueueItem.cs @@@ -107,10 -107,10 +107,10 @@@ namespace Cro Layoutable.RegisteredLayoutings |= LayoutType; Interface.CurrentInterface.DiscardQueue.Enqueue (this); } -- //#if DEBUG_LAYOUTING ++ #if DEBUG_LAYOUTING else Debug.WriteLine ("\tDELETED => " + this.ToString ()); -- //#endif ++ #endif } #if DEBUG_LAYOUTING currentLQI = null;