aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2016-08-03 14:21:19 +0200
committerjpbruyere <jp.bruyere@hotmail.com>2016-08-03 14:21:19 +0200
commitb24819ffb8f629fb0ed70064f90357a42653ae5d (patch)
treeb3636cddb37b4fcc679b81b0afb2b1e1ac12f840 /src/GraphicObjects
parent5e7f9ad632b4c42bee7f111c0155b869e3ae4f18 (diff)
ItemTemplate xml element implementation
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
Diffstat (limited to 'src/GraphicObjects')
-rw-r--r--src/GraphicObjects/ListBox.cs36
-rw-r--r--src/GraphicObjects/TemplatedControl.cs39
2 files changed, 48 insertions, 27 deletions
diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs
index e7a1c330..c315d81d 100644
--- a/src/GraphicObjects/ListBox.cs
+++ b/src/GraphicObjects/ListBox.cs
@@ -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)
diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs
index 12c2b81f..5b7df01d 100644
--- a/src/GraphicObjects/TemplatedControl.cs
+++ b/src/GraphicObjects/TemplatedControl.cs
@@ -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 ();