diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2016-07-31 12:02:14 +0200 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2016-07-31 12:02:14 +0200 |
| commit | a508dabb5edb41304143bc135ad769d63164d026 (patch) | |
| tree | 20bdd7d24dc57a4efdf530d7200d78e9cb6d4199 /src/GraphicObjects/GraphicObject.cs | |
| parent | 9804d49ef322db2623b3390311dd00e2afe649a1 (diff) | |
Style attribute in xml, add default value loader style key.
modifié : src/GraphicObjects/GraphicObject.cs
modifié : src/Interface.cs
Diffstat (limited to 'src/GraphicObjects/GraphicObject.cs')
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 80 |
1 files changed, 48 insertions, 32 deletions
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index a24b5763..a053e700 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -45,17 +45,14 @@ namespace Crow uid = currentUid; currentUid++; - if (Interface.XmlSerializerInit) + if (Interface.CurrentInterface.XmlLoading) return; - - loadDefaultValues (); } public GraphicObject (Rectangle _bounds) { - if (Interface.XmlSerializerInit) - return; - - loadDefaultValues (); + if (!Interface.CurrentInterface.XmlLoading) + loadDefaultValues (); + Left = _bounds.Left; Top = _bounds.Top; Width = _bounds.Width; @@ -485,17 +482,6 @@ namespace Crow } #endregion - - /// <summary> - /// Add 'Styles' to full class name between assembly name and the rest of the full name space - /// </summary> - string getDefaultStyleResId (Type t) { - string [] tmp = t.FullName.Split ('.'); - string res = tmp [0] + ".Styles"; - for (int i = 1; i < tmp.Length; i++) - res += "." + tmp [i]; - return res; - } /// <summary> Loads the default values from XML attributes default </summary> protected virtual void loadDefaultValues() { @@ -504,10 +490,21 @@ namespace Crow #endif Type thisType = this.GetType (); + + if (!string.IsNullOrEmpty (Style)) { + if (Interface.DefaultValuesLoader.ContainsKey (Style)) { + Interface.DefaultValuesLoader [Style] (this); + return; + } + } if (Interface.DefaultValuesLoader.ContainsKey (thisType.FullName)) { Interface.DefaultValuesLoader [thisType.FullName] (this); return; } + if (Interface.DefaultValuesLoader.ContainsKey (thisType.Name)) { + Interface.DefaultValuesLoader [thisType.Name] (this); + return; + } List<Dictionary<string, object>> styling = new List<Dictionary<string, object>>(); @@ -516,15 +513,26 @@ namespace Crow //2: class name //3: style may have been registered with their ressource ID minus .style extention // those files being placed in a Styles folder - - if (Interface.CurrentInterface.Styling.ContainsKey (thisType.FullName)) + string styleKey = Style; + if (!string.IsNullOrEmpty (Style)) { + if (Interface.CurrentInterface.Styling.ContainsKey (Style)) { + styling.Add (Interface.CurrentInterface.Styling [Style]); + } + } + if (Interface.CurrentInterface.Styling.ContainsKey (thisType.FullName)) { styling.Add (Interface.CurrentInterface.Styling [thisType.FullName]); - if (Interface.CurrentInterface.Styling.ContainsKey (thisType.Name)) + if (string.IsNullOrEmpty (styleKey)) + styleKey = thisType.FullName; + } + if (Interface.CurrentInterface.Styling.ContainsKey (thisType.Name)) { styling.Add (Interface.CurrentInterface.Styling [thisType.Name]); - - string styleFullName = getDefaultStyleResId (thisType); - if (Interface.CurrentInterface.Styling.ContainsKey (styleFullName)) - styling.Add (Interface.CurrentInterface.Styling [styleFullName]); + if (string.IsNullOrEmpty (styleKey)) + styleKey = thisType.Name; + } + + if (string.IsNullOrEmpty (styleKey)) + styleKey = thisType.FullName; + //Reflexion being very slow compared to dyn method or delegates, //I compile the initial values coded in the CustomAttribs of the class, @@ -676,8 +684,8 @@ namespace Crow il.Emit(OpCodes.Ret); #endregion - Interface.DefaultValuesLoader[thisType.FullName] = (Interface.loadDefaultInvoker)dm.CreateDelegate(typeof(Interface.loadDefaultInvoker)); - Interface.DefaultValuesLoader[thisType.FullName] (this); + Interface.DefaultValuesLoader[styleKey] = (Interface.loadDefaultInvoker)dm.CreateDelegate(typeof(Interface.loadDefaultInvoker)); + Interface.DefaultValuesLoader[styleKey] (this); } public virtual GraphicObject FindByName(string nameToFind){ @@ -1283,13 +1291,21 @@ namespace Crow } public virtual void ReadXml (System.Xml.XmlReader reader) { - if (!reader.HasAttributes) - return; + if (reader.HasAttributes) { + + style = reader.GetAttribute ("Style"); - while (reader.MoveToNextAttribute ()) - affectMember (reader.Name, reader.Value); + loadDefaultValues (); - reader.MoveToElement(); + while (reader.MoveToNextAttribute ()) { + if (reader.Name == "Style") + continue; + + affectMember (reader.Name, reader.Value); + } + reader.MoveToElement (); + }else + loadDefaultValues (); } public virtual void WriteXml (System.Xml.XmlWriter writer) { |