]> O.S.I.I.S - jp/crow.git/commitdiff
:bulb: :lipstick: :bug: template attribute fetch when no default template exist.
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 29 Jan 2018 03:24:36 +0000 (04:24 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 29 Jan 2018 03:24:36 +0000 (04:24 +0100)
Crow.csproj
Tests/Tests.csproj
Tests/ui/showcase.crow
src/CompilerServices/CompilerServices.cs
src/GraphicObjects/TemplatedGroup.cs
src/IML/Node.cs
src/Instantiator.cs
src/ItemTemplate.cs

index a78add0b3eed8eba0f8bdf596bb46a9e6b9e55c8..c556bc7998d1dbaaed77ae7cd00580e2a7728d58 100644 (file)
@@ -31,7 +31,7 @@
     <DebugSymbols>true</DebugSymbols>
     <DebugType>full</DebugType>
     <CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
-    <DefineConstants>DEBUG_UPDATE0;DEBUG_FOCUS0;DEBUG_LAYOUTING0;TRACE0;DEBUG;__linux__;MEASURE_TIME0;DEBUG_LOAD0;DEBUG_BINDING0;DEBUG_CLIP_RECTANGLE0</DefineConstants>
+    <DefineConstants>DEBUG_UPDATE0;DEBUG_FOCUS0;DEBUG_LAYOUTING0;TRACE0;DEBUG;MEASURE_TIME;DEBUG_LOAD0;DEBUG_BINDING0;DEBUG_CLIP_RECTANGLE0</DefineConstants>
     <Optimize>false</Optimize>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
index 21cb740d0eb55b1b966ec5d24dc7386f03ce2311..2adcdb16b88ff81baa386c3c2c99f0d7894d731f 100644 (file)
@@ -8,7 +8,7 @@
     <OutputType>Exe</OutputType>
     <RootNamespace>Tests</RootNamespace>
     <AssemblyName>Tests</AssemblyName>
-    <StartupObject>Tests.BasicTests</StartupObject>
+    <StartupObject>Tests.Showcase</StartupObject>
     <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
     <ReleaseVersion>0.5</ReleaseVersion>
index a511a100ca8f4b03f9d2b9f905a17283dbb47029..24b038d658b38819d95f4009babf14cc6c2c51ea 100755 (executable)
@@ -1,7 +1,6 @@
 <?xml version="1.0"?>
 <HorizontalStack Background="Onyx" Margin="5">
-       <DirectoryView Name="dv" CurrentDirectory="Interfaces" Width="25%" SelectedItemChanged="Dv_SelectedItemChanged"
-               />
+       <DirectoryView Name="dv" CurrentDirectory="Interfaces" Width="25%" SelectedItemChanged="Dv_SelectedItemChanged"/>
        <Splitter Width="6"/>
        <VerticalStack>
                <Container Name="CrowContainer" Height="60%" Background="SmokyBlack"/>
index 827ee6178b4667fdef2fb28ccb8154f26b8ab45f..b119b3e7d811b4b382fee07507f2a4678e18f16b 100644 (file)
@@ -846,6 +846,23 @@ namespace Crow
                                exps.Add(expression);
                        return exps.ToArray ();
                }
+               /// <summary>
+               /// Try to get the type named strDataType, search first in crow assembly then in
+               /// entry assembly.
+               /// </summary>
+               /// <returns>the corresponding type object if found</returns>
+               /// <param name="strDataType">type name</param>
+               internal static Type tryGetType (string strDataType){
+                       Type dataType = Type.GetType(strDataType);
+                       if (dataType != null)
+                               return dataType;
+                       Assembly a = Assembly.GetEntryAssembly ();
+                       foreach (Type expT in a.GetExportedTypes ()) {
+                               if (expT.Name == strDataType)
+                                       return dataType;
+                       }
+                       return null;
+               }
        }
 }
 
index 60f18994707f7198c646a43742f681228bfc20f4..3d5b7e83ae1b6ecd439b10e5f75588ff24133ac3 100644 (file)
@@ -266,6 +266,9 @@ namespace Crow
 //             }
                #endregion
 
