]> O.S.I.I.S - jp/crow.git/commitdiff
* Interface.cs:
authorjpbruyere <jp.bruyere@hotmail.com>
Wed, 16 Sep 2015 13:16:45 +0000 (15:16 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Wed, 16 Sep 2015 13:16:45 +0000 (15:16 +0200)
* GraphicObject.cs:
* TemplatedControl.cs:
* CompilerServices.cs: Free references queue for dynamic bindings
prevent adding reference to spurious object creation during serializer
  init which cause alien ref impossible to clear

* testPopper.goml: f

Tests/Interfaces/testPopper.goml
src/CompilerServices/CompilerServices.cs
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/TemplatedControl.cs
src/Interface.cs

index 8f66d751e332e94b63779c5606f9870eb68cb72d..114f471a32b5cf3585c2c7c195b262ff60201469 100755 (executable)
@@ -1,6 +1,12 @@
 <?xml version="1.0"?>\r
 <Popper Title="TestPopper" Width="100" Background="DimGray">\r
        <Border Fit="True" Background="ArmyGreen">\r
-               <Image Fit="true" Path="#go.Images.Icons.tetra.png" Margin="10"/>\r
+<!--           <Image Fit="true" Path="#go.Images.Icons.tetra.png" Margin="10"/>-->\r
+               <VerticalStack Fit="true" Background="Blue">\r
+                       <Checkbox Name="chk1"/>\r
+                       <Checkbox Name="chk2" IsChecked="true"/>\r
+                       <Checkbox Name="chk3"/>\r
+                       <Checkbox Name="chk4"/>\r
+               </VerticalStack>        \r
        </Border>\r
 </Popper>\r
index 3d4ebc5afacb1fe54bd28332661ace385f8567cc..1f5df063bcea6a53fb46fa3f848aa60e8436979c 100644 (file)
@@ -254,14 +254,7 @@ namespace go
                        dynHandleCpt++;
 
                        //register target object reference
-                       int dstIdx = Interface.References.IndexOf(binding.Source);
-
-                       if (dstIdx < 0) {
-                               dstIdx = Interface.References.Count;
-                               Interface.References.Add (binding.Source);
-                       }
-
-
+                       int dstIdx = Interface.Reference(binding.Source);
 
                        #region IL generation
                        ILGenerator il = dm.GetILGenerator(256);
index 41720ed95fb55eb69d9f79b68b321973ebdf6c66..a068a0d50466f3c5c7b240767abe3eafe420b526 100644 (file)
@@ -749,7 +749,10 @@ namespace go
 \r
                public override string ToString ()\r
                {\r
-                       return Name == "unamed" ? this.GetType ().ToString() : Name;\r
+                       string tmp ="";\r
+                       if (Parent != null)\r
+                               tmp = Parent.ToString () + tmp;\r
+                       return Name == "unamed" ? tmp + "." + this.GetType ().Name : tmp + "." + Name;\r
                }\r
                        \r
                #region IXmlSerializable\r
@@ -771,11 +774,13 @@ namespace go
                                        continue;\r
                                }\r
                                if (mi.MemberType == MemberTypes.Event) {\r
-                                       Interface.GOMLResolver.Add (new DynAttribute { \r
-                                               Source = this, \r
-                                               Value = attValue,\r
-                                               MemberName = attName\r
-                                       });\r
+                                       if (!Interface.DontResoveGOML) {\r
+                                               Interface.GOMLResolver.Add (new DynAttribute { \r
+                                                       Source = this, \r
+                                                       Value = attValue,\r
+                                                       MemberName = attName\r
+                                               });\r
+                                       }\r
                                } else if (mi.MemberType == MemberTypes.Property) {\r
                                        PropertyInfo pi = mi as PropertyInfo;\r
 \r
@@ -817,6 +822,8 @@ namespace go
                                        } else {\r
 \r
                                                if (attValue.StartsWith("{")) {\r
+                                                       if (Interface.DontResoveGOML)\r
+                                                               continue;\r
                                                        //binding\r
                                                        if (!attValue.EndsWith("}"))\r
                                                                throw new Exception (string.Format("GOML:Malformed binding: {0}", attValue));\r
@@ -944,27 +951,26 @@ namespace go
                /// </summary>\r
                public virtual void ClearBinding(){\r
                        object ds = this.DataSource;\r
-                       if (ds == null)\r
-                               return;\r
-                       \r
-                       Type dataSourceType = ds.GetType ();\r
-                       EventInfo evtInfo = dataSourceType.GetEvent ("ValueChanged");\r
-                       if (evtInfo != null) {\r
-                               FieldInfo evtFi = CompilerServices.GetEventHandlerField (dataSourceType, "ValueChanged");\r
-                               MulticastDelegate multicastDelegate = evtFi.GetValue (ds) as MulticastDelegate;\r
-                               if (multicastDelegate != null) {                                \r
-                                       foreach (Delegate d in multicastDelegate.GetInvocationList()) {\r
-                                               string dn = d.Method.Name;\r
-                                               if (!dn.StartsWith ("dynHandle_"))\r
-                                                       continue;\r
-                                               int did = int.Parse (dn.Substring (10));\r
-                                               if (this.DynamicMethodIds.Contains (did))\r
-                                                       evtInfo.RemoveEventHandler (ds, d);\r
+                       if (ds != null) {\r
+                               Type dataSourceType = ds.GetType ();\r
+                               EventInfo evtInfo = dataSourceType.GetEvent ("ValueChanged");\r
+                               if (evtInfo != null) {\r
+                                       FieldInfo evtFi = CompilerServices.GetEventHandlerField (dataSourceType, "ValueChanged");\r
+                                       MulticastDelegate multicastDelegate = evtFi.GetValue (ds) as MulticastDelegate;\r
+                                       if (multicastDelegate != null) {                                \r
+                                               foreach (Delegate d in multicastDelegate.GetInvocationList()) {\r
+                                                       string dn = d.Method.Name;\r
+                                                       if (!dn.StartsWith ("dynHandle_"))\r
+                                                               continue;\r
+                                                       int did = int.Parse (dn.Substring (10));\r
+                                                       if (this.DynamicMethodIds.Contains (did))\r
+                                                               evtInfo.RemoveEventHandler (ds, d);\r
+                                               }\r
                                        }\r
                                }\r
                        }\r
-                               \r
-                       Interface.References.Remove (this);\r
+                       Interface.Unreference (this);\r
+\r
                }\r
        }\r
 }\r
index 87bbeb09a734a1c263b3840630b00ce7ee9a1043..0599c6e39826e7388ae544ef4871172df017c40d 100644 (file)
@@ -104,7 +104,7 @@ namespace go
                {
                        if (template == null) {
                                DefaultTemplate dt = (DefaultTemplate)this.GetType ().GetCustomAttributes (typeof(DefaultTemplate), true).FirstOrDefault();
-                               this.SetChild (Interface.Load (dt.Path, this));
+                               this.SetChild (Interface.Load (dt.Path, this,!Interface.DontResoveGOML));
                        }else
                                this.SetChild (template);
                }
@@ -146,13 +146,14 @@ namespace go
 
                                                                xr.Read ();//go close tag
                                                                xr.Read ();//Template close tag
+                                                               break;
                                                        } else {
                                                                xr.ReadInnerXml ();
                                                        }
                                                }
                                        }                               
                                } else
