]> O.S.I.I.S - jp/crow.git/commitdiff
replace styling constant in iml files while generating instantiator
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 1 Jun 2020 23:56:18 +0000 (01:56 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 1 Jun 2020 23:56:18 +0000 (01:56 +0200)
Crow/src/IML/Instantiator.cs
Crow/src/styling/StyleReader.cs

index 0aa49eb42c9028c237725f08bea3e83270914975..4254933b553b8e58a998916bf87b969626ff01a6 100644 (file)
@@ -31,7 +31,7 @@ namespace Crow.IML {
        ///     - Default values (appearing as attribute in C#)  loading
        ///     - Styling
        /// 
-       /// Instantiators are shared amongs interfaces. Their are stored with their path as key, and inlined template
+       /// Their are stored in the Interface with their path as key, and inlined template
        /// and itemtemplate are stored with a generated uuid
        /// </summary>
        public class Instantiator
@@ -470,17 +470,44 @@ namespace Crow.IML {
                                                if (reader.Name == "Style" || reader.Name == "DataSourceType" || reader.Name == "Template")
                                                        continue;
 
-                                               #if DESIGN_MODE
+#if DESIGN_MODE
                                                emitSetDesignAttribute (ctx, reader.Name, reader.Value);
-                                               #endif
+#endif
+
+                                               string imlValue = reader.Value;
+                                               StringBuilder styledValue = new StringBuilder();
+
+                                               int vPtr = 0;
+                                               while (vPtr < imlValue.Length) {
+                                                       if (imlValue [vPtr] == '$') {
+                                                               if (imlValue [vPtr+1] == '{') {
+                                                                       vPtr+=2;
+                                                                       string cstId = "";
+                                                                       while (vPtr < imlValue.Length) {
+                                                                               if (imlValue [vPtr] == '}') {
+                                                                                       vPtr++;
+                                                                                       break;
+                                                                               }
+                                                                               cstId += imlValue [vPtr++];
+                                                                       }
+                                                                       if (string.IsNullOrEmpty (cstId) || !iface.StylingConstants.ContainsKey (cstId))
+                                                                               throw new Exception ("undefined constant id: " + cstId);
+                                                                       styledValue.Append (iface.StylingConstants [cstId]);
+                                                                       continue; 
+                                                               }
+                                                       }
+                                                       styledValue.Append (imlValue [vPtr++]);
+                                               }
+                                               imlValue = styledValue.ToString ();
 
                                                MemberInfo mi = ctx.CurrentNodeType.GetMember (reader.Name).FirstOrDefault ();
                                                if (mi == null)
                                                        throw new Exception ("Member '" + reader.Name + "' not found in " + ctx.CurrentNodeType.Name);
 
                                                if (mi.MemberType == MemberTypes.Event) {
-                                                       foreach (string exp in reader.Value.Split (';')) {
+                                                       foreach (string exp in imlValue.ToString().Split (';')) {
                                                                string trimed = exp.Trim();
+
                                                                if (trimed.StartsWith ("{", StringComparison.Ordinal))
                                                                        compileAndStoreDynHandler (ctx, mi as EventInfo, trimed.Substring (1, trimed.Length - 2));
                                                                else
@@ -496,10 +523,10 @@ namespace Crow.IML {
                                                if (pi.Name == "Name")
                                                        ctx.StoreCurrentName (reader.Value);
 
-                                               if (reader.Value.StartsWith ("{", StringComparison.Ordinal))
-                                                       readPropertyBinding (ctx, reader.Name, reader.Value.Substring (1, reader.Value.Length - 2));
+                                               if (imlValue.StartsWith ("{", StringComparison.Ordinal))
+                                                       readPropertyBinding (ctx, reader.Name, imlValue.Substring (1, reader.Value.Length - 2));
                                                else
-                                                       CompilerServices.EmitSetValue (ctx.il, pi, reader.Value);
+                                                       CompilerServices.EmitSetValue (ctx.il, pi, styledValue);
 
                                        }
                                        reader.MoveToElement ();
index cace196a81c26e28190eb93bf907e5bb5a596ab0..218032e7602c5f40ecf3ab848a5111cccbd3831d 100644 (file)
@@ -20,7 +20,8 @@ namespace Crow
                enum States { classNames, members, value, endOfStatement }
 
                States curState = States.classNames;
-
+               int column = 1;
+               int line = 1;
 
                #region Character ValidityCheck
                static Regex rxValidChar = new Regex(@"\p{Lu}|\p{Ll}|\p{Lt}|\p{Lm}|\p{Lo}|\p{Nl}|\p{Mn}|\p{Mc}|\p{Nd}|\p{Pc}|\p{Cf}");
@@ -62,8 +63,8 @@ namespace Crow
                /// <param name="iFace">the Interface to load the style for</param>
                public void Parse (Interface iFace, string resId)
                {
-                       int column = 1;
-                       int line = 1;
+                       column = 1;
+                       line = 1;
                        curState = States.classNames;
 
                        string styleKey = resId.Substring (0, resId.Length - 6);