]> O.S.I.I.S - jp/crow.git/commitdiff
crowide wip, DesignIDS
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 27 Feb 2018 17:18:42 +0000 (18:18 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 27 Feb 2018 17:18:42 +0000 (18:18 +0100)
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/Group.cs
src/GraphicObjects/PrivateContainer.cs
src/Instantiator.cs

index fadbe124f3a0846a39878f1c2a24b08020c07c21..f5a1a224efe78fe022742c328f68d6cc7ffc201d 100644 (file)
@@ -52,12 +52,23 @@ namespace Crow
                internal ReaderWriterLockSlim parentRWLock = new ReaderWriterLockSlim();
 
                #if DESIGN_MODE
+               public volatile bool HasChanged = false;
+               public string design_id;
                public int design_line;
                public int design_column;
                public string design_imlPath;
                public Dictionary<string,string> design_members = new Dictionary<string, string>();
                public bool design_isTGItem = false;
 
+               public virtual bool FindByDesignID(string designID, out GraphicObject go){
+                       go = null;
+                       if (this.design_id == designID){
+                               go = this;
+                               return true;
+                       }
+                       return false;
+               }
+
                public string GetIML(){
                        XmlDocument doc = new XmlDocument( );
 
@@ -73,6 +84,7 @@ namespace Crow
                                        getIML (doc, (XmlNode)doc);
                                        doc.WriteTo (xtw);
                                }
+                               this.HasChanged = false;
                                return sw.ToString ();
                        }
                }
index 2875b4de191c3f1d09911e8c807c0dc119bb733f..0eb1ece239d6215158b38cc6ef9ea5979b7ae7e1 100644 (file)
@@ -39,6 +39,20 @@ namespace Crow
        public class Group : GraphicObject
     {
                #if DESIGN_MODE
+               public override bool FindByDesignID(string designID, out GraphicObject go){
+                       go = null;
+                       if (base.FindByDesignID (designID, out go))
+                               return true;
+                       childrenRWLock.EnterReadLock ();
+                       foreach (GraphicObject w in Children) {
+                               if (!w.FindByDesignID (designID, out go))
+                                       continue;
+                               childrenRWLock.ExitReadLock ();
+                               return true;
+                       }
+                       childrenRWLock.ExitReadLock ();
+                       return false;
+               }
                public override void getIML (System.Xml.XmlDocument doc, System.Xml.XmlNode parentElem)
                {
                        if (this.design_isTGItem)
index f2626e255a17fd6dd26b02d9c534fd6d34fd1e3c..81017a7e6bb440558af61a5610e75f3711daa40f 100644 (file)
@@ -45,6 +45,14 @@ namespace Crow
                public PrivateContainer (Interface iface) : base(iface){}
                #endregion
 
+               #if DESIGN_MODE
+               public override bool FindByDesignID(string designID, out GraphicObject go){
+                       go = null;
+                       if (base.FindByDesignID (designID, out go))
+                               return true;
+                       return (bool)child?.FindByDesignID (designID, out go);                          
+               }
+               #endif
                protected GraphicObject child;
 
                protected virtual void SetChild(GraphicObject _child)
index c0b886ada2684694d959d2938f7409827a1b512e..5c6711f5f0e1bff56958f772701ebe88e3d3b8ce 100644 (file)
@@ -74,6 +74,13 @@ namespace Crow.IML
 
                internal string sourcePath;
 
+               #if DESIGN_MODE
+               public static int NextInstantiatorID = 0;
+               public int currentInstantiatorID = 0;
+               int currentDesignID = 0;
+               internal string NextDesignID { get { return string.Format ("{0}_{1}",currentInstantiatorID, currentDesignID++); }}
+               #endif
+
                #region CTOR
                /// <summary>
                /// Initializes a new instance of the Instantiator class.
@@ -86,6 +93,9 @@ namespace Crow.IML
                /// </summary>
                public Instantiator (Interface _iface, Stream stream, string srcPath = null)
                {
+                       #if DESIGN_MODE
+                       currentInstantiatorID = NextInstantiatorID++;
+                       #endif
                        iface = _iface;
                        sourcePath = srcPath;
                        #if DEBUG_LOAD
@@ -112,12 +122,18 @@ namespace Crow.IML
                /// positionned on the start tag inside the itemTemplate
                /// </summary>
                public Instantiator (Interface _iface, XmlReader itr){
+                       #if DESIGN_MODE
+                       currentInstantiatorID = NextInstantiatorID++;
+                       #endif
                        iface = _iface;
                        parseIML (itr);
                }
                //TODO:check if still used
                public Instantiator (Interface _iface, Type _root, InstanciatorInvoker _loader)
                {
+                       #if DESIGN_MODE
+                       currentInstantiatorID = NextInstantiatorID++;
+                       #endif
                        iface = _iface;
                        RootType = _root;
                        loader = _loader;
@@ -384,6 +400,9 @@ namespace Crow.IML
                                #if DESIGN_MODE
                                IXmlLineInfo li = (IXmlLineInfo)reader;
                                ctx.il.Emit (OpCodes.Ldloc_0);
+                               ctx.il.Emit (OpCodes.Ldstr, this.NextDesignID);
+                               ctx.il.Emit (OpCodes.Stfld, typeof(GraphicObject).GetField("design_id"));
+                               ctx.il.Emit (OpCodes.Ldloc_0);
                                ctx.il.Emit (OpCodes.Ldc_I4, ctx.curLine + li.LineNumber);
                                ctx.il.Emit (OpCodes.Stfld, typeof(GraphicObject).GetField("design_line"));
                                ctx.il.Emit (OpCodes.Ldloc_0);