]> O.S.I.I.S - jp/crow.git/commitdiff
debug bindings when new value is null
authorjpbruyere <jp.bruyere@hotmail.com>
Wed, 25 May 2016 13:46:58 +0000 (15:46 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Wed, 25 May 2016 13:46:58 +0000 (15:46 +0200)
Templates/ComboBox.goml
Tests/GLCrow.cs
Tests/Interfaces/Divers/testBind0.crow [new file with mode: 0755]
Tests/Interfaces/Divers/testCombobox.crow
Tests/Tests.csproj
src/CompilerServices/CompilerServices.cs
src/GraphicObjects/ListBox.cs

index aeedd97f66a8c2b3d1587843ab2a73ae8769be50..9a5addaf430dccfd8651687453be8a55bab27ed9 100755 (executable)
@@ -21,7 +21,7 @@
                        Height="{../HeightPolicy}" Width="{../WidthPolicy}"
                        HorizontalAlignment="Left"
                        ValueChanged="../../../_scroller_ValueChanged">
-                       <VerticalStack LayoutChanged="../../../../_list_LayoutChanged" Background="Mantis"
+                       <VerticalStack LayoutChanged="../../../../_list_LayoutChanged"
                                Height="Fit" Width="{../../WidthPolicy}" Name="List" Margin="0"
                                HorizontalAlignment="Left"
                                VerticalAlignment="Top"/>
index 3064ad37310acc7b0d245be05167011799013f94..1ede02684ea5c2d644007eadb81b4172fcebac32 100644 (file)
@@ -94,9 +94,17 @@ namespace Tests
                                w.Run (30);
                        }
                }
-
+               public object data = "datas";
+               public object Datas {
+                       get { return data; }
+               }
+               void onSetDataToNull (object sender, MouseButtonEventArgs e) {
+                       data = null;
+                       NotifyValueChanged ("Datas", null);
+               }
                public override void OnLoad ()
                {
+                       //testFiles = new string [] { @"Interfaces/Divers/testBind0.crow" };
                        testFiles = new string [] { @"Interfaces/Divers/testCombobox.crow" };
                        testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/GraphicObject", "*.crow")).ToArray ();
                        //testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/basicTests", "*.crow")).ToArray ();
diff --git a/Tests/Interfaces/Divers/testBind0.crow b/Tests/Interfaces/Divers/testBind0.crow
new file mode 100755 (executable)
index 0000000..d8991c7
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0"?>
+<VerticalStack Fit="true">
+       <TextBox Text="{Datas}" Width="100" />
+       <Button Text="Set Text to Null" MouseClick="onSetDataToNull"/>
+</VerticalStack>
\ No newline at end of file
index b52e9d8200225223231a5d92747fe701eada0d9c..2ef6d3912269aea26783bd681b1af0a3a9ece8ae 100755 (executable)
@@ -1,5 +1,4 @@
 <?xml version="1.0"?>
 <Container Background="Onyx" Width="300">
-       <ComboBox  Data="{TestList}" SelectedIndex="0"
-               ItemTemplate="#Tests.Interfaces.colorItem.crow"/>
+       <ComboBox  Data="{TestList}" ItemTemplate="#Tests.Interfaces.colorItem.crow"/>
 </Container>
\ No newline at end of file
index 0a839765b9bd12db5ae53faa115fc58301d2b3af..444c63c86bfd0eef6f4b104129ea94ff0dfcaccc 100644 (file)
     <None Include="GOLIBTestsOTK.cs">
       <LogicalName></LogicalName>
     </None>
+    <None Include="Interfaces\Divers\2 %28copier%29.crow">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+      <LogicalName></LogicalName>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Interfaces\" />
index af72a9e0ea7404dbf6a2bc1eedcbb26f4d8ea5cf..0f8c5d474fef5452f4186407802b4a78fa9bd871 100644 (file)
@@ -226,9 +226,9 @@ namespace Crow
                                return;
                        if (Bindings.Count == 0)
                                return;
-#if DEBUG_BINDING
-                       Debug.WriteLine ("Resolve Bindings => " + this.ToString ());
-#endif
+//#if DEBUG_BINDING
+//                     Debug.WriteLine ("Resolve Bindings => " + this.ToString ());
+//#endif
                        //grouped bindings by Instance of Source
                        Dictionary<object,List<Binding>> resolved = new Dictionary<object, List<Binding>>();
 
@@ -361,12 +361,16 @@ namespace Crow
                                                }else
                                                        targetValue = targetValue.ToString ();
                                        }
