replace xmlLoadingCount by xmlLoading.
modifié : src/GraphicObjects/ListBox.cs
modifié : src/GraphicObjects/TemplatedControl.cs
modifié : src/IMLStream.cs
modifié : src/Interface.cs
#endregion
void loading(){
if (itemTemplates == null)
- itemTemplates = new Dictionary<string, IMLStream> ();
+ itemTemplates = new Dictionary<string, ItemTemplate> ();
if (!itemTemplates.ContainsKey ("default"))
- itemTemplates["default"] = new IMLStream (ItemTemplate);
+ itemTemplates["default"] = new ItemTemplate (ItemTemplate);
for (int i = 1; i <= (data.Count / itemPerPage) + 1; i++) {
if (cancelLoading)
return;
GraphicObject g = null;
- IMLStream itemStream = null;
+ ItemTemplate itemStream = null;
Type dataType = data [i].GetType ();
if (itemTemplates.ContainsKey (dataType.FullName))
g.DataSource = data [i];
}
g.MouseClick += itemClick;
- if (!string.IsNullOrEmpty (itemStream.Datas)) {
-
+ if (itemStream.Expand != null && g is Expandable) {
+ (g as Expandable).Expand += itemStream.Expand;
}
//g.LogicalParent = this;
}
#region CTOR
public TemplatedControl () : base()
{
- if (Interface.XmlLoaderCount > 0)
+ if (Interface.CurrentInterface.XmlLoading)
return;
loadTemplate ();
}
string _template;
string _itemTemplate;
- protected Dictionary<string, IMLStream> itemTemplates;
+ protected Dictionary<string, ItemTemplate> itemTemplates;
[XmlAttributeAttribute][DefaultValue(null)]
public string Template {
itemTmp = xr.ReadInnerXml ();
if (itemTemplates == null)
- itemTemplates = new Dictionary<string, IMLStream> ();
+ itemTemplates = new Dictionary<string, ItemTemplate> ();
//TODO:check encoding
- itemTemplates[dataType] = new IMLStream (Encoding.UTF8.GetBytes(itemTmp));
- itemTemplates [dataType].Datas = datas;
+ itemTemplates[dataType] = new ItemTemplate (Encoding.UTF8.GetBytes(itemTmp));
+ itemTemplates [dataType].CreateExpandDelegate(dataType, datas);
continue;
}
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.IO;
+using System.Reflection;
+using System.Reflection.Emit;
namespace Crow
{
public class IMLStream : MemoryStream {
+ public string Path;
public Type RootType;
- //TODO:this has nothing to do in there, I should derive IMLStream
- public string Datas;
public IMLStream(string path) : base (){
+ Path = path;
using (Stream stream = Interface.GetStreamFromPath (path))
stream.CopyTo (this);
RootType = Interface.GetTopContainerOfXMLStream (this);
RootType = Interface.GetTopContainerOfXMLStream (this);
}
}
+ public class ItemTemplate : IMLStream {
+ public EventHandler Expand;
+
+ public ItemTemplate(string path)
+ : base(path){}
+ public ItemTemplate(Byte[] b)
+ : base(b){}
+
+ public void CreateExpandDelegate (string strDataType, string method){
+ Type dataType = Type.GetType(strDataType);
+ Type host_type = typeof(ItemTemplate);//not sure is the best place to put the dyn method
+ Type evt_type = typeof(EventHandler);
+
+ MethodInfo evtInvoke = evt_type.GetMethod ("Invoke");
+ ParameterInfo [] evtParams = evtInvoke.GetParameters ();
+ Type handlerArgsType = evtParams [1].ParameterType;
+
+ Type [] args = { typeof (object), typeof (object), handlerArgsType };
+ DynamicMethod dm = new DynamicMethod ("dyn_expand_" + method,
+ typeof (void),
+ args,
+ host_type);
+
+
+ #region IL generation
+ ILGenerator il = dm.GetILGenerator (256);
+
+ il.Emit (OpCodes.Ret);
+
+ #endregion
+
+ Expand = (EventHandler)dm.CreateDelegate (evt_type, this);
+ }
+ }
}
#endregion
#region Static and constants
- /// <summary> keep ressource path for debug msg </summary>
- internal static string CurrentGOMLPath = "";
- //used in templatedControl
- internal static int XmlLoaderCount = 0;
-
public static int TabSize = 4;
public static string LineBreak = "\r\n";
//TODO: shold be declared in graphicObject
System.Globalization.CultureInfo savedCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
- Interface.XmlLoaderCount ++;
- CurrentGOMLPath = path;
GraphicObject tmp = null;
try {
using (Stream stream = GetStreamFromPath (path)) {
tmp = Load(stream, GetTopContainerOfXMLStream(stream), hostClass);
}
} catch (Exception ex) {
- throw new Exception ("Error loading <" + CurrentGOMLPath + ">:", ex);
+ throw new Exception ("Error loading <" + path + ">:", ex);
}
- Interface.XmlLoaderCount --;
Thread.CurrentThread.CurrentCulture = savedCulture;