]> O.S.I.I.S - jp/crow.git/commitdiff
in design saving of GraphicObject
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 26 Feb 2018 11:47:39 +0000 (12:47 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 26 Feb 2018 11:47:39 +0000 (12:47 +0100)
src/GraphicObjects/Container.cs
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/Group.cs
src/GraphicObjects/TemplatedContainer.cs
src/GraphicObjects/TemplatedControl.cs
src/GraphicObjects/TemplatedGroup.cs
src/Instantiator.cs
src/ItemTemplate.cs

index fedee0af8d232dd475e90a8dfe2d7f8bfb3f50a7..364bad833285491ddf819753efffecd48875d2df 100644 (file)
@@ -38,6 +38,18 @@ namespace Crow
        /// </summary>
     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){}
index 768b5c0759fe0654fedc0d12840e40b742b7b611..fadbe124f3a0846a39878f1c2a24b08020c07c21 100644 (file)
@@ -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
 {
        /// <summary>
@@ -50,6 +56,42 @@ namespace Crow
                public int design_column;
                public string design_imlPath;
                public Dictionary<string,string> design_members = new Dictionary<string, string>();
+               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<string,string> 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
index cfec77742605add4f7bd072376d0effdfd3c6d66..2875b4de191c3f1d09911e8c807c0dc119bb733f 100644 (file)
@@ -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
index 3e0dd801fcbea1d0e9713f61ad2296aa2a9f21cb..a779595d9b30d002a28c005940ad68c7aa79f52c 100644 (file)
@@ -38,6 +38,18 @@ namespace Crow
        /// </summary>
        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){}
index c231fd0f8a0938b59d0b8cb6228876a22a094e55..54991a415960e24b1e85080c36cfdb12302f49f4 100644 (file)
@@ -43,6 +43,20 @@ namespace Crow
        /// </summary>
        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){}
index 8e0ffb448d9cc7f716fbcf93a1df6f676d8cdbc4..a5cd2dd6b5d70a4239ab9156c553b16138f6e0a1 100644 (file)
@@ -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;
index 5c4b82f3f59d3ce84ee6f98f95597455e9c620ca..c0b886ada2684694d959d2938f7409827a1b512e 100644 (file)
@@ -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")
index 7eb9d752b2a9e6798cd2481910922baa3d95a698..dda9d15279b40c27d7fe823d9ee193f2e14dcc62 100644 (file)
@@ -48,6 +48,48 @@ namespace Crow
        /// 
        /// </summary>
        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
                /// <param name="path">IML file to parse</param>
                /// <param name="_dataType">type this item will be choosen for, or member of the data item</param>
                /// <param name="_fetchDataMethod">for hierarchical data, method to call for children fetching</param>
-               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);
                }
+
+       
+       
        }
 }