From 39a9fa35ff36f8bcb3a88679e3658596d2e79b1c Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Tue, 6 Sep 2016 17:55:41 +0200 Subject: [PATCH] rebase master --- Templates/ComboBox.template | 2 +- Templates/ListBox.template | 2 +- Templates/ScrollingListBox.goml | 2 +- Templates/TreeView.template | 2 +- Templates/treeList.crow | 2 +- Tests/BasicTests.cs | 8 +- .../TemplatedContainer/testTreeView.crow | 2 +- .../TemplatedControl/testItemTemplateTag.crow | 2 +- appveyor.yml | 2 +- src/GraphicObjects/ListBox.cs | 208 +------------- src/GraphicObjects/MenuItem.cs | 4 +- src/GraphicObjects/TemplatedControl.cs | 36 +-- src/GraphicObjects/TemplatedGroup.cs | 256 +++++++++++++++++- src/GraphicObjects/TreeView.cs | 31 +-- src/IMLReader.cs | 6 +- src/ItemTemplate.cs | 17 +- 16 files changed, 288 insertions(+), 294 deletions(-) diff --git a/Templates/ComboBox.template b/Templates/ComboBox.template index 9688721a..d28a7b91 100755 --- a/Templates/ComboBox.template +++ b/Templates/ComboBox.template @@ -22,7 +22,7 @@ HorizontalAlignment="Left" ValueChanged="../../../_scroller_ValueChanged"> diff --git a/Templates/ListBox.template b/Templates/ListBox.template index c56ec0d0..36f2f61e 100755 --- a/Templates/ListBox.template +++ b/Templates/ListBox.template @@ -4,6 +4,6 @@ Height="{./HeightPolicy}" Width="{./WidthPolicy}" ValueChanged="./_scroller_ValueChanged"> + Height="Fit" Width="{./WidthPolicy}" Name="ItemsContainer" Margin="0" VerticalAlignment="Top"/> \ No newline at end of file diff --git a/Templates/ScrollingListBox.goml b/Templates/ScrollingListBox.goml index a746cb65..54e3eb48 100644 --- a/Templates/ScrollingListBox.goml +++ b/Templates/ScrollingListBox.goml @@ -5,7 +5,7 @@ Margin="2" VerticalScrolling="true" ScrollY="{../scrollbar1.Value}" ValueChanged="./_scroller_ValueChanged"> + Height="Fit" Width="{./WidthPolicy}" Name="ItemsContainer" Margin="0" VerticalAlignment="Top"/> \ No newline at end of file + Height="Fit" Width="{../WidthPolicy}" Name="ItemsContainer"/> \ No newline at end of file diff --git a/Tests/BasicTests.cs b/Tests/BasicTests.cs index 62ddc567..cd9e3ba3 100644 --- a/Tests/BasicTests.cs +++ b/Tests/BasicTests.cs @@ -145,8 +145,12 @@ namespace Tests idx = testFiles.Length - 1; this.Title = testFiles [idx] + ". Press to cycle examples."; - GraphicObject obj = CrowInterface.LoadInterface(testFiles[idx]); - obj.DataSource = this; + try { + GraphicObject obj = CrowInterface.LoadInterface(testFiles[idx]); + obj.DataSource = this; + } catch (Exception ex) { + Debug.WriteLine (ex.Message + ex.InnerException); + } } void Tv_SelectedItemChanged (object sender, SelectionChangeEventArgs e) { diff --git a/Tests/Interfaces/TemplatedContainer/testTreeView.crow b/Tests/Interfaces/TemplatedContainer/testTreeView.crow index 3a44bf34..e8e71645 100755 --- a/Tests/Interfaces/TemplatedContainer/testTreeView.crow +++ b/Tests/Interfaces/TemplatedContainer/testTreeView.crow @@ -32,7 +32,7 @@ diff --git a/Tests/Interfaces/TemplatedControl/testItemTemplateTag.crow b/Tests/Interfaces/TemplatedControl/testItemTemplateTag.crow index 5f860719..94625915 100755 --- a/Tests/Interfaces/TemplatedControl/testItemTemplateTag.crow +++ b/Tests/Interfaces/TemplatedControl/testItemTemplateTag.crow @@ -10,7 +10,7 @@ Margin="2" VerticalScrolling="true" ScrollY="{../scrollbar1.Value}" ValueChanged="../../../_scroller_ValueChanged"> diff --git a/appveyor.yml b/appveyor.yml index dad396ef..358d2b61 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,7 +2,7 @@ version: 0.4.{build} branches: only: - - appveyor + - master clone_depth: 1 diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs index f91a9836..82a4014b 100644 --- a/src/GraphicObjects/ListBox.cs +++ b/src/GraphicObjects/ListBox.cs @@ -30,218 +30,12 @@ using System.Threading; namespace Crow { - public class ListBox : TemplatedControl + public class ListBox : TemplatedGroup { #region CTOR public ListBox () : base() {} #endregion - #region events - public event EventHandler SelectedItemChanged; - #endregion - - Group _list; - GenericStack _gsList; - IList data; - int _selectedIndex; - int itemPerPage = 50; - Thread loadingThread = null; - volatile bool cancelLoading = false; - - [XmlAttributeAttribute]public IList Data { - get { - return data; - } - set { - if (value == data) - return; - - cancelLoadingThread (); - - data = value; - - NotifyValueChanged ("Data", data); - - lock (CurrentInterface.UpdateMutex) - _list.ClearChildren (); - if (_gsList.Orientation == Orientation.Horizontal) - _gsList.Width = -1; - else - _gsList.Height = -1; - - if (data == null) - return; - - loadingThread = new Thread (loading); - loadingThread.IsBackground = true; - loadingThread.Start (); - //loadPage(1); - - NotifyValueChanged ("SelectedIndex", _selectedIndex); - NotifyValueChanged ("SelectedItem", SelectedItem); - SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem)); - } - } - - [XmlAttributeAttribute][DefaultValue(-1)]public int SelectedIndex{ - get { return _selectedIndex; } - set { - if (value == _selectedIndex) - return; - - _selectedIndex = value; - - NotifyValueChanged ("SelectedIndex", _selectedIndex); - NotifyValueChanged ("SelectedItem", SelectedItem); - SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem)); - } - } - [XmlIgnore]public virtual object SelectedItem{ - get { return data == null ? null : _selectedIndex < 0 ? null : data[_selectedIndex]; } - } - protected void raiseSelectedItemChanged(){ - SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem)); - } - - #region TemplatedControl override - protected override void loadTemplate (GraphicObject template = null) - { - base.loadTemplate (template); - _list = this.child.FindByName ("List") as Group; - if (_list == null) - throw new Exception ("ListBox Template MUST contain a Goup widget named 'List'."); - _gsList = _list as GenericStack; - } - #endregion - - void loading(){ - if (ItemTemplates == null) - ItemTemplates = new Dictionary (); - if (!ItemTemplates.ContainsKey ("default")) - ItemTemplates ["default"] = Interface.GetItemTemplate (ItemTemplate); - - for (int i = 1; i <= (data.Count / itemPerPage) + 1; i++) { - if (cancelLoading) - return; - loadPage (i); - } - } - void cancelLoadingThread(){ - if (loadingThread == null) - return; - if (!loadingThread.IsAlive) - return; - cancelLoading = true; - loadingThread.Join (); - cancelLoading = false; - } - void loadPage(int pageNum) - { - #if DEBUG_LOAD - Stopwatch loadingTime = new Stopwatch (); - loadingTime.Start (); - #endif - - Group page = _list.Clone () as Group; - - page.Name = "page" + pageNum; - - //reset size to fit in the dir of the stacking - //because _list total size is forced to approx size - if (_gsList.Orientation == Orientation.Horizontal) { - page.Width = Measure.Fit; - page.BindMember ("Height", "../HeightPolicy"); - } else { - page.Height = Measure.Fit; - page.BindMember ("Width", "../WidthPolicy"); - } - - for (int i = (pageNum - 1) * itemPerPage; i < pageNum * itemPerPage; i++) { - if (i >= data.Count) - break; - if (cancelLoading) - return; - - loadItem (i, page); - - //g.LogicalParent = this; - } - - lock (CurrentInterface.LayoutMutex) - _list.AddChild (page); - - #if DEBUG_LOAD - loadingTime.Stop (); - Debug.WriteLine("Listbox {2} Loading: {0} ticks \t, {1} ms", - loadingTime.ElapsedTicks, - loadingTime.ElapsedMilliseconds, this.ToString()); - #endif - } - protected void loadItem(int i, Group page){ - GraphicObject g = null; - ItemTemplate iTemp = null; - Type dataType = data [i].GetType (); - - while (dataType.FullName != "System.Object") { - if (ItemTemplates.ContainsKey (dataType.FullName)) { - iTemp = ItemTemplates [dataType.FullName]; - break; - } - dataType = dataType.BaseType; - if (dataType == null) - break; - } - - if (iTemp == null) - iTemp = ItemTemplates ["default"]; - - lock (CurrentInterface.LayoutMutex) { - g = iTemp.CreateInstance(CurrentInterface); - page.AddChild (g); - g.DataSource = data [i]; - } - - registerItemClick (g); - - if (iTemp.Expand != null && g is Expandable) { - (g as Expandable).Expand += iTemp.Expand; - } - } - protected virtual void registerItemClick(GraphicObject g){ - g.MouseClick += itemClick; - } - protected void _list_LayoutChanged (object sender, LayoutingEventArgs e) - { -#if DEBUG_LAYOUTING - Debug.WriteLine("list_LayoutChanged"); -#endif - if (_gsList.Orientation == Orientation.Horizontal) { - if (e.LayoutType == LayoutingType.Width) - _gsList.Width = approxSize; - } else if (e.LayoutType == LayoutingType.Height) - _gsList.Height = approxSize; - } - int approxSize - { - get { - if (data == null) - return -1; - GenericStack page1 = _list.FindByName ("page1") as GenericStack; - if (page1 == null) - return -1; - - return page1.Orientation == Orientation.Horizontal ? - data.Count < itemPerPage ? - -1: - (int)Math.Ceiling ((double)page1.Slot.Width / (double)itemPerPage * (double)(data.Count+1)): - data.Count < itemPerPage ? - -1: - (int)Math.Ceiling ((double)page1.Slot.Height / (double)itemPerPage * (double)(data.Count+1)); - } - } - internal virtual void itemClick(object sender, MouseButtonEventArgs e){ - SelectedIndex = data.IndexOf((sender as GraphicObject).DataSource); - } } } diff --git a/src/GraphicObjects/MenuItem.cs b/src/GraphicObjects/MenuItem.cs index 60233361..78162fbb 100644 --- a/src/GraphicObjects/MenuItem.cs +++ b/src/GraphicObjects/MenuItem.cs @@ -101,11 +101,11 @@ namespace Crow { Execute.Raise (this, null); } - void onOpen (object sender, EventArgs e){ + protected virtual void onOpen (object sender, EventArgs e){ MenuRoot.IsOpened = true; Open.Raise (this, null); } - void onClose (object sender, EventArgs e){ + protected virtual void onClose (object sender, EventArgs e){ //MenuRoot.IsOpened = true; Close.Raise (this, null); } diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs index cb14dfd9..7f2e1b87 100644 --- a/src/GraphicObjects/TemplatedControl.cs +++ b/src/GraphicObjects/TemplatedControl.cs @@ -46,9 +46,6 @@ namespace Crow } string _template; - string _itemTemplate; - 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; } @@ -63,19 +60,7 @@ namespace Crow loadTemplate (CurrentInterface.Load (_template)); } } - [XmlAttributeAttribute][DefaultValue("#Crow.Templates.ItemTemplate.goml")] - public string ItemTemplate { - get { return _itemTemplate; } - set { - if (value == _itemTemplate) - return; - _itemTemplate = value; - - //TODO:reload list with new template? - NotifyValueChanged("ItemTemplate", _itemTemplate); - } - } #region GraphicObject overrides public override GraphicObject FindByName (string nameToFind) { @@ -86,7 +71,7 @@ namespace Crow { //onDraw is overrided to prevent default drawing of background, template top container //may have a binding to root background or a fixed one. - //this allow applying root background to random template component + //this allow applying root background to random template's component gr.Save (); if (ClipToClientRect) { @@ -113,6 +98,7 @@ namespace Crow this.ResolveBindings (); } + //TODO:IXmlSerializable is not used anymore #region IXmlSerializable public override System.Xml.Schema.XmlSchema GetSchema(){ return null; } public override void ReadXml(System.Xml.XmlReader reader) @@ -151,15 +137,15 @@ namespace Crow xr.MoveToElement (); itemTmp = xr.ReadInnerXml (); - if (ItemTemplates == null) - ItemTemplates = new Dictionary (); - - using (IMLReader iTmp = new IMLReader (null, itemTmp)) { - ItemTemplates [dataType] = - new ItemTemplate (iTmp.RootType, iTmp.GetLoader (), dataType, datas); - } - if (!string.IsNullOrEmpty (datas)) - ItemTemplates [dataType].CreateExpandDelegate(this); +// if (ItemTemplates == null) +// ItemTemplates = new Dictionary (); +// +// using (IMLReader iTmp = new IMLReader (null, itemTmp)) { +// ItemTemplates [dataType] = +// new ItemTemplate (iTmp.RootType, iTmp.GetLoader (), dataType, datas); +// } +// if (!string.IsNullOrEmpty (datas)) +// ItemTemplates [dataType].CreateExpandDelegate(this); continue; } diff --git a/src/GraphicObjects/TemplatedGroup.cs b/src/GraphicObjects/TemplatedGroup.cs index 0d48b9eb..500e5ea6 100644 --- a/src/GraphicObjects/TemplatedGroup.cs +++ b/src/GraphicObjects/TemplatedGroup.cs @@ -23,6 +23,9 @@ using System.Xml.Serialization; using System.Xml; using System.Reflection; using System.Collections.Generic; +using System.ComponentModel; +using System.Collections; +using System.Threading; namespace Crow { @@ -33,8 +36,127 @@ namespace Crow #endregion protected Group items; + string _itemTemplate; + + #region events + public event EventHandler SelectedItemChanged; + #endregion + + Group _list; + IList data; + int _selectedIndex; + Color selBackground, selForeground; + + int itemPerPage = 50; + Thread loadingThread = null; + volatile bool cancelLoading = false; + + #region Templating + //TODO: dont instantiate ItemTemplates if not used + //but then i should test if null in msil gen + public Dictionary ItemTemplates = new Dictionary(); + + [XmlAttributeAttribute][DefaultValue("#Crow.Templates.ItemTemplate.goml")] + public string ItemTemplate { + get { return _itemTemplate; } + set { + if (value == _itemTemplate) + return; + + _itemTemplate = value; + + //TODO:reload list with new template? + NotifyValueChanged("ItemTemplate", _itemTemplate); + } + } + protected override void loadTemplate(GraphicObject template = null) + { + base.loadTemplate (template); + + items = this.child.FindByName ("ItemsContainer") as Group; + if (items == null) + throw new Exception ("TemplatedGroup template Must contain a Group named 'ItemsContainer'"); + if (items.Children.Count == 0) + NotifyValueChanged ("HasChildren", false); + else + NotifyValueChanged ("HasChildren", true); + } + #endregion public virtual List Items{ get { return items.Children; }} + [XmlAttributeAttribute][DefaultValue(-1)]public int SelectedIndex{ + get { return _selectedIndex; } + set { + if (value == _selectedIndex) + return; + + _selectedIndex = value; + + NotifyValueChanged ("SelectedIndex", _selectedIndex); + NotifyValueChanged ("SelectedItem", SelectedItem); + SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem)); + } + } + [XmlIgnore]public virtual object SelectedItem{ + get { return data == null ? null : _selectedIndex < 0 ? null : data[_selectedIndex]; } + } + + [XmlAttributeAttribute]public IList Data { + get { return data; } + set { + if (value == data) + return; + + cancelLoadingThread (); + + data = value; + + NotifyValueChanged ("Data", data); + + lock (CurrentInterface.UpdateMutex) + ClearItems (); + + if (data == null) + return; + + loadingThread = new Thread (loading); + loadingThread.IsBackground = true; + loadingThread.Start (); + //loadPage(1); + + NotifyValueChanged ("SelectedIndex", _selectedIndex); + NotifyValueChanged ("SelectedItem", SelectedItem); + SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem)); + } + } + + [XmlAttributeAttribute][DefaultValue("SteelBlue")]//DeepJungleGreen + public virtual Color SelectionBackground { + get { return selBackground; } + set { + if (value == selBackground) + return; + selBackground = value; + NotifyValueChanged ("SelectionBackground", selBackground); + RegisterForRedraw (); + } + } + [XmlAttributeAttribute][DefaultValue("White")] + public virtual Color SelectionForeground { + get { return selForeground; } + set { + if (value == selForeground) + return; + selForeground = value; + NotifyValueChanged ("SelectionForeground", selForeground); + RegisterForRedraw (); + } + } + + protected void raiseSelectedItemChanged(){ + SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem)); + } + public virtual void AddItem(GraphicObject g){ items.AddChild (g); @@ -53,18 +175,6 @@ namespace Crow NotifyValueChanged ("HasChildren", false); } - protected override void loadTemplate(GraphicObject template = null) - { - base.loadTemplate (template); - - items = this.child.FindByName ("ItemsContainer") as Group; - if (items == null) - throw new Exception ("TemplatedGroup template Must contain a Group named 'ItemsContainer'"); - if (items.Children.Count == 0) - NotifyValueChanged ("HasChildren", false); - else - NotifyValueChanged ("HasChildren", true); - } #region GraphicObject overrides public override GraphicObject FindByName (string nameToFind) @@ -160,5 +270,127 @@ namespace Crow throw new NotImplementedException (); } #endregion + + void loading(){ + if (ItemTemplates == null) + ItemTemplates = new Dictionary (); + if (!ItemTemplates.ContainsKey ("default")) + ItemTemplates ["default"] = Interface.GetItemTemplate (ItemTemplate); + + for (int i = 1; i <= (data.Count / itemPerPage) + 1; i++) { + if (cancelLoading) + return; + loadPage (i); + } + } + void cancelLoadingThread(){ + if (loadingThread == null) + return; + if (!loadingThread.IsAlive) + return; + cancelLoading = true; + loadingThread.Join (); + cancelLoading = false; + } + void loadPage(int pageNum) + { + #if DEBUG_LOAD + Stopwatch loadingTime = new Stopwatch (); + loadingTime.Start (); + #endif + + Group page = items.Clone () as Group; + + page.Name = "page" + pageNum; + +// //reset size to fit in the dir of the stacking +// //because items total size is forced to approx size +// if (_gsList.Orientation == Orientation.Horizontal) { +// page.Width = Measure.Fit; + page.BindMember ("Height", "../HeightPolicy"); + page.BindMember ("Width", "../WidthPolicy"); +// } else { +// page.Height = Measure.Fit; +// page.BindMember ("Width", "../WidthPolicy"); +// } + + for (int i = (pageNum - 1) * itemPerPage; i < pageNum * itemPerPage; i++) { + if (i >= data.Count) + break; + if (cancelLoading) + return; + + loadItem (i, page); + + //g.LogicalParent = this; + } + + lock (CurrentInterface.LayoutMutex) + items.AddChild (page); + + #if DEBUG_LOAD + loadingTime.Stop (); + Debug.WriteLine("Listbox {2} Loading: {0} ticks \t, {1} ms", + loadingTime.ElapsedTicks, + loadingTime.ElapsedMilliseconds, this.ToString()); + #endif + } + protected void loadItem(int i, Group page){ + GraphicObject g = null; + ItemTemplate iTemp = null; + Type dataType = data [i].GetType (); + + if (ItemTemplates.ContainsKey (dataType.FullName)) + iTemp = ItemTemplates [dataType.FullName]; + else + iTemp = ItemTemplates ["default"]; + + lock (CurrentInterface.LayoutMutex) { + g = iTemp.CreateInstance(CurrentInterface); + page.AddChild (g); + g.DataSource = data [i]; + } + + registerItemClick (g); + + if (iTemp.Expand != null && g is Expandable) { + (g as Expandable).Expand += iTemp.Expand; + } + } + protected virtual void registerItemClick(GraphicObject g){ + g.MouseClick += itemClick; + } +// protected void _list_LayoutChanged (object sender, LayoutingEventArgs e) +// { +// #if DEBUG_LAYOUTING +// Debug.WriteLine("list_LayoutChanged"); +// #endif +// if (_gsList.Orientation == Orientation.Horizontal) { +// if (e.LayoutType == LayoutingType.Width) +// _gsList.Width = approxSize; +// } else if (e.LayoutType == LayoutingType.Height) +// _gsList.Height = approxSize; +// } + int approxSize + { + get { + if (data == null) + return -1; + GenericStack page1 = items.FindByName ("page1") as GenericStack; + if (page1 == null) + return -1; + + return page1.Orientation == Orientation.Horizontal ? + data.Count < itemPerPage ? + -1: + (int)Math.Ceiling ((double)page1.Slot.Width / (double)itemPerPage * (double)(data.Count+1)): + data.Count < itemPerPage ? + -1: + (int)Math.Ceiling ((double)page1.Slot.Height / (double)itemPerPage * (double)(data.Count+1)); + } + } + internal virtual void itemClick(object sender, MouseButtonEventArgs e){ + SelectedIndex = data.IndexOf((sender as GraphicObject).DataSource); + } } } diff --git a/src/GraphicObjects/TreeView.cs b/src/GraphicObjects/TreeView.cs index 78786cd7..4fa881b4 100644 --- a/src/GraphicObjects/TreeView.cs +++ b/src/GraphicObjects/TreeView.cs @@ -27,17 +27,17 @@ namespace Crow { //treeview expect expandable child (or not) //if their are expandable, some functions and events are added - public class TreeView : ListBox + public class TreeView : TemplatedGroup { GraphicObject selectedItemContainer = null; - Color selBackground; - Color selForeground; bool isRoot; - + #region CTOR public TreeView () : base() { } + #endregion + [XmlAttributeAttribute()][DefaultValue(false)] public virtual bool IsRoot { get { return isRoot; } @@ -49,29 +49,6 @@ namespace Crow } } - [XmlAttributeAttribute][DefaultValue("SteelBlue")]//DeepJungleGreen - public virtual Color SelectionBackground { - get { return selBackground; } - set { - if (value == selBackground) - return; - selBackground = value; - NotifyValueChanged ("SelectionBackground", selBackground); - RegisterForRedraw (); - } - } - [XmlAttributeAttribute][DefaultValue("White")] - public virtual Color SelectionForeground { - get { return selForeground; } - set { - if (value == selForeground) - return; - selForeground = value; - NotifyValueChanged ("SelectionForeground", selForeground); - RegisterForRedraw (); - } - } - [XmlIgnore]public override object SelectedItem { get { return selectedItemContainer == null ? diff --git a/src/IMLReader.cs b/src/IMLReader.cs index bf6cbc49..ad4fd835 100644 --- a/src/IMLReader.cs +++ b/src/IMLReader.cs @@ -101,7 +101,7 @@ namespace Crow il.Emit (OpCodes.Ldloc_0);//save current go onto the stack if child has to be added - #region Template and TemplateItems loading + #region Template and ItemTemplates loading if (typeof(TemplatedControl).IsAssignableFrom (crowType)) { //if its a template, first read template elements using (IMLReader reader = new IMLReader (il, tmpXml)) { @@ -168,7 +168,7 @@ namespace Crow foreach (string[] iTempId in itemTemplateIds) { reader.il.Emit (OpCodes.Ldloc_0);//load TempControl ref reader.il.Emit (OpCodes.Ldfld,//load ItemTemplates dic field - typeof(TemplatedControl).GetField("ItemTemplates")); + typeof(TemplatedGroup).GetField("ItemTemplates")); reader.il.Emit (OpCodes.Ldstr, iTempId[0]);//load key reader.il.Emit (OpCodes.Ldstr, iTempId[1]);//load value reader.il.Emit (OpCodes.Callvirt, @@ -181,7 +181,7 @@ namespace Crow //expand delegate creation reader.il.Emit (OpCodes.Ldloc_0);//load TempControl ref reader.il.Emit (OpCodes.Ldfld,//load ItemTemplates dic field - typeof(TemplatedControl).GetField ("ItemTemplates")); + typeof(TemplatedGroup).GetField ("ItemTemplates")); reader.il.Emit (OpCodes.Ldstr, iTempId [0]);//load key reader.il.Emit (OpCodes.Callvirt, typeof(Dictionary).GetMethod ("get_Item", diff --git a/src/ItemTemplate.cs b/src/ItemTemplate.cs index ed3459a8..a1f67786 100644 --- a/src/ItemTemplate.cs +++ b/src/ItemTemplate.cs @@ -50,12 +50,14 @@ namespace Crow } #endregion - public void CreateExpandDelegate (TemplatedControl host){ - Type hostType = typeof(TemplatedControl);//not sure is the best place to put the dyn method + public void CreateExpandDelegate (TemplatedGroup host){ + Type dataType = Type.GetType(strDataType); + Type tmpGrpType = typeof(TemplatedGroup); + Type hostType = tmpGrpType;//not sure is the best place to put the dyn method Type evtType = typeof(EventHandler); - Type listBoxType = typeof(ListBox); - PropertyInfo piListData = listBoxType.GetProperty ("Data"); + + PropertyInfo piData = tmpGrpType.GetProperty ("Data"); MethodInfo evtInvoke = evtType.GetMethod ("Invoke"); ParameterInfo [] evtParams = evtInvoke.GetParameters (); @@ -87,13 +89,13 @@ namespace Crow //check that 'Data' of list is not already set il.Emit (OpCodes.Ldloc_0); - il.Emit (OpCodes.Callvirt, piListData.GetGetMethod ()); + il.Emit (OpCodes.Callvirt, piData.GetGetMethod ()); il.Emit (OpCodes.Brfalse, ifDataIsNull); il.Emit (OpCodes.Br, gotoEnd); il.MarkLabel(ifDataIsNull); //copy the ref of ItemTemplates list TODO: maybe find another way to share it among the nodes? - FieldInfo fiTemplates = typeof(TemplatedControl).GetField("ItemTemplates"); + FieldInfo fiTemplates = tmpGrpType.GetField("ItemTemplates"); il.Emit (OpCodes.Ldloc_0); il.Emit (OpCodes.Ldarg_0); il.Emit (OpCodes.Ldfld, fiTemplates); @@ -105,12 +107,11 @@ namespace Crow il.Emit (OpCodes.Callvirt, typeof(GraphicObject).GetProperty("DataSource").GetGetMethod ()); if (fetchMethodName != "self"){//special keyword self allows the use of recurent list<<< - Type dataType = Type.GetType(strDataType); emitGetSubData(il, dataType); } //set 'return' from the fetch method as 'data' of the list - il.Emit (OpCodes.Callvirt, piListData.GetSetMethod ()); + il.Emit (OpCodes.Callvirt, piData.GetSetMethod ()); il.MarkLabel(gotoEnd); il.Emit (OpCodes.Ret); -- 2.47.3