+               /// <summary>
+               /// Items loading thread
+               /// </summary>
                void loading(){
                        if (ItemTemplates == null)
                                ItemTemplates = new Dictionary<string, ItemTemplate> ();
@@ -359,16 +362,7 @@ namespace Crow
                                iTemp = ItemTemplates [itempKey];
                        else {
                                foreach (string it in ItemTemplates.Keys) {
-                                       Type t = Type.GetType (it);
-                                       if (t == null) {
-                                               Assembly a = Assembly.GetEntryAssembly ();
-                                               foreach (Type expT in a.GetExportedTypes ()) {
-                                                       if (expT.Name == it) {
-                                                               t = expT;
-                                                               break;
-                                                       }
-                                               }
-                                       }
+                                       Type t = CompilerServices.tryGetType (it);
                                        if (t == null)
                                                continue;
                                        if (t.IsAssignableFrom (dataType)) {//TODO:types could be cached
index 2b63cf4b9cade78d3105366ee76120c0ed9b4aa5..8b85388bdf1c46c7e89b2c006d58e6d969c3058c 100644 (file)
@@ -49,6 +49,11 @@ namespace Crow.IML
                /// <summary> Index in parent, -1 for template</summary>
                public int Index;
 
+               /// <summary>
+               /// retrieve the child addition method depending on the type of this node
+               /// </summary>
+               /// <returns>The child addition method</returns>
+               /// <param name="childIdx">child index or, template root node has index == -1</param>
                public MethodInfo GetAddMethod(int childIdx){
                        if (typeof (Group).IsAssignableFrom (CrowType))
                                return CompilerServices.miAddChild;
index 4c236cd47e0afd06c8308c56a84a480ac916330f..3520ce8363177380c60f1a9fd548086b4c3a61f7 100644 (file)
@@ -93,7 +93,7 @@ namespace Crow
                                        return new Instantiator (s);
                                }
                        } catch (Exception ex) {
-                               throw new Exception ("Error loading fragment:\n" + fragment + "\n", ex);
+                               throw new Exception ("Error loading IML fragment:\n" + fragment + "\n", ex);
                        }
                }
                #endregion
@@ -145,17 +145,7 @@ namespace Crow
                                        break;
                                }
                        }
-
-                       Type t = Type.GetType ("Crow." + root);
-                       if (t == null) {
-                               Assembly a = Assembly.GetEntryAssembly ();
-                               foreach (Type expT in a.GetExportedTypes ()) {
-                                       if (expT.Name == root) {
-                                               t = expT;
-                                               break;
-                                       }
-                               }
-                       }
+                       Type t = tryGetGOType (root);
                        if (t == null)
                                throw new Exception ("IML parsing error: undefined root type (" + root + ")");
                        return t;
@@ -177,9 +167,9 @@ namespace Crow
                                List<string[]> itemTemplateIds = new List<string[]> ();
                                bool inlineTemplate = false;
 
+                               reader.Read ();
                                string templatePath = reader.GetAttribute ("Template");
 
-                               reader.Read ();
                                int depth = reader.Depth + 1;
                                while (reader.Read ()) {
                                        if (!reader.IsStartElement () || reader.Depth > depth)
@@ -310,7 +300,6 @@ namespace Crow
                                ctx.nodesStack.ResetCurrentNodeIndex ();
                        }
                }
-
                /// <summary>
                /// Parse child node an generate corresponding msil
                /// </summary>
@@ -336,16 +325,7 @@ namespace Crow
                                        ctx.il.Emit (OpCodes.Ldloc_0);
                                        ctx.il.Emit (OpCodes.Ldloc_0);
 
-                                       Type t = Type.GetType ("Crow." + reader.Name);
-                                       if (t == null) {
-                                               Assembly a = Assembly.GetEntryAssembly ();
-                                               foreach (Type expT in a.GetExportedTypes ()) {
-                                                       if (expT.Name == reader.Name) {
-                                                               t = expT;
-                                                               break;
-                                                       }
-                                               }
-                                       }
+                                       Type t = tryGetGOType (reader.Name);
                                        if (t == null)
                                                throw new Exception (reader.Name + " type not found");
 
@@ -392,6 +372,25 @@ namespace Crow
                                (dataSource as IValueChange).ValueChanged +=
                                        (EventHandler<ValueChangeEventArgs>)dsValueChangedDynMeths [dynMethIdx].CreateDelegate (typeof(EventHandler<ValueChangeEventArgs>), dscSource);
                }
