]> O.S.I.I.S - jp/crow.git/commitdiff
:book:, default item template loading if none defined for TemplatedGroup
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 6 Feb 2018 06:07:57 +0000 (07:07 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 6 Feb 2018 06:07:57 +0000 (07:07 +0100)
Crow.csproj
Templates/DefaultItem.template [new file with mode: 0755]
Templates/ItemTemplate.goml [deleted file]
src/GraphicObjects/TemplatedGroup.cs
src/IML/Node.cs
src/Instantiator.cs
src/Interface.cs
src/ItemTemplate.cs

index e6cf6864ce152779ed7ddbe9b856bf352bb3f463..38f19b9e6a1cfa86a2c45fe7e6292e1bc312b835 100644 (file)
     <EmbeddedResource Include="Images\Icons\checkbox.svg" />
     <EmbeddedResource Include="Images\Icons\radiobutton.svg" />
     <EmbeddedResource Include="Templates\Spinner %28copier%29.goml" />
-    <EmbeddedResource Include="Templates\ItemTemplate.goml" />
     <EmbeddedResource Include="Images\Icons\expandable.svg" />
     <EmbeddedResource Include="Templates\Checkbox2.goml" />
     <EmbeddedResource Include="Images\Icons\tetra.png" />
       <LogicalName>Crow.DockingView.template</LogicalName>
     </EmbeddedResource>
     <EmbeddedResource Include="Templates\FileItems.template" />
+    <EmbeddedResource Include="Templates\DefaultItem.template">
+      <LogicalName>Crow.DefaultItem.template</LogicalName>
+    </EmbeddedResource>
   </ItemGroup>
   <ItemGroup>
     <None Include="Crow.dll.config">
diff --git a/Templates/DefaultItem.template b/Templates/DefaultItem.template
new file mode 100755 (executable)
index 0000000..fc13ab4
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<Container Fit="true" Margin="0" Focusable="true"
+               HorizontalAlignment="Left"
+               MouseEnter="{Background=SteelBlue}"
+               MouseLeave="{Background=Transparent}">
+       <Label Text="{}"/>
+</Container>
+
diff --git a/Templates/ItemTemplate.goml b/Templates/ItemTemplate.goml
deleted file mode 100755 (executable)
index fc13ab4..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<?xml version="1.0"?>
-<Container Fit="true" Margin="0" Focusable="true"
-               HorizontalAlignment="Left"
-               MouseEnter="{Background=SteelBlue}"
-               MouseLeave="{Background=Transparent}">
-       <Label Text="{}"/>
-</Container>
-
index 81ea25fbcfebf2eb6929a4d51d09ba1d8567d6d9..55726b509fb705f8c99e90ee34ec6403a108780b 100644 (file)
@@ -71,9 +71,9 @@ namespace Crow
                /// 
                /// ItemTemplate file may contains either a single template without the
                /// ItemTemplate enclosing tag, or several item templates each enclosed
-               /// in a separate tag
+               /// in a separate tag.
                /// </summary>
-               [XmlAttributeAttribute][DefaultValue("#Crow.Templates.ItemTemplate.goml")]
+               [XmlAttributeAttribute]
                public string ItemTemplate {
                        get { return _itemTemplate; }
                        set {
@@ -344,7 +344,7 @@ namespace Crow
                }
                string getItempKey(Type dataType, object o){
                        try {
-                               return dataType.GetProperty (_dataTest).GetGetMethod ().Invoke (o, null).ToString();
+                               return dataType.GetProperty (_dataTest).GetGetMethod ().Invoke (o, null)?.ToString();
                        } catch  {
                                return dataType.FullName;
                        }
index 8b85388bdf1c46c7e89b2c006d58e6d969c3058c..2ca90e8c098b515ddb32d59360b92ac1d0e26c4b 100644 (file)
@@ -85,6 +85,9 @@ namespace Crow.IML
                public bool HasTemplate {
                        get { return typeof (TemplatedControl).IsAssignableFrom (CrowType);}
                }
+               public bool IsTemplatedGroup {
+                       get { return typeof (TemplatedGroup).IsAssignableFrom (CrowType);}
+               }
 
                public static implicit operator string (Node sn)
                {
index 5f187c58c20af034460188666519778ca4fec464..b79fbc82427f8d14dabaf3f72f4f5b698057a661 100644 (file)
@@ -207,7 +207,7 @@ namespace Crow.IML
                /// </summary>
                /// <returns>the string triplet dataType, itemTmpID read as attribute of this tag</returns>
                /// <param name="reader">current xml text reader</param>
-               /// /// <param name="itemTemplatePath">file containing the templates if its a dedicated one</param>
+               /// <param name="itemTemplatePath">file containing the templates if its a dedicated one</param>
                string[] parseItemTemplateTag (XmlReader reader, string itemTemplatePath = "") {
                        string dataType = "default", datas = "", path = "";
                        while (reader.MoveToNextAttribute ()) {
@@ -307,6 +307,11 @@ namespace Crow.IML
                                                }
                                        }
                                }
+                               if (!ctx.nodesStack.Peek ().IsTemplatedGroup)
+                                       return;
+                               //add the default item template if no default is defined
+                               if (!itemTemplateIds.Any(ids=>ids[0] == "default"))
+                                       itemTemplateIds.Add (new string [] { "default", "#Crow.DefaultItem.template", "" });
                                //copy item templates (review this)
                                foreach (string [] iTempId in itemTemplateIds) {
                                        ctx.il.Emit (OpCodes.Ldloc_0);//load TempControl ref
index 32b9549efc3ede87235e234576a981c02bc91b2f..b16acc072bb0de5f0a6bb663d6bd80aee96bdb3e 100644 (file)
@@ -224,9 +224,9 @@ namespace Crow
                }
                static void loadCursors(){
                        //Load cursors
-                       XCursor.Cross = XCursorFile.Load("#Crow.Images.Icons.Cursors.cross").Cursors[3];
-                       XCursor.Default = XCursorFile.Load("#Crow.Images.Icons.Cursors.arrow").Cursors[3];
-                       XCursor.NW = XCursorFile.Load("#Crow.Images.Icons.Cursors.top_left_corner").Cursors[3];
+                       XCursor.Cross = XCursorFile.Load("#Crow.Images.Icons.Cursors.cross").Cursors[0];
+                       XCursor.Default = XCursorFile.Load("#Crow.Images.Icons.Cursors.arrow").Cursors[0];
+                       XCursor.NW = XCursorFile.Load("#Crow.Images.Icons.Cursors.top_left_corner").Cursors[0];
                        XCursor.NE = XCursorFile.Load("#Crow.Images.Icons.Cursors.top_right_corner").Cursors[0];
                        XCursor.SW = XCursorFile.Load("#Crow.Images.Icons.Cursors.bottom_left_corner").Cursors[0];
                        XCursor.SE = XCursorFile.Load("#Crow.Images.Icons.Cursors.bottom_right_corner").Cursors[0];
index d0c6873e62ec4b305ebf0c72548992c60d5743e4..915aafd84a5869f113a9d27673e2d69a5daeec2c 100644 (file)
@@ -43,6 +43,9 @@ namespace Crow
 
        /// <summary>
        /// Derived from Instantiator with sub data fetching facilities for hierarchical data access.
+       /// 
+       /// ItemTemplate stores the dynamic method for instantiating the control tree defined in a valid IML file.
+       /// 
        /// </summary>
        public class ItemTemplate : Instantiator {
                public EventHandler Expand;
@@ -51,18 +54,36 @@ namespace Crow
                string fetchMethodName;
 
                #region CTOR
+               /// <summary>
+               /// Initializes a new instance of the <see cref="Crow.ItemTemplate"/> class by parsing the file passed as argument.
+               /// </summary>
+               /// <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(string path, string _dataType = null, string _fetchDataMethod = null)
                        : base(path) {
                        strDataType = _dataType;
                        fetchMethodName = _fetchDataMethod;
 
                }
+               /// <summary>
+               /// Initializes a new instance of the <see cref="Crow.ItemTemplate"/> class by parsing the IML fragment passed as arg.
+               /// </summary>
+               /// <param name="path">IML fragment 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 (Stream ImlFragment, string _dataType, string _fetchDataMethod)
                        :base(ImlFragment)
                {
                        strDataType = _dataType;
                        fetchMethodName = _fetchDataMethod;
                }
+               /// <summary>
+               /// Initializes a new instance of the <see cref="Crow.ItemTemplate"/> class using the opened XmlReader in args.
+               /// </summary>
+               /// <param name="path">XML reader positionned before or at the root node</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 (XmlReader reader, string _dataType = null, string _fetchDataMethod = null)
                        :base(reader)
                {
@@ -71,6 +92,10 @@ namespace Crow
                }
                #endregion
 
+               /// <summary>
+               /// Creates the expand delegate.
+               /// </summary>
+               /// <param name="host">Host.</param>
                public void CreateExpandDelegate (TemplatedGroup host){
                        Type dataType = CompilerServices.tryGetType(strDataType);
                        if (dataType == null) {