]> O.S.I.I.S - jp/crow.git/commitdiff
- fuse binding and event resolution contexts in GOMLResolver
authorjpbruyere <jp.bruyere@hotmail.com>
Wed, 10 Jun 2015 08:30:48 +0000 (10:30 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Wed, 10 Jun 2015 08:30:49 +0000 (10:30 +0200)
src/GraphicObjects/Expandable.cs
src/GraphicObjects/GraphicObject.cs
src/Interface.cs

index e3274ca024ec743e4c1c6d83e91205697259e2f8..6f215b2fe8e126aa8a6d407ca3c506cdfacc7da2 100644 (file)
@@ -22,6 +22,7 @@ namespace go
     {          \r
                bool _isExpanded;\r
                Label _caption;\r
+               Image _image;\r
 \r
                public Container Content;\r
 \r
@@ -41,6 +42,14 @@ namespace go
 \r
                        _caption = this.child.FindByName ("Caption") as Label;\r
                        Content = this.child.FindByName ("Content") as Container;\r
+                       _image = this.child.FindByName ("Image") as Image;\r
+\r
+                       if (_image == null)\r
+                               return;\r
+                       _image.SvgSub = "collapsed";\r
+                       this.Expand += (object sender, EventArgs e) => {_image.SvgSub = "expanded";};\r
+                       this.Collapse += (object sender, EventArgs e) => {_image.SvgSub = "collapsed";};\r
+\r
                }\r
                        \r
 \r
index 8098f86334e700c7dca1f34c53f36e7f0e922237..9cafe13bf11af349a5a14d93ac31ac7db1500539 100644 (file)
@@ -685,7 +685,7 @@ namespace go
                                if (string.IsNullOrEmpty (handler))\r
                                        continue;\r
                                        \r
-                               Interface.EventsToResolve.Add(new DynAttribute \r
+                               Interface.GOMLResolver.Add(new DynAttribute \r
                                        { \r
                                                Source = this, \r
                                                Value = handler,\r
@@ -770,7 +770,7 @@ namespace go
                                                                throw new Exception (string.Format("GOML:Malformed binding: {0}", v));\r
                                                        \r
                                                        string strBinding = v.Substring (1, v.Length - 2);\r
-                                                       Interface.Bindings.Add (new DynAttribute () {\r
+                                                       Interface.GOMLResolver.Add (new DynAttribute () {\r
                                                                Source = this,\r
                                                                MemberName = name,\r
                                                                Value = strBinding\r
index 29e276c04bd2d8968418907b4b41fba08cca2d96..0c3098fc1bf0eb02a88487f937825475e942ca4d 100644 (file)
@@ -45,12 +45,12 @@ namespace go
 
                #region Load/Save
 
-               internal static Stack<List<DynAttribute>> EventsResolutionStack = new Stack<List<DynAttribute>>();
-               internal static List<DynAttribute> EventsToResolve
+               internal static Stack<List<DynAttribute>> GOMLResolutionStack = new Stack<List<DynAttribute>>();
+               internal static List<DynAttribute> GOMLResolver
                {
-                       get { return EventsResolutionStack.Peek ();}
+                       get { return GOMLResolutionStack.Peek ();}
                }
-               internal static List<DynAttribute> Bindings;
+               //internal static List<DynAttribute> Bindings;
 
 
                public static void Save<T>(string file, T graphicObject)
@@ -110,8 +110,7 @@ namespace go
                {
                        //result = (T)(Load (file, hostClass) as object);
 
-                       EventsResolutionStack.Push(new List<DynAttribute>());
-                       Bindings = new List<DynAttribute> ();
+                       GOMLResolutionStack.Push(new List<DynAttribute>());
 
                        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<DynAttribute>());
+                       GOMLResolutionStack.Push(new List<DynAttribute>());
 
                        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
        }