]> O.S.I.I.S - jp/crow.git/commitdiff
ItemTemplate xml element implementation
authorjpbruyere <jp.bruyere@hotmail.com>
Wed, 3 Aug 2016 12:21:19 +0000 (14:21 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Wed, 3 Aug 2016 12:21:19 +0000 (14:21 +0200)
nouveau fichier : Tests/Interfaces/Unsorted/testItemTemplateTag.crow
modifié :         Tests/Tests.csproj
modifié :         src/GraphicObjects/ListBox.cs
modifié :         src/GraphicObjects/TemplatedControl.cs
modifié :         src/IMLStream.cs

Tests/Interfaces/Unsorted/testItemTemplateTag.crow [new file with mode: 0755]
Tests/Tests.csproj
src/GraphicObjects/ListBox.cs
src/GraphicObjects/TemplatedControl.cs
src/IMLStream.cs

diff --git a/Tests/Interfaces/Unsorted/testItemTemplateTag.crow b/Tests/Interfaces/Unsorted/testItemTemplateTag.crow
new file mode 100755 (executable)
index 0000000..e05c2d1
--- /dev/null
@@ -0,0 +1,40 @@
+<?xml version="1.0"?>
+<Border BorderWidth="2" Fit="true">
+       <VerticalStack Fit="true" Margin="5">
+               <ListBox Data="{TestList}" Background="0.5,0.5,0.5,0.7"
+                                        HorizontalAlignment="Center" Width="200" Height="200" Margin="5">
+                       <Template>
+                               <Border BorderWidth="1" Height="{../HeightPolicy}" Width="{../WidthPolicy}">
+                                       <HorizontalStack Margin="1" Height="{../../HeightPolicy}" Width="{../../WidthPolicy}" >
+                                               <Scroller Name="scroller1" Height="{../../../HeightPolicy}" Width="{../../../WidthPolicy}" 
+                                                               Margin="2" VerticalScrolling="true" ScrollY="{../scrollbar1.Value}"
+                                                               ValueChanged="../../../_scroller_ValueChanged">
+                                                       <VerticalStack Width="{../../../../WidthPolicy}" Height="Fit" MinimumSize="10,10"
+                                                               Name="List" Margin="0"
+                                                               VerticalAlignment="Top"
+                                                               HorizontalAlignment="Left"
+                                                               LayoutChanged="../../../../_list_LayoutChanged"/>
+                                               </Scroller>
+                                               <ScrollBar Name="scrollbar1" Value="{../scroller1.ScrollY}" 
+                                                       Maximum="{../scroller1.MaximumScroll}" Orientation="Vertical" 
+                                                       Width="14" Height="{../../../HeightPolicy}" />
+                                       </HorizontalStack>
+                               </Border>
+                       </Template>
+                       <ItemTemplate DataType="Crow.Color">
+                               <HorizontalStack
+                                                       HorizontalAlignment="Left"
+                                                       Height="Fit" Width="200" Margin="1" Focusable="true"
+                                                       MouseEnter="{Background=hgradient|0:DarkRed|1:Transparent}"
+                                                       MouseLeave="{Background=Transparent}">
+                                       <GraphicObject Height="12" Width="20" Background="{}" Margin="0" CornerRadius="3"/>
+                                       <Label Text="{Name}" Margin="0" Width="Stretched"/>
+                               </HorizontalStack>
+                       </ItemTemplate>
+               </ListBox>
+               <HorizontalStack Fit="true" HorizontalAlignment="Right">
+                       <Button Caption="Load list" MouseClick="OnLoadList"/>
+                       <Button Caption="Clear" MouseClick="OnClear"/>
+               </HorizontalStack>
+       </VerticalStack>
+</Border>
\ No newline at end of file
index 7e32a7d5cd13b839065dc970202d9c60b6324a59..d365c0600e6f18998b754c2fa8cf6a1882a46c93 100644 (file)
@@ -45,7 +45,7 @@
        <Reference Include="gdk-sharp"/>
        <Reference Include="gio-sharp"/>
        <Reference Include="glib-sharp"/>
-       <Reference Include="OpenTK">
+    <Reference Include="OpenTK">
       <HintPath>$(SolutionDir)packages\OpenTK.Next.1.2.2336.6514-pre\lib\net20\OpenTK.dll</HintPath>
     </Reference>
   </ItemGroup>
     <None Include="Interfaces\Unsorted\0.crow">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
+    <None Include="Interfaces\Unsorted\testItemTemplateTag.crow">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Interfaces\" />
index e7a1c3304f25fe9d29fa821c4794a774d2e280b6..c315d81d34c7bfd160418d9dbd62504d4210af55 100644 (file)
@@ -45,13 +45,10 @@ namespace Crow
                GenericStack _gsList;
                IList data;
                int _selectedIndex;
-               string _itemTemplate;
                int itemPerPage = 50;
                Thread loadingThread = null;
                volatile bool cancelLoading = false;
 
-               IMLStream templateStream = null;
-
                [XmlAttributeAttribute]public IList Data {
                        get {
                                return data;
@@ -86,24 +83,7 @@ namespace Crow
                                SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem));
                        }
                }
