From: jpbruyere Date: Wed, 10 Jun 2015 08:30:48 +0000 (+0200) Subject: - fuse binding and event resolution contexts in GOMLResolver X-Git-Tag: 0.2~85 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=73c7ac95b12d72bcb3f5d549c76bdf0b5a093847;p=jp%2Fcrow.git - fuse binding and event resolution contexts in GOMLResolver --- diff --git a/src/GraphicObjects/Expandable.cs b/src/GraphicObjects/Expandable.cs index e3274ca0..6f215b2f 100644 --- a/src/GraphicObjects/Expandable.cs +++ b/src/GraphicObjects/Expandable.cs @@ -22,6 +22,7 @@ namespace go { bool _isExpanded; Label _caption; + Image _image; public Container Content; @@ -41,6 +42,14 @@ namespace go _caption = this.child.FindByName ("Caption") as Label; Content = this.child.FindByName ("Content") as Container; + _image = this.child.FindByName ("Image") as Image; + + if (_image == null) + return; + _image.SvgSub = "collapsed"; + this.Expand += (object sender, EventArgs e) => {_image.SvgSub = "expanded";}; + this.Collapse += (object sender, EventArgs e) => {_image.SvgSub = "collapsed";}; + } diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 8098f863..9cafe13b 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -685,7 +685,7 @@ namespace go if (string.IsNullOrEmpty (handler)) continue; - Interface.EventsToResolve.Add(new DynAttribute + Interface.GOMLResolver.Add(new DynAttribute { Source = this, Value = handler, @@ -770,7 +770,7 @@ namespace go throw new Exception (string.Format("GOML:Malformed binding: {0}", v)); string strBinding = v.Substring (1, v.Length - 2); - Interface.Bindings.Add (new DynAttribute () { + Interface.GOMLResolver.Add (new DynAttribute () { Source = this, MemberName = name, Value = strBinding diff --git a/src/Interface.cs b/src/Interface.cs index 29e276c0..0c3098fc 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -45,12 +45,12 @@ namespace go #region Load/Save - internal static Stack> EventsResolutionStack = new Stack>(); - internal static List EventsToResolve + internal static Stack> GOMLResolutionStack = new Stack>(); + internal static List GOMLResolver { - get { return EventsResolutionStack.Peek ();} + get { return GOMLResolutionStack.Peek ();} } - internal static List Bindings; + //internal static List Bindings; public static void Save(string file, T graphicObject) @@ -110,8 +110,7 @@ namespace go { //result = (T)(Load (file, hostClass) as object); - EventsResolutionStack.Push(new List()); - Bindings = new List (); + GOMLResolutionStack.Push(new List()); XmlSerializerNamespaces xn = new XmlSerializerNamespaces(); xn.Add("", ""); @@ -125,13 +124,13 @@ namespace go if (hostClass == null) return; - resolveEvents (hostClass); + resolveGOML (hostClass); - while (Bindings.Count > 0) { - DynAttribute binding = Bindings [0]; - Bindings.RemoveAt (0); - CompilerServices.ResolveBinding (binding, hostClass); - } +// while (Bindings.Count > 0) { +// DynAttribute binding = Bindings [0]; +// Bindings.RemoveAt (0); +// CompilerServices.ResolveBinding (binding, hostClass); +// } // foreach (DynAttribute binding in Bindings) { //// Type tSource = binding.Source.GetType (); //// if (!tSource.GetInterfaces ().Any (i => i.Name == "IValueChange")){ @@ -147,7 +146,7 @@ namespace go public static GraphicObject Load(Stream stream, Type type, object hostClass = null) { GraphicObject result; - EventsResolutionStack.Push(new List()); + GOMLResolutionStack.Push(new List()); XmlSerializerNamespaces xn = new XmlSerializerNamespaces(); xn.Add("", ""); @@ -155,16 +154,18 @@ namespace go result = (GraphicObject)xs.Deserialize(stream); - if (hostClass == null) + if (hostClass == null) { + GOMLResolutionStack.Pop (); return result; + } - resolveEvents (hostClass); + resolveGOML (hostClass); - while (Bindings.Count > 0) { - DynAttribute binding = Bindings [0]; - Bindings.RemoveAt (0); - CompilerServices.ResolveBinding (binding, hostClass); - } +// while (Bindings.Count > 0) { +// DynAttribute binding = Bindings [0]; +// Bindings.RemoveAt (0); +// CompilerServices.ResolveBinding (binding, hostClass); +// } // foreach (DynAttribute binding in Bindings) { // // Type tSource = binding.Source.GetType (); @@ -181,30 +182,42 @@ namespace go return result; } - static void resolveEvents(object hostClass) + static void resolveGOML(object hostClass) { - foreach (DynAttribute es in EventsToResolve) + foreach (DynAttribute es in GOMLResolver) { if (string.IsNullOrEmpty(es.Value)) continue; - if (es.Value.StartsWith ("{")) { - CompilerServices.CompileEventSource (es); - } else { - MethodInfo mi = hostClass.GetType ().GetMethod (es.Value, BindingFlags.NonPublic | BindingFlags.Public - | BindingFlags.Instance); + Type dstType = es.Source.GetType (); + MemberInfo miTarget = dstType.GetMember (es.MemberName).FirstOrDefault(); - if (mi == null) { - Debug.WriteLine ("Handler Method not found: " + es.Value); - continue; + if (miTarget == null) { + Debug.WriteLine ("'{0}' Member not found in '{1}' type.", es.MemberName, dstType.ToString ()); + continue; + } + + if (miTarget.MemberType == MemberTypes.Event) { + if (es.Value.StartsWith ("{")) { + CompilerServices.CompileEventSource (es); + } else { + MethodInfo mi = hostClass.GetType ().GetMethod (es.Value, BindingFlags.NonPublic | BindingFlags.Public + | BindingFlags.Instance); + + if (mi == null) { + Debug.WriteLine ("Handler Method not found: " + es.Value); + continue; + } + + FieldInfo fi = CompilerServices.getEventHandlerField (es.Source.GetType (), es.MemberName); + Delegate del = Delegate.CreateDelegate (fi.FieldType, hostClass, mi); + fi.SetValue (es.Source, del); } - - FieldInfo fi = CompilerServices.getEventHandlerField (es.Source.GetType (), es.MemberName); - Delegate del = Delegate.CreateDelegate(fi.FieldType, hostClass, mi); - fi.SetValue(es.Source, del); + } else { + CompilerServices.ResolveBinding (es, hostClass); } } - EventsResolutionStack.Pop(); + GOMLResolutionStack.Pop(); } #endregion }