diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2015-06-10 10:30:48 +0200 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2015-06-10 10:30:49 +0200 |
| commit | 73c7ac95b12d72bcb3f5d549c76bdf0b5a093847 (patch) | |
| tree | d595f3e95d71c92e4d52a33f6a6411e5f7afbee3 /src | |
| parent | 578341c3e4410b803b65a739f950b103f3f0a95c (diff) | |
- fuse binding and event resolution contexts in GOMLResolver
Diffstat (limited to 'src')
| -rw-r--r-- | src/GraphicObjects/Expandable.cs | 9 | ||||
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 4 | ||||
| -rw-r--r-- | src/Interface.cs | 83 |
3 files changed, 59 insertions, 37 deletions
diff --git a/src/GraphicObjects/Expandable.cs b/src/GraphicObjects/Expandable.cs index e3274ca0..6f215b2f 100644 --- a/src/GraphicObjects/Expandable.cs +++ b/src/GraphicObjects/Expandable.cs @@ -22,6 +22,7 @@ namespace go {
bool _isExpanded;
Label _caption;
+ Image _image;
public Container Content;
@@ -41,6 +42,14 @@ namespace go _caption = this.child.FindByName ("Caption") as Label;
Content = this.child.FindByName ("Content") as Container;
+ _image = this.child.FindByName ("Image") as Image;
+
+ if (_image == null)
+ return;
+ _image.SvgSub = "collapsed";
+ this.Expand += (object sender, EventArgs e) => {_image.SvgSub = "expanded";};
+ this.Collapse += (object sender, EventArgs e) => {_image.SvgSub = "collapsed";};
+
}
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 8098f863..9cafe13b 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -685,7 +685,7 @@ namespace go if (string.IsNullOrEmpty (handler))
continue;
- Interface.EventsToResolve.Add(new DynAttribute
+ Interface.GOMLResolver.Add(new DynAttribute
{
Source = this,
Value = handler,
@@ -770,7 +770,7 @@ namespace go throw new Exception (string.Format("GOML:Malformed binding: {0}", v));
string strBinding = v.Substring (1, v.Length - 2);
- Interface.Bindings.Add (new DynAttribute () {
+ Interface.GOMLResolver.Add (new DynAttribute () {
Source = this,
MemberName = name,
Value = strBinding
diff --git a/src/Interface.cs b/src/Interface.cs index 29e276c0..0c3098fc 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -45,12 +45,12 @@ namespace go #region Load/Save - internal static Stack<List<DynAttribute>> EventsResolutionStack = new Stack<List<DynAttribute>>(); - internal static List<DynAttribute> EventsToResolve + internal static Stack<List<DynAttribute>> GOMLResolutionStack = new Stack<List<DynAttribute>>(); + internal static List<DynAttribute> GOMLResolver { - get { return EventsResolutionStack.Peek ();} + get { return GOMLResolutionStack.Peek ();} } - internal static List<DynAttribute> Bindings; + //internal static List<DynAttribute> Bindings; public static void Save<T>(string file, T graphicObject) @@ -110,8 +110,7 @@ namespace go { //result = (T)(Load (file, hostClass) as object); - EventsResolutionStack.Push(new List<DynAttribute>()); - Bindings = new List<DynAttribute> (); + GOMLResolutionStack.Push(new List<DynAttribute>()); XmlSerializerNamespaces xn = new XmlSerializerNamespaces(); xn.Add("", ""); @@ -125,13 +124,13 @@ namespace go if (hostClass == null) return; - resolveEvents (hostClass); + resolveGOML (hostClass); - while (Bindings.Count > 0) { - DynAttribute binding = Bindings [0]; - Bindings.RemoveAt (0); - CompilerServices.ResolveBinding (binding, hostClass); - } +// while (Bindings.Count > 0) { +// DynAttribute binding = Bindings [0]; +// Bindings.RemoveAt (0); +// CompilerServices.ResolveBinding (binding, hostClass); +// } // foreach (DynAttribute binding in Bindings) { //// Type tSource = binding.Source.GetType (); //// if (!tSource.GetInterfaces ().Any (i => i.Name == "IValueChange")){ @@ -147,7 +146,7 @@ namespace go public static GraphicObject Load(Stream stream, Type type, object hostClass = null) { GraphicObject result; - EventsResolutionStack.Push(new List<DynAttribute>()); + GOMLResolutionStack.Push(new List<DynAttribute>()); XmlSerializerNamespaces xn = new XmlSerializerNamespaces(); xn.Add("", ""); @@ -155,16 +154,18 @@ namespace go result = (GraphicObject)xs.Deserialize(stream); - if (hostClass == null) + if (hostClass == null) { + GOMLResolutionStack.Pop (); return result; + } - resolveEvents (hostClass); + resolveGOML (hostClass); - while (Bindings.Count > 0) { - DynAttribute binding = Bindings [0]; - Bindings.RemoveAt (0); - CompilerServices.ResolveBinding (binding, hostClass); - } +// while (Bindings.Count > 0) { +// DynAttribute binding = Bindings [0]; +// Bindings.RemoveAt (0); +// CompilerServices.ResolveBinding (binding, hostClass); +// } // foreach (DynAttribute binding in Bindings) { // // Type tSource = binding.Source.GetType (); @@ -181,30 +182,42 @@ namespace go return result; } - static void resolveEvents(object hostClass) + static void resolveGOML(object hostClass) { - foreach (DynAttribute es in EventsToResolve) + foreach (DynAttribute es in GOMLResolver) { if (string.IsNullOrEmpty(es.Value)) continue; - if (es.Value.StartsWith ("{")) { - CompilerServices.CompileEventSource (es); - } else { - MethodInfo mi = hostClass.GetType ().GetMethod (es.Value, BindingFlags.NonPublic | BindingFlags.Public - | BindingFlags.Instance); + Type dstType = es.Source.GetType (); + MemberInfo miTarget = dstType.GetMember (es.MemberName).FirstOrDefault(); - if (mi == null) { - Debug.WriteLine ("Handler Method not found: " + es.Value); - continue; - } + if (miTarget == null) { + Debug.WriteLine ("'{0}' Member not found in '{1}' type.", es.MemberName, dstType.ToString ()); + continue; + } + + if (miTarget.MemberType == MemberTypes.Event) { + if (es.Value.StartsWith ("{")) { + CompilerServices.CompileEventSource (es); + } else { + MethodInfo mi = hostClass.GetType ().GetMethod (es.Value, BindingFlags.NonPublic | BindingFlags.Public + | BindingFlags.Instance); - FieldInfo fi = CompilerServices.getEventHandlerField (es.Source.GetType (), es.MemberName); - Delegate del = Delegate.CreateDelegate(fi.FieldType, hostClass, mi); - fi.SetValue(es.Source, del); + if (mi == null) { + Debug.WriteLine ("Handler Method not found: " + es.Value); + continue; + } + + FieldInfo fi = CompilerServices.getEventHandlerField (es.Source.GetType (), es.MemberName); + Delegate del = Delegate.CreateDelegate (fi.FieldType, hostClass, mi); + fi.SetValue (es.Source, del); + } + } else { + CompilerServices.ResolveBinding (es, hostClass); } } - EventsResolutionStack.Pop(); + GOMLResolutionStack.Pop(); } #endregion } |