-               [XmlAttributeAttribute][DefaultValue("#Crow.Templates.ItemTemplate.goml")]
-               public string ItemTemplate {
-                       get { return _itemTemplate; }
-                       set { 
-                               if (value == _itemTemplate)
-                                       return;
-
-                               _itemTemplate = value;
-
-                               if (templateStream != null) {
-                                       templateStream.Dispose ();
-                                       templateStream = null;
-                               }
 
-                               //TODO:reload list with new template?
-                               NotifyValueChanged("ItemTemplate", _itemTemplate);
-                       }
-               }
                [XmlAttributeAttribute][DefaultValue(-1)]public int SelectedIndex{
                        get { return _selectedIndex; }
                        set { 
@@ -131,8 +111,12 @@ namespace Crow
                        _gsList = _list as GenericStack;
                }
                #endregion
-               void loading(){                 
-                       templateStream = new IMLStream (ItemTemplate);
+               void loading(){
+                       if (itemTemplates == null) {
+                               itemTemplates = new Dictionary<string, IMLStream> ();
+                               //TODO:check encoding
+                               itemTemplates["default"] = new IMLStream (ItemTemplate);
+                       }
                        for (int i = 1; i <= (data.Count / itemPerPage) + 1; i++) {
                                if (cancelLoading)
                                        return;
@@ -174,8 +158,14 @@ namespace Crow
                                        break;
                                if (cancelLoading)
                                        return;
+                               
+                               GraphicObject g = null;
+                               Type dataType = data [i].GetType ();
+                               if (itemTemplates.ContainsKey (dataType.FullName))
+                                       g = Interface.Load (itemTemplates [dataType.FullName]);
+                               else if (itemTemplates.ContainsKey ("default"))
+                                       g = Interface.Load (itemTemplates ["default"]);                         
 
-                               GraphicObject g = Interface.Load (templateStream);
                                g.MouseClick += itemClick;
 
                                lock (Interface.CurrentInterface.UpdateMutex)
index 12c2b81f144d43d11bf0f8b443b1713936292139..5b7df01d80d38352daa5f61057ad895d3c6b2110 100644 (file)
@@ -25,6 +25,8 @@ using System.IO;
 using System.Xml;
 using System.Diagnostics;
 using System.Linq;
+using System.Collections.Generic;
+using System.Text;
 
 namespace Crow
 {
@@ -61,6 +63,8 @@ namespace Crow
                #endregion
 
                string _template;
+               string _itemTemplate;
+               protected Dictionary<string, IMLStream> itemTemplates;
 
                [XmlAttributeAttribute][DefaultValue(null)]
                public string Template {
@@ -76,7 +80,19 @@ namespace Crow
                                        loadTemplate (Interface.Load (_template, this));
                        }
                }
+               [XmlAttributeAttribute][DefaultValue("#Crow.Templates.ItemTemplate.goml")]
+               public string ItemTemplate {
+                       get { return _itemTemplate; }
+                       set { 
+                               if (value == _itemTemplate)
+                                       return;
+
+                               _itemTemplate = value;
 
+                               //TODO:reload list with new template?
+                               NotifyValueChanged("ItemTemplate", _itemTemplate);
+                       }
+               }
                #region GraphicObject overrides
                public override GraphicObject FindByName (string nameToFind)
                {
@@ -121,7 +137,23 @@ namespace Crow
                                                        xr.Read (); //read first child
                                                        if (!xr.IsStartElement ())
                                                                continue;
-                                                       if (xr.Name == "Template") {
+                                                       if (xr.Name == "ItemTemplate") {
+                                                               string dataType = "default", datas, itemTmp;
+                                                               while (xr.MoveToNextAttribute ()) {
+                                                                       if (xr.Name == "DataType")
+                                                                               dataType = xr.Value;
+                                                                       else if (xr.Name == "Data")
+                                                                               datas = xr.Value;
+                                                               }
+                                                               xr.MoveToElement ();
+                                                               itemTmp = xr.ReadInnerXml ();
+                                                               xr.Read ();//itemTemplate close tag
+                                                               if (itemTemplates == null)
+                                                                       itemTemplates = new Dictionary<string, IMLStream> ();
+                                                               //TODO:check encoding
+                                                               itemTemplates[dataType] = new IMLStream (Encoding.UTF8.GetBytes(itemTmp));
+
+                                                       }else if (xr.Name == "Template") {
                                                                xr.Read ();
 
                                                                Type t = Type.GetType ("Crow." + xr.Name);
@@ -131,8 +163,7 @@ namespace Crow
                                                                loadTemplate (go);
 
                                                                xr.Read ();//go close tag
-                                                               xr.Read ();//Template close tag
-                                                               break;
+                                                               //xr.Read ();//Template close tag
                                                        } else
                                                                xr.ReadInnerXml ();
                                                }
@@ -143,7 +174,7 @@ namespace Crow
                                //if no template found, load default one
                                if (this.child == null)
                                        loadTemplate ();
-
+                               
                                //normal xml read
                                using (XmlReader xr = new XmlTextReader (tmp, XmlNodeType.Element, null)) {
                                        xr.Read ();
index 69357791953552159d759fce86f4b120d8ed7f7a..776a70e7d2c489b05a5329b4604697996ca5f64e 100644 (file)
@@ -30,6 +30,9 @@ namespace Crow
                                stream.CopyTo (this);
                        RootType = Interface.GetTopContainerOfXMLStream (this);
                }
+               public IMLStream(Byte[] b) : base (b){                  
+                       RootType = Interface.GetTopContainerOfXMLStream (this);
+               }
        }
 }