diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2016-08-06 17:48:03 +0200 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2016-08-06 17:48:03 +0200 |
| commit | c45ce80e0e4298afcbeee9215ee2d1d30c4c3be8 (patch) | |
| tree | ec659a28153b9df8406736d9f8df6ee255b8cb7e /src/CompilerServices | |
| parent | f42cabddc008529eddc0a43cad3be2b39b6790ee (diff) | |
* Crow.csproj:
* Label.cs: update
* GraphicObject.cs: key up
* ListBox.cs: IMLStream instanciing
* PrivateContainer.cs: Clear child Changes
* Scroller.cs: scroller have VerticalSrcrolling by default
* TemplatedControl.cs: remove unused hostClass attribute
* IMLStream.cs: IMLStream instance and source properties
* Interface.cs: removed unused hostClass
Only putOnTop Window widget when focused
KeyboardState key up and down
* TreeView.crow: no border in default template
* BasicTests.cs: IMLEditor
PropLessBinding test
* Tests.csproj:
* 2.crow:
* 0.crow:
* test5.crow:
* 2.crow:
* testTreeView.crow: update tests
* Bindings.cs:
* MemberReference.cs:
* CompilerServices.cs: property less bindings debug
Diffstat (limited to 'src/CompilerServices')
| -rw-r--r-- | src/CompilerServices/Bindings.cs | 63 | ||||
| -rw-r--r-- | src/CompilerServices/CompilerServices.cs | 4 | ||||
| -rw-r--r-- | src/CompilerServices/MemberReference.cs | 4 |
3 files changed, 38 insertions, 33 deletions
diff --git a/src/CompilerServices/Bindings.cs b/src/CompilerServices/Bindings.cs index 40ade60d..8ece856c 100644 --- a/src/CompilerServices/Bindings.cs +++ b/src/CompilerServices/Bindings.cs @@ -93,12 +93,12 @@ namespace Crow /// resolve target expression /// </summary> /// <returns><c>true</c>, if target was found, <c>false</c> otherwise.</returns> - public bool FindTarget () + public bool TryFindTarget () { if (Target != null) return true; - string member = null; + string memberName = null; //if binding exp = '{}' => binding is done on datasource if (string.IsNullOrEmpty (Expression)) { @@ -118,85 +118,86 @@ namespace Crow string [] bindingExp = expression.Split ('/'); + if (bindingExp.Length == 1) { //datasource binding - Target = new MemberReference ((Source.Instance as GraphicObject).DataSource); - member = bindingExp [0]; + object dataSource = (Source.Instance as GraphicObject).DataSource; + if (dataSource == null) { + Debug.WriteLine ("\tDataSource is null => " + this.ToString()); + return false; + } + + Target = new MemberReference (dataSource); + memberName = bindingExp [0]; } else { int ptr = 0; - ILayoutable tmp = Source.Instance as ILayoutable; + ILayoutable tmpTarget = Source.Instance as ILayoutable; //if exp start with '/' => Graphic tree parsing start at source if (string.IsNullOrEmpty (bindingExp [0])) ptr++; else if (bindingExp[0] == "."){ //search template root do { - tmp = tmp.Parent; - if (tmp == null) + tmpTarget = tmpTarget.Parent; + if (tmpTarget == null) return false; - if (tmp is Interface) + if (tmpTarget is Interface) throw new Exception ("Not in Templated Control"); - } while (!(tmp is TemplatedControl)); + } while (!(tmpTarget is TemplatedControl)); ptr++; } while (ptr < bindingExp.Length - 1) { - if (tmp == null) { + if (tmpTarget == null) { #if DEBUG_BINDING Debug.WriteLine ("\tERROR: target not found => " + this.ToString()); #endif return false; } if (bindingExp [ptr] == "..") - tmp = tmp.LogicalParent; + tmpTarget = tmpTarget.LogicalParent; else if (bindingExp [ptr] == ".") { if (ptr > 0) throw new Exception ("Syntax error in binding, './' may only appear in first position"); - tmp = Source.Instance as ILayoutable; + tmpTarget = Source.Instance as ILayoutable; } else - tmp = (tmp as GraphicObject).FindByName (bindingExp [ptr]); + tmpTarget = (tmpTarget as GraphicObject).FindByName (bindingExp [ptr]); ptr++; } - if (tmp == null) { + if (tmpTarget == null) { #if DEBUG_BINDING - Debug.WriteLine ("\tERROR: target not found => " + this.ToString()); + Debug.WriteLine ("\tERROR: Binding Target not found => " + this.ToString()); #endif return false; } + Target = new MemberReference (tmpTarget); + string [] bindTrg = bindingExp [ptr].Split ('.'); if (bindTrg.Length == 1) - member = bindTrg [0]; + memberName = bindTrg [0]; else if (bindTrg.Length == 2) { - tmp = (tmp as GraphicObject).FindByName (bindTrg [0]); - member = bindTrg [1]; + tmpTarget = (tmpTarget as GraphicObject).FindByName (bindTrg [0]); + memberName = bindTrg [1]; } else throw new Exception ("Syntax error in binding, expected 'go dot member'"); - Target = new MemberReference (tmp); - } - if (Target == null) { - #if DEBUG_BINDING - Debug.WriteLine ("Binding Source is null: " + Expression); - #endif - return false; } - if (Target.TryFindMember (member)) { + if (Target.TryFindMember (memberName)) { if (TwoWayBinding) { IBindable source = Target.Instance as IBindable; if (source == null) throw new Exception (Source.Instance + " does not implement IBindable for 2 way bindings"); source.Bindings.Add (new Binding (Target, Source)); } - return true; } - #if DEBUG_BINDING - Debug.WriteLine ("Binding member not found: " + member); + else + Debug.WriteLine ("Property less binding: " + Target + expression); #endif - Target = null; - return false; + + return true; } public void Reset () { diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs index 4a85c442..0b69f970 100644 --- a/src/CompilerServices/CompilerServices.cs +++ b/src/CompilerServices/CompilerServices.cs @@ -31,7 +31,7 @@ namespace Crow CompilerServices.CompileEventSource (b); continue; } - if (!b.FindTarget ()) + if (!b.TryFindTarget ()) continue; //register handler for event if (b.Target.Method == null) { @@ -53,7 +53,7 @@ namespace Crow continue; } - if (!b.FindTarget ()) + if (!b.TryFindTarget ()) continue; //group Bindings by target instanceq diff --git a/src/CompilerServices/MemberReference.cs b/src/CompilerServices/MemberReference.cs index 1dc3a3e4..97f470fc 100644 --- a/src/CompilerServices/MemberReference.cs +++ b/src/CompilerServices/MemberReference.cs @@ -68,6 +68,10 @@ namespace Crow return Member != null; } + public override string ToString () + { + return string.Format ("{0}.{1}", Instance, Member); + } } } |