From e9c3f48e6615c8bf193ad814c74fc6d75858f513 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Tue, 6 Feb 2018 07:07:57 +0100 Subject: [PATCH] :book:, default item template loading if none defined for TemplatedGroup --- Crow.csproj | 4 ++- ...ItemTemplate.goml => DefaultItem.template} | 0 src/GraphicObjects/TemplatedGroup.cs | 6 ++--- src/IML/Node.cs | 3 +++ src/Instantiator.cs | 7 +++++- src/Interface.cs | 6 ++--- src/ItemTemplate.cs | 25 +++++++++++++++++++ 7 files changed, 43 insertions(+), 8 deletions(-) rename Templates/{ItemTemplate.goml => DefaultItem.template} (100%) diff --git a/Crow.csproj b/Crow.csproj index e6cf6864..38f19b9e 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -252,7 +252,6 @@ - @@ -371,6 +370,9 @@ Crow.DockingView.template + + Crow.DefaultItem.template + diff --git a/Templates/ItemTemplate.goml b/Templates/DefaultItem.template similarity index 100% rename from Templates/ItemTemplate.goml rename to Templates/DefaultItem.template diff --git a/src/GraphicObjects/TemplatedGroup.cs b/src/GraphicObjects/TemplatedGroup.cs index 81ea25fb..55726b50 100644 --- a/src/GraphicObjects/TemplatedGroup.cs +++ b/src/GraphicObjects/TemplatedGroup.cs @@ -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. /// - [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; } diff --git a/src/IML/Node.cs b/src/IML/Node.cs index 8b85388b..2ca90e8c 100644 --- a/src/IML/Node.cs +++ b/src/IML/Node.cs @@ -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) { diff --git a/src/Instantiator.cs b/src/Instantiator.cs index 5f187c58..b79fbc82 100644 --- a/src/Instantiator.cs +++ b/src/Instantiator.cs @@ -207,7 +207,7 @@ namespace Crow.IML /// /// the string triplet dataType, itemTmpID read as attribute of this tag /// current xml text reader - /// /// file containing the templates if its a dedicated one + /// file containing the templates if its a dedicated one 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 diff --git a/src/Interface.cs b/src/Interface.cs index 32b9549e..b16acc07 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -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]; diff --git a/src/ItemTemplate.cs b/src/ItemTemplate.cs index d0c6873e..915aafd8 100644 --- a/src/ItemTemplate.cs +++ b/src/ItemTemplate.cs @@ -43,6 +43,9 @@ namespace Crow /// /// 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. + /// /// public class ItemTemplate : Instantiator { public EventHandler Expand; @@ -51,18 +54,36 @@ namespace Crow string fetchMethodName; #region CTOR + /// + /// Initializes a new instance of the class by parsing the file passed as argument. + /// + /// IML file to parse + /// type this item will be choosen for, or member of the data item + /// for hierarchical data, method to call for children fetching public ItemTemplate(string path, string _dataType = null, string _fetchDataMethod = null) : base(path) { strDataType = _dataType; fetchMethodName = _fetchDataMethod; } + /// + /// Initializes a new instance of the class by parsing the IML fragment passed as arg. + /// + /// IML fragment to parse + /// type this item will be choosen for, or member of the data item + /// for hierarchical data, method to call for children fetching public ItemTemplate (Stream ImlFragment, string _dataType, string _fetchDataMethod) :base(ImlFragment) { strDataType = _dataType; fetchMethodName = _fetchDataMethod; } + /// + /// Initializes a new instance of the class using the opened XmlReader in args. + /// + /// XML reader positionned before or at the root node + /// type this item will be choosen for, or member of the data item + /// for hierarchical data, method to call for children fetching public ItemTemplate (XmlReader reader, string _dataType = null, string _fetchDataMethod = null) :base(reader) { @@ -71,6 +92,10 @@ namespace Crow } #endregion + /// + /// Creates the expand delegate. + /// + /// Host. public void CreateExpandDelegate (TemplatedGroup host){ Type dataType = CompilerServices.tryGetType(strDataType); if (dataType == null) { -- 2.47.3