From 225d8384090e77e6099010fdb0dfb474ab5c9a8f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Mon, 26 Feb 2018 12:47:39 +0100 Subject: [PATCH] in design saving of GraphicObject --- src/GraphicObjects/Container.cs | 12 ++++++ src/GraphicObjects/GraphicObject.cs | 42 +++++++++++++++++++++ src/GraphicObjects/Group.cs | 12 ++++++ src/GraphicObjects/TemplatedContainer.cs | 12 ++++++ src/GraphicObjects/TemplatedControl.cs | 14 +++++++ src/GraphicObjects/TemplatedGroup.cs | 21 +++++++++++ src/Instantiator.cs | 7 +++- src/ItemTemplate.cs | 47 +++++++++++++++++++++++- 8 files changed, 165 insertions(+), 2 deletions(-) diff --git a/src/GraphicObjects/Container.cs b/src/GraphicObjects/Container.cs index fedee0af..364bad83 100644 --- a/src/GraphicObjects/Container.cs +++ b/src/GraphicObjects/Container.cs @@ -38,6 +38,18 @@ namespace Crow /// public class Container : PrivateContainer { + #if DESIGN_MODE + public override void getIML (System.Xml.XmlDocument doc, System.Xml.XmlNode parentElem) + { + if (this.design_isTGItem) + return; + base.getIML (doc, parentElem); + if (child == null) + return; + child.getIML (doc, parentElem.LastChild); + } + #endif + #region CTOR protected Container() : base(){} public Container (Interface iface) : base(iface){} diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 768b5c07..fadbe124 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -36,6 +36,12 @@ using System.Diagnostics; using Crow.IML; using System.Threading; + +#if DESIGN_MODE +using System.Xml; +using System.IO; +#endif + namespace Crow { /// @@ -50,6 +56,42 @@ namespace Crow public int design_column; public string design_imlPath; public Dictionary design_members = new Dictionary(); + public bool design_isTGItem = false; + + public string GetIML(){ + XmlDocument doc = new XmlDocument( ); + + using (StringWriter sw = new StringWriter ()) { + XmlWriterSettings settings = new XmlWriterSettings { + Indent = true, + IndentChars = "\t", + }; + using (XmlWriter xtw = XmlWriter.Create (sw, settings)) { + //(1) the xml declaration is recommended, but not mandatory + XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration ("1.0", "UTF-8", null); + doc.InsertBefore (xmlDeclaration, null); + getIML (doc, (XmlNode)doc); + doc.WriteTo (xtw); + } + return sw.ToString (); + } + } + + public virtual void getIML(XmlDocument doc, XmlNode parentElem) { + if (this.design_isTGItem) + return; + + XmlElement xe = doc.CreateElement(this.GetType().Name); + + foreach (KeyValuePair kv in design_members) { + XmlAttribute xa = doc.CreateAttribute (kv.Key); + xa.Value = kv.Value; + xe.Attributes.Append (xa); + } + + parentElem.AppendChild (xe); + } + #endif #region IDisposable implementation diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index cfec7774..2875b4de 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -38,6 +38,18 @@ namespace Crow { public class Group : GraphicObject { + #if DESIGN_MODE + public override void getIML (System.Xml.XmlDocument doc, System.Xml.XmlNode parentElem) + { + if (this.design_isTGItem) + return; + base.getIML (doc, parentElem); + foreach (GraphicObject g in Children) { + g.getIML (doc, parentElem.LastChild); + } + } + #endif + protected ReaderWriterLockSlim childrenRWLock = new ReaderWriterLockSlim(); #region CTOR diff --git a/src/GraphicObjects/TemplatedContainer.cs b/src/GraphicObjects/TemplatedContainer.cs index 3e0dd801..a779595d 100644 --- a/src/GraphicObjects/TemplatedContainer.cs +++ b/src/GraphicObjects/TemplatedContainer.cs @@ -38,6 +38,18 @@ namespace Crow /// public class TemplatedContainer : TemplatedControl { + #if DESIGN_MODE + public override void getIML (System.Xml.XmlDocument doc, System.Xml.XmlNode parentElem) + { + if (this.design_isTGItem) + return; + base.getIML (doc, parentElem); + if (!HasContent) + return; + Content.getIML (doc, parentElem.LastChild); + } + #endif + #region CTOR protected TemplatedContainer() : base(){} public TemplatedContainer (Interface iface) : base(iface){} diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs index c231fd0f..54991a41 100644 --- a/src/GraphicObjects/TemplatedControl.cs +++ b/src/GraphicObjects/TemplatedControl.cs @@ -43,6 +43,20 @@ namespace Crow /// public abstract class TemplatedControl : PrivateContainer { + #if DESIGN_MODE + public bool design_inlineTemplate = false; + public override void getIML (System.Xml.XmlDocument doc, System.Xml.XmlNode parentElem) + { + if (this.design_isTGItem) + return; + base.getIML (doc, parentElem); + if (child == null || !design_inlineTemplate) + return; + XmlElement xe = doc.CreateElement("Template"); + child.getIML (doc, xe); + parentElem.LastChild.AppendChild (xe); + } + #endif #region CTOR protected TemplatedControl() : base(){} public TemplatedControl (Interface iface) : base(iface){} diff --git a/src/GraphicObjects/TemplatedGroup.cs b/src/GraphicObjects/TemplatedGroup.cs index 8e0ffb44..a5cd2dd6 100644 --- a/src/GraphicObjects/TemplatedGroup.cs +++ b/src/GraphicObjects/TemplatedGroup.cs @@ -40,6 +40,24 @@ namespace Crow { public abstract class TemplatedGroup : TemplatedControl { + #if DESIGN_MODE + public override void getIML (System.Xml.XmlDocument doc, System.Xml.XmlNode parentElem) + { + if (this.design_isTGItem) + return; + base.getIML (doc, parentElem); + + if (string.IsNullOrEmpty(_itemTemplate)) { + foreach (ItemTemplate it in ItemTemplates.Values) + it.getIML (doc, parentElem.LastChild); + } + + foreach (GraphicObject g in Items) { + g.getIML (doc, parentElem.LastChild); + } + } + #endif + #region CTOR protected TemplatedGroup() : base(){} public TemplatedGroup (Interface iface) : base(iface){} @@ -429,6 +447,9 @@ namespace Crow lock (IFace.LayoutMutex) { g = iTemp.CreateInstance(); + #if DESIGN_MODE + g.design_isTGItem = true; + #endif page.AddChild (g); // if (isPaged) g.LogicalParent = this; diff --git a/src/Instantiator.cs b/src/Instantiator.cs index 5c4b82f3..c0b886ad 100644 --- a/src/Instantiator.cs +++ b/src/Instantiator.cs @@ -263,7 +263,7 @@ namespace Crow.IML itemTmpID += path+dataType+datas; if (!iface.Instantiators.ContainsKey (itemTmpID)) iface.Instantiators [itemTmpID] = - new ItemTemplate (iface, Interface.GetStreamFromPath (path), dataTest, dataType, datas); + new ItemTemplate (iface, path, dataTest, dataType, datas); } return new string [] { dataType, itemTmpID, datas, dataTest }; } @@ -289,6 +289,11 @@ namespace Crow.IML continue; if (reader.Name == "Template") { inlineTemplate = true; + #if DESIGN_MODE + ctx.il.Emit (OpCodes.Ldloc_0); + ctx.il.Emit (OpCodes.Ldc_I4_1); + ctx.il.Emit (OpCodes.Stfld, typeof(TemplatedControl).GetField("design_inlineTemplate")); + #endif reader.Read (); readChildren (reader, ctx, -1); } else if (reader.Name == "ItemTemplate") diff --git a/src/ItemTemplate.cs b/src/ItemTemplate.cs index 7eb9d752..dda9d152 100644 --- a/src/ItemTemplate.cs +++ b/src/ItemTemplate.cs @@ -48,6 +48,48 @@ namespace Crow /// /// public class ItemTemplate : Instantiator { + #if DESIGN_MODE + public void getIML (System.Xml.XmlDocument doc, System.Xml.XmlNode parentElem){ + if (sourcePath == "#Crow.DefaultItem.template") + return; + + XmlElement xe = doc.CreateElement("ItemTemplate"); + XmlAttribute xa = null; + + if (string.IsNullOrEmpty (sourcePath)) { + //inline item template + using (GraphicObject go = this.CreateInstance()) + go.getIML (doc, xe); + } else { + xa = doc.CreateAttribute ("Path"); + xa.Value = sourcePath; + xe.Attributes.Append (xa); + } + + if (strDataType != "default") { + xa = doc.CreateAttribute ("DataType"); + xa.Value = strDataType; + xe.Attributes.Append (xa); + + if (dataTest != "TypeOf"){ + xa = doc.CreateAttribute ("DataTest"); + xa.Value = dataTest; + xe.Attributes.Append (xa); + } + } + + if (!string.IsNullOrEmpty(fetchMethodName)){ + xa = doc.CreateAttribute ("Data"); + xa.Value = fetchMethodName; + xe.Attributes.Append (xa); + } + + parentElem.AppendChild (xe); + + + } + #endif + public EventHandler Expand; public BooleanTestOnInstance HasSubItems; string strDataType; @@ -61,7 +103,7 @@ namespace Crow /// IML file to parse /// type this item will be choosen for, or member of the data item /// for hierarchical data, method to call for children fetching - public ItemTemplate(Interface _iface, string path, string _dataTest = "TypeOf", string _dataType = null, string _fetchDataMethod = null) + public ItemTemplate(Interface _iface, string path, string _dataTest = "TypeOf", string _dataType = "default", string _fetchDataMethod = null) : base(_iface, path) { strDataType = _dataType; fetchMethodName = _fetchDataMethod; @@ -251,6 +293,9 @@ namespace Crow il.Emit (OpCodes.Callvirt, miGetDatas); } + + + } } -- 2.47.3