-                                       loadTemplate (Interface.Load (template, this));
+                                       loadTemplate (Interface.Load (template, this, !Interface.DontResoveGOML));
                                
 
                                //normal xml read
index c3ddc8fad009053f6e87ab24372e993e56ef957b..723bdad70ec249e8d3d177f42166856b29a221da 100644 (file)
@@ -36,6 +36,7 @@ namespace go
                public static bool ReplaceTabsWithSpace = false;
                /// <summary> Allow rendering of interface in development environment </summary>
                public static bool DesignerMode = false;
+               public static bool DontResoveGOML = false;
                /// <summary> Threshold to catch borders for sizing </summary>
                public static int BorderThreshold = 5;
 
@@ -43,7 +44,32 @@ namespace go
                /// Graphic objects References use in dynamic delegates for binding
                /// </summary>
                public static List<object> References = new List<object>();
+               public static Queue<int> FreeRefIndices = new Queue<int>();
+               public static void Unreference(Object o)
+               {
+                       int idxt = Interface.References.IndexOf (o);
+                       if (idxt < 0)
+                               return;
+                       References[idxt] = null;
+                       FreeRefIndices.Enqueue (idxt);
+               }
+               /// <summary> register target object reference in an array for binding CIL </summary>
+               public static int Reference(object o)
+               {
+                       
+                       int dstIdx = Interface.References.IndexOf(o);
 
+                       if (dstIdx < 0) {
+                               if (FreeRefIndices.Count == 0) {
+                                       dstIdx = Interface.References.Count;
+                                       Interface.References.Add (o);
+                               } else {
+                                       dstIdx = FreeRefIndices.Dequeue ();
+                                       Interface.References [dstIdx] = o;
+                               }
+                       }
+                       return dstIdx;
+               }
                public static LayoutingQueue LayoutingQueue = new LayoutingQueue();
 
                #region Load/Save
@@ -110,22 +136,26 @@ namespace go
                        return t;
                }
                public static string CurrentGOMLPath;
-               public static GraphicObject Load(string path, object hostClass = null)
+               public static GraphicObject Load(string path, object hostClass = null, bool resolveGOML = true)
                {                       
                        CurrentGOMLPath = path;
                        using (Stream stream = GetStreamFromPath (path)) {
-                               return Load(stream, GetTopContainerOfGOMLStream(stream), hostClass);
+                               return Load(stream, GetTopContainerOfGOMLStream(stream), hostClass, resolveGOML);
                        }
                        CurrentGOMLPath = "";
                }
                public static GraphicObject Load(Stream stream, Type type, object hostClass = null, bool resolve = true)
                {
                        GraphicObject result;
-                       GOMLResolutionStack.Push(new List<DynAttribute>());
+
 
                        XmlSerializerNamespaces xn = new XmlSerializerNamespaces();
                        xn.Add("", "");
-                       XmlSerializer xs = new XmlSerializer(type);            
+                       //prevent unused ref in References created by xmlSerializer
+                       Interface.DontResoveGOML = true;
+                       XmlSerializer xs = new XmlSerializer(type);
+                       Interface.DontResoveGOML = false;
+                       GOMLResolutionStack.Push(new List<DynAttribute>());
 
                        result = (GraphicObject)xs.Deserialize(stream);
                        result.DataSource = hostClass;