-                                       if (targetValue != null)
-                                               b.Target.Property.GetSetMethod ().Invoke
-                                               (b.Target.Instance, new object[] { b.Target.Property.PropertyType.Cast(targetValue)});
-                                       else
-                                               b.Target.Property.GetSetMethod ().Invoke
-                                               (b.Target.Instance, new object[] { targetValue });
+                                       try {
+                                               if (targetValue != null)
+                                                       b.Target.Property.GetSetMethod ().Invoke
+                                                       (b.Target.Instance, new object [] { b.Target.Property.PropertyType.Cast (targetValue) });
+                                               else
+                                                       b.Target.Property.GetSetMethod ().Invoke
+                                                       (b.Target.Instance, new object [] { targetValue });
+                                       } catch (Exception ex) {
+                                               Debug.WriteLine (ex.ToString ());
+                                       }
 #endregion
 
                                        //if no dyn update, skip jump table
@@ -390,10 +394,24 @@ namespace Crow
                                il.Emit (OpCodes.Br, endMethod);
 
                                i = 0;
-                               foreach (Binding b in grouped) {
-
+                               foreach (Binding b in grouped) {                                        
+                                       
                                        il.MarkLabel (jumpTable [i]);
-                                       il.Emit(OpCodes.Ldloc_1);
+
+
+                                       //load 2 times to check first for null
+                                       il.Emit (OpCodes.Ldloc_1);
+                                       il.Emit (OpCodes.Ldloc_1);
+
+                                       System.Reflection.Emit.Label labSetValue = il.DefineLabel ();
+                                       il.Emit (OpCodes.Brtrue, labSetValue);
+                                       //if null
+                                       il.Emit (OpCodes.Unbox_Any, b.Target.Property.PropertyType);
+                                       il.Emit (OpCodes.Callvirt, b.Target.Property.GetSetMethod ());
+                                       il.Emit (OpCodes.Br, endMethod);
+
+                                       il.MarkLabel (labSetValue);
+                                       //new value not null
 
                                        //by default, source value type is deducted from target member type to allow
                                        //memberless binding, if targetMember exists, it will be used to determine target
@@ -408,6 +426,8 @@ namespace Crow
                                                        throw new Exception ("unhandle target member type in binding");
                                        }
 
+
+
                                        if (b.Target.Property.PropertyType == typeof(string)) {
                                                MemberReference tostring = new MemberReference (b.Target.Instance);
                                                if (!tostring.FindMember ("ToString"))
@@ -421,6 +441,11 @@ namespace Crow
                                                il.Emit(OpCodes.Unbox_Any, b.Target.Property.PropertyType);
 
                                        il.Emit(OpCodes.Callvirt, b.Target.Property.GetSetMethod());
+
+                                       //il.BeginCatchBlock (typeof (Exception));
+                                       //il.Emit (OpCodes.Pop);
+                                       //il.EndExceptionBlock ();
+
                                        il.Emit (OpCodes.Br, endMethod);
                                        i++;
 
index 8daf95504f0b0da5ceb54864f9fa1a86c6d3a2b9..34834b8d432040aea6582396bd3d4dbc15ffa85f 100644 (file)
@@ -93,7 +93,7 @@ namespace Crow
                        }
                }
                public object SelectedItem{
-                       get { return data == null ? "" : _selectedIndex < 0 ? "" : data[_selectedIndex]; }
+                       get { return data == null ? null : _selectedIndex < 0 ? null : data[_selectedIndex]; }
                }
                [XmlAttributeAttribute]//[DefaultValue(null)]
                public IList Data {