aboutsummaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2016-05-25 15:46:58 +0200
committerjpbruyere <jp.bruyere@hotmail.com>2016-05-25 15:46:58 +0200
commitc02ea44eb9010aee1f03fba4342730f338598356 (patch)
tree30b9c7c4653dad5818bf65a1774183c326313481
parent63cb46716cd042c2884687be2d47f7a5ce35e9c6 (diff)
debug bindings when new value is null
-rwxr-xr-xTemplates/ComboBox.goml2
-rw-r--r--Tests/GLCrow.cs10
-rwxr-xr-xTests/Interfaces/Divers/testBind0.crow5
-rwxr-xr-xTests/Interfaces/Divers/testCombobox.crow3
-rw-r--r--Tests/Tests.csproj4
-rw-r--r--src/CompilerServices/CompilerServices.cs49
-rw-r--r--src/GraphicObjects/ListBox.cs2
7 files changed, 58 insertions, 17 deletions
diff --git a/Templates/ComboBox.goml b/Templates/ComboBox.goml
index aeedd97f..9a5addaf 100755
--- a/Templates/ComboBox.goml
+++ b/Templates/ComboBox.goml
@@ -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"/>
diff --git a/Tests/GLCrow.cs b/Tests/GLCrow.cs
index 3064ad37..1ede0268 100644
--- a/Tests/GLCrow.cs
+++ b/Tests/GLCrow.cs
@@ -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
index 00000000..d8991c71
--- /dev/null
+++ b/Tests/Interfaces/Divers/testBind0.crow
@@ -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
diff --git a/Tests/Interfaces/Divers/testCombobox.crow b/Tests/Interfaces/Divers/testCombobox.crow
index b52e9d82..2ef6d391 100755
--- a/Tests/Interfaces/Divers/testCombobox.crow
+++ b/Tests/Interfaces/Divers/testCombobox.crow
@@ -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
diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj
index 0a839765..444c63c8 100644
--- a/Tests/Tests.csproj
+++ b/Tests/Tests.csproj
@@ -447,6 +447,10 @@
<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\" />
diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs
index af72a9e0..0f8c5d47 100644
--- a/src/CompilerServices/CompilerServices.cs
+++ b/src/CompilerServices/CompilerServices.cs
@@ -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++;
diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs
index 8daf9550..34834b8d 100644
--- a/src/GraphicObjects/ListBox.cs
+++ b/src/GraphicObjects/ListBox.cs
@@ -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 {