+               /// <summary> Emits remove old data source event handler./summary>
+               void emitRemoveOldDataSourceHandler(ILGenerator il, string eventName, string delegateName, bool DSSide = true){
+                       System.Reflection.Emit.Label cancel = il.DefineLabel ();
+
+                       il.Emit (OpCodes.Ldarg_2);//load old parent
+                       il.Emit (OpCodes.Ldfld, CompilerServices.fiDSCOldDS);
+                       il.Emit (OpCodes.Brfalse, cancel);//old parent is null
+
+                       //remove handler
+                       if (DSSide){//event is defined in the dataSource instance
+                               il.Emit (OpCodes.Ldarg_2);//1st arg load old datasource
+                               il.Emit (OpCodes.Ldfld, CompilerServices.fiDSCOldDS);
+                       }else//the event is in the source
+                               il.Emit (OpCodes.Ldarg_1);//1st arg load old datasource
+                       il.Emit (OpCodes.Ldstr, eventName);//2nd arg event name
+                       il.Emit (OpCodes.Ldstr, delegateName);//3d arg: delegate name
+                       il.Emit (OpCodes.Call, CompilerServices.miRemEvtHdlByName);
+                       il.MarkLabel(cancel);
+               }
                #endregion
 
                #region Event Bindings
@@ -970,26 +969,23 @@ namespace Crow
                }
                #endregion
 
-               /// <summary> Emits remove old data source event handler./summary>
-               void emitRemoveOldDataSourceHandler(ILGenerator il, string eventName, string delegateName, bool DSSide = true){
-                       System.Reflection.Emit.Label cancel = il.DefineLabel ();
-
-                       il.Emit (OpCodes.Ldarg_2);//load old parent
-                       il.Emit (OpCodes.Ldfld, CompilerServices.fiDSCOldDS);
-                       il.Emit (OpCodes.Brfalse, cancel);//old parent is null
-
-                       //remove handler
-                       if (DSSide){//event is defined in the dataSource instance
-                               il.Emit (OpCodes.Ldarg_2);//1st arg load old datasource
-                               il.Emit (OpCodes.Ldfld, CompilerServices.fiDSCOldDS);
-                       }else//the event is in the source
-                               il.Emit (OpCodes.Ldarg_1);//1st arg load old datasource
-                       il.Emit (OpCodes.Ldstr, eventName);//2nd arg event name
-                       il.Emit (OpCodes.Ldstr, delegateName);//3d arg: delegate name
-                       il.Emit (OpCodes.Call, CompilerServices.miRemEvtHdlByName);
-                       il.MarkLabel(cancel);
+               /// <summary>
+               /// search for graphic object type in crow assembly, if not found,
+               /// search for type independently of namespace in entry assembly
+               /// </summary>
+               /// <returns>the corresponding type object</returns>
+               /// <param name="typeName">graphic object type name without its namespace</param>
+               Type tryGetGOType (string typeName){
+                       Type t = Type.GetType ("Crow." + typeName);
+                       if (t != null)
+                               return t;
+                       Assembly a = Assembly.GetEntryAssembly ();
+                       foreach (Type expT in a.GetExportedTypes ()) {
+                               if (expT.Name == typeName)
+                                       return expT;
+                       }
+                       return null;
                }
-
        }
 }
 
index 5361904292531a2f09258302fe824057d607c31d..fc7d90638ddce89aeba66058eb9cdc12f1b9b403 100644 (file)
@@ -65,16 +65,7 @@ namespace Crow
                #endregion
 
                public void CreateExpandDelegate (TemplatedGroup host){
-                       Type dataType = Type.GetType(strDataType);
-                       if (dataType == null) {
-                               Assembly a = Assembly.GetEntryAssembly ();
-                               foreach (Type expT in a.GetExportedTypes ()) {
-                                       if (expT.Name == strDataType) {
-                                               dataType = expT;
-                                               break;
-                                       }
-                               }
-                       }
+                       Type dataType = CompilerServices.tryGetType(strDataType);
                        if (dataType == null) {
                                Debug.WriteLine ("ItemTemplate error: DataType not found: {0}.", strDataType);
                                return;