From 6bedf8d5d0b78ba0705e37375d8dee016e87ebbb Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Tue, 13 Oct 2015 16:57:26 +0200 Subject: - GraphicTree parsing bindings in templates instead of using datasource which could be kept for other uses - ListBox bindings debug - LogicalParent for Popper to get correct DataSource for content --- src/CompilerServices/CompilerServices.cs | 9 +++++++-- src/GraphicObjects/Combobox.cs | 28 +++++++++++++++----------- src/GraphicObjects/Expandable.cs | 7 ++++++- src/GraphicObjects/GraphicObject.cs | 34 +++++++++++++++++++++++++------- src/GraphicObjects/ListBox.cs | 10 ++++++++-- src/GraphicObjects/Popper.cs | 9 ++++++++- src/GraphicObjects/TemplatedContainer.cs | 11 +++++++---- src/GraphicObjects/TemplatedControl.cs | 3 ++- src/Interface.cs | 2 +- 9 files changed, 82 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs index c72137df..e7395383 100644 --- a/src/CompilerServices/CompilerServices.cs +++ b/src/CompilerServices/CompilerServices.cs @@ -29,6 +29,8 @@ namespace go } public bool FindMember(string _memberName) { + if (Instance == null) + return false; Type t = Instance.GetType (); Member = t.GetMember (_memberName,BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).FirstOrDefault (); @@ -79,7 +81,7 @@ namespace go //if binding exp = '{}' => binding is done on datasource if (string.IsNullOrEmpty (Expression)) { - Target = new MemberReference (Source.Instance); + Target = new MemberReference ((Source.Instance as GraphicObject).DataSource); return true; } @@ -101,7 +103,7 @@ namespace go if (tmp == null) return false; if (bindingExp [ptr] == "..") - tmp = tmp.Parent as GraphicObject; + tmp = tmp.Parent as ILayoutable; else if (bindingExp [ptr] == ".") { if (ptr > 0) throw new Exception ("Syntax error in binding, './' may only appear in first position"); @@ -111,6 +113,9 @@ namespace go ptr++; } + if (tmp == null) + return false; + string[] bindTrg = bindingExp [ptr].Split ('.'); if (bindTrg.Length == 1) diff --git a/src/GraphicObjects/Combobox.cs b/src/GraphicObjects/Combobox.cs index 02040570..3e841793 100644 --- a/src/GraphicObjects/Combobox.cs +++ b/src/GraphicObjects/Combobox.cs @@ -22,7 +22,7 @@ namespace go { [DefaultTemplate("#go.Templates.Combobox.goml")] [DefaultOverlayTemplate("#go.Templates.ComboboxOverlay.goml")] - public class Combobox : TemplatedContainer + public class Combobox : TemplatedControl { #region CTOR public Combobox() : base(){ } @@ -48,21 +48,22 @@ namespace go base.loadTemplate (template); loadOverlayTemplate (null); } - public override GraphicObject Content { - get { - throw new NotImplementedException (); - } - set { - throw new NotImplementedException (); - } - } +// public override GraphicObject Content { +// get { +// throw new NotImplementedException (); +// } +// set { +// throw new NotImplementedException (); +// } +// } #endregion protected virtual void loadOverlayTemplate(GraphicObject overlayTemplate) { if (overlayTemplate == null) { DefaultOverlayTemplate dt = (DefaultOverlayTemplate)this.GetType ().GetCustomAttributes (typeof(DefaultOverlayTemplate), true).FirstOrDefault (); - Overlay = Interface.Load (dt.Path, this, !Interface.DontResoveGOML); + Overlay = Interface.Load (dt.Path); + Overlay.ResolveBindings (); } else Overlay = overlayTemplate; _list = Overlay.FindByName ("List") as Group; @@ -173,8 +174,9 @@ namespace go lock (pendingChildrenAddition) { if (!threadedLoadingFinished && pendingChildrenAddition.Count < 50) return; - while (pendingChildrenAddition.Count > 0) + while (pendingChildrenAddition.Count > 0) { _list.addChild (pendingChildrenAddition.Dequeue ()); + } } } @@ -198,7 +200,8 @@ namespace go foreach (var item in data) { ms.Seek(0,SeekOrigin.Begin); - GraphicObject g = Interface.Load (ms, t, item); + GraphicObject g = Interface.Load (ms, t); + g.DataSource = item; g.MouseClick += itemClick; lock (pendingChildrenAddition) { @@ -348,5 +351,6 @@ namespace go base.ClearBinding (); } + } } diff --git a/src/GraphicObjects/Expandable.cs b/src/GraphicObjects/Expandable.cs index 0bc5d067..3d4ef229 100644 --- a/src/GraphicObjects/Expandable.cs +++ b/src/GraphicObjects/Expandable.cs @@ -116,6 +116,11 @@ namespace go IsExpanded = !IsExpanded; base.onMouseClick (sender, e); } - + public override void ResolveBindings () + { + base.ResolveBindings (); + if (Content != null) + Content.ResolveBindings (); + } } } diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 5d7e0dae..1496e0e5 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -76,6 +76,7 @@ namespace go #endregion #region public fields + public GraphicObject LogicalParent; public Rectangle Bounds; public Rectangle Slot = new Rectangle (); public object Tag; @@ -85,8 +86,20 @@ namespace go #region ILayoutable [XmlIgnore]public ILayoutable Parent { get { return _parent; } - set { _parent = value; } + set { +// if (_parent == value) +// return; +// if (_parent != null) +// ClearBinding (); +// + _parent = value; +// +// if (DataSource != null) +// ResolveBindings (); + } } + + [XmlIgnore]public virtual Rectangle ClientRectangle { get { Rectangle cb = Slot.Size; @@ -336,7 +349,7 @@ namespace go } object dataSource; - [XmlIgnore]public object DataSource { + [XmlIgnore]public virtual object DataSource { set { if (dataSource == value) return; @@ -351,7 +364,8 @@ namespace go } get { return dataSource == null ? - Parent is GraphicObject ? (Parent as GraphicObject).DataSource : null : dataSource; + LogicalParent == null ? + Parent is GraphicObject ? (Parent as GraphicObject).DataSource : null : LogicalParent.DataSource : dataSource; } } #endregion @@ -799,6 +813,8 @@ namespace go { List resolved = new List (); foreach (Binding b in Bindings) { + if (!string.IsNullOrEmpty (b.DynMethodId)) + continue; if (b.Source.Member.MemberType == MemberTypes.Event) { if (b.Expression.StartsWith("{")){ CompileEventSource(b); @@ -854,9 +870,13 @@ namespace go Type[] args = {typeof(object), typeof(object),handlerArgsType}; dm = new DynamicMethod(grouped[0].NewDynMethodId, - typeof(void), + MethodAttributes.Family | MethodAttributes.FamANDAssem | MethodAttributes.NewSlot, + CallingConventions.Standard, + typeof(void), args, - sourceType); + sourceType,true); + + il = dm.GetILGenerator(256); @@ -905,7 +925,7 @@ namespace go }else throw new Exception ("unandled source member type for binding"); }else if (string.IsNullOrEmpty(b.Expression)) - targetValue= grouped [0].Target;//empty binding exp=> bound to target object by default + targetValue= grouped [0].Target.Instance;//empty binding exp=> bound to target object by default //TODO: handle other dest type conversions if (b.Source.Property.PropertyType == typeof(string)){ if (targetValue == null){ @@ -925,7 +945,7 @@ namespace go if (b.Target.Member != null) il.Emit (OpCodes.Ldstr, b.Target.Member.Name); else - il.Emit (OpCodes.Ldstr, b.Expression); + il.Emit (OpCodes.Ldstr, b.Expression.Split('/').LastOrDefault()); il.Emit (OpCodes.Callvirt, stringEquals); il.Emit (OpCodes.Brtrue, jumpTable[i]); i++; diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs index 9f408b5a..15752f80 100644 --- a/src/GraphicObjects/ListBox.cs +++ b/src/GraphicObjects/ListBox.cs @@ -91,10 +91,15 @@ namespace go Thread t = new Thread (loadingThread); t.Start (); + t.Join (); } } - + public override void UpdateLayout (LayoutingType layoutType) + { + CheckPendingChildrenAddition (); + base.UpdateLayout (layoutType); + } internal void CheckPendingChildrenAddition() { if (pendingChildrenAddition == null) @@ -127,7 +132,8 @@ namespace go foreach (var item in data) { ms.Seek(0,SeekOrigin.Begin); - GraphicObject g = Interface.Load (ms, t, item); + GraphicObject g = Interface.Load (ms, t); + g.DataSource = item; g.MouseClick += itemClick; lock (pendingChildrenAddition) { diff --git a/src/GraphicObjects/Popper.cs b/src/GraphicObjects/Popper.cs index e1a02fc6..2ec4396f 100644 --- a/src/GraphicObjects/Popper.cs +++ b/src/GraphicObjects/Popper.cs @@ -38,6 +38,7 @@ namespace go get { return _content; } set { if (_content != null) { + _content.LogicalParent = null; _content.LayoutChanged -= _content_LayoutChanged; _content.MouseLeave -= _content_MouseLeave; } @@ -47,6 +48,7 @@ namespace go if (_content == null) return; + _content.LogicalParent = this; _content.Focusable = true; _content.LayoutChanged += _content_LayoutChanged; _content.MouseLeave += _content_MouseLeave; @@ -93,7 +95,12 @@ namespace go } } base.ClearBinding (); - + } + public override void ResolveBindings () + { + base.ResolveBindings (); + if (Content != null) + Content.ResolveBindings (); } [XmlAttributeAttribute()][DefaultValue(true)]//overiden to get default to true diff --git a/src/GraphicObjects/TemplatedContainer.cs b/src/GraphicObjects/TemplatedContainer.cs index dcea97d7..cef8266b 100644 --- a/src/GraphicObjects/TemplatedContainer.cs +++ b/src/GraphicObjects/TemplatedContainer.cs @@ -35,14 +35,17 @@ namespace go #region GraphicObject overrides public override void ClearBinding () { - if (Content != null) { - //fix datasource = null to clear bindings, but it's illogic - Content.DataSource = this.DataSource; + if (Content != null) Content.ClearBinding (); - } base.ClearBinding (); } +// public override void ResolveBindings () +// { +// base.ResolveBindings (); +// if (Content != null) +// Content.ResolveBindings (); +// } public override GraphicObject FindByName (string nameToFind) { if (Name == nameToFind) diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs index e203c0cf..d6c7243d 100644 --- a/src/GraphicObjects/TemplatedControl.cs +++ b/src/GraphicObjects/TemplatedControl.cs @@ -115,7 +115,8 @@ namespace go { if (template == null) { DefaultTemplate dt = (DefaultTemplate)this.GetType ().GetCustomAttributes (typeof(DefaultTemplate), true).FirstOrDefault(); - this.SetChild (Interface.Load (dt.Path, this,!Interface.DontResoveGOML)); + this.SetChild (Interface.Load (dt.Path, this)); + this.child.ResolveBindings (); }else this.SetChild (template); } diff --git a/src/Interface.cs b/src/Interface.cs index 2ce0266b..ddd2a008 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -441,7 +441,7 @@ namespace go XmlSerializer xs = new XmlSerializer (type); result = (GraphicObject)xs.Deserialize (stream); - result.DataSource = hostClass; + //result.DataSource = hostClass; #if DEBUG_LOAD_TIME loadingTime.Stop (); -- cgit v1.3.1-4-g156e