aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2015-06-10 16:10:18 +0200
committerjpbruyere <jp.bruyere@hotmail.com>2015-06-10 16:10:18 +0200
commit04f0def856c8ff46ad63cd5976a1299c0b91ac44 (patch)
tree274f83dc92712d8352b7949551e9eefcb66ad291 /src/GraphicObjects
parent73c7ac95b12d72bcb3f5d549c76bdf0b5a093847 (diff)
- template attribute (in xml, and in c# for default one
Diffstat (limited to 'src/GraphicObjects')
-rw-r--r--src/GraphicObjects/Checkbox.cs11
-rw-r--r--src/GraphicObjects/Expandable.cs7
-rw-r--r--src/GraphicObjects/ListBox.cs7
-rw-r--r--src/GraphicObjects/RadioButton.cs8
-rw-r--r--src/GraphicObjects/Spinner.cs9
-rw-r--r--src/GraphicObjects/TemplatedControl.cs70
6 files changed, 66 insertions, 46 deletions
diff --git a/src/GraphicObjects/Checkbox.cs b/src/GraphicObjects/Checkbox.cs
index d36f1266..0e20ddb7 100644
--- a/src/GraphicObjects/Checkbox.cs
+++ b/src/GraphicObjects/Checkbox.cs
@@ -16,6 +16,7 @@ using System.ComponentModel;
namespace go
{
+ [DefaultTemplate("#go.Templates.Checkbox.goml")]
public class Checkbox : TemplatedControl
{
Label _caption;
@@ -24,13 +25,13 @@ namespace go
public Checkbox() : base()
{
}
-
+ protected override void loadDefaultValues ()
+ {
+ base.loadDefaultValues ();
+ }
protected override void loadTemplate(GraphicObject template = null)
{
- if (template == null)
- this.SetChild (Interface.Load ("#go.Templates.Checkbox.goml", this));
- else
- this.SetChild (template);
+ base.loadTemplate (template);
_caption = this.child.FindByName ("Caption") as Label;
_image = this.child.FindByName ("Image") as Image;
diff --git a/src/GraphicObjects/Expandable.cs b/src/GraphicObjects/Expandable.cs
index 6f215b2f..5bf535a4 100644
--- a/src/GraphicObjects/Expandable.cs
+++ b/src/GraphicObjects/Expandable.cs
@@ -18,6 +18,7 @@ using System.IO;
namespace go
{
+ [DefaultTemplate("#go.Templates.Expandable.goml")]
public class Expandable : TemplatedControl
{
bool _isExpanded;
@@ -35,10 +36,7 @@ namespace go
protected override void loadTemplate(GraphicObject template = null)
{
- if (template == null)
- this.SetChild (Interface.Load ("#go.Templates.Expandable.goml",this));
- else
- this.SetChild (template);
+ base.loadTemplate (template);
_caption = this.child.FindByName ("Caption") as Label;
Content = this.child.FindByName ("Content") as Container;
@@ -47,6 +45,7 @@ namespace go
if (_image == null)
return;
_image.SvgSub = "collapsed";
+
this.Expand += (object sender, EventArgs e) => {_image.SvgSub = "expanded";};
this.Collapse += (object sender, EventArgs e) => {_image.SvgSub = "collapsed";};
diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs
index ce6db79b..a66fe7d4 100644
--- a/src/GraphicObjects/ListBox.cs
+++ b/src/GraphicObjects/ListBox.cs
@@ -25,6 +25,7 @@ using System.ComponentModel;
namespace go
{
+ [DefaultTemplate("#go.Templates.Listbox.goml")]
public class ListBox : TemplatedControl
{
Group _list;
@@ -36,11 +37,7 @@ namespace go
#region implemented abstract members of TemplatedControl
protected override void loadTemplate (GraphicObject template = null)
{
- if (template == null)
- this.SetChild (Interface.Load ("#go.Templates.Listbox.goml"));
- else
- this.SetChild (template);
-
+ base.loadTemplate (template);
_list = this.child.FindByName ("List") as Group;
}
#endregion
diff --git a/src/GraphicObjects/RadioButton.cs b/src/GraphicObjects/RadioButton.cs
index 71911d68..8c8000e2 100644
--- a/src/GraphicObjects/RadioButton.cs
+++ b/src/GraphicObjects/RadioButton.cs
@@ -16,6 +16,7 @@ using System.ComponentModel;
namespace go
{
+ [DefaultTemplate("#go.Templates.RadioButton.goml")]
public class RadioButton : TemplatedControl
{
Label _caption;
@@ -27,10 +28,7 @@ namespace go
protected override void loadTemplate(GraphicObject template = null)
{
- if (template == null)
- this.SetChild (Interface.Load ("#go.Templates.RadioButton.goml"));
- else
- this.SetChild (template);
+ base.loadTemplate (template);
_caption = this.child.FindByName ("Caption") as Label;
_image = this.child.FindByName ("Image") as Image;
@@ -38,7 +36,7 @@ namespace go
}
- [XmlAttributeAttribute()][DefaultValue("RadioButton")]
+ [XmlAttributeAttribute][DefaultValue("RadioButton")]
public string Caption {
get { return _caption.Text; }
set {
diff --git a/src/GraphicObjects/Spinner.cs b/src/GraphicObjects/Spinner.cs
index 4bd3a723..048dd849 100644
--- a/src/GraphicObjects/Spinner.cs
+++ b/src/GraphicObjects/Spinner.cs
@@ -23,10 +23,9 @@ using OpenTK.Input;
namespace go
{
+ [DefaultTemplate("#go.Templates.Spinner.goml")]
public class Spinner : NumericControl
{
-// Button butUp;
-// Button butDown;
Label labCpt;
public Spinner (double minimum, double maximum, double step) :
@@ -42,11 +41,7 @@ namespace go
protected override void loadTemplate (GraphicObject template = null)
{
- if (template == null)
- this.SetChild (Interface.Load ("#go.Templates.Spinner.goml", this));
- else
- this.SetChild (template);
-
+ base.loadTemplate (template);
labCpt = this.child.FindByName ("labCpt") as Label;
}
diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs
index 75d5b54f..7c50a2ea 100644
--- a/src/GraphicObjects/TemplatedControl.cs
+++ b/src/GraphicObjects/TemplatedControl.cs
@@ -23,9 +23,21 @@ using System.Xml.Serialization;
using System.ComponentModel;
using System.IO;
using System.Xml;
+using System.Linq;
+using System.Diagnostics;
namespace go
{
+ [AttributeUsage(AttributeTargets.Class)]
+ public class DefaultTemplate : Attribute
+ {
+ public string Path = "";
+ public DefaultTemplate(string path)
+ {
+ Path = path;
+ }
+ }
+
public abstract class TemplatedControl : PrivateContainer, IXmlSerializable
{
public TemplatedControl () : base()
@@ -40,7 +52,14 @@ namespace go
// }
- protected abstract void loadTemplate(GraphicObject template = null);
+ protected virtual void loadTemplate(GraphicObject template = null)
+ {
+ if (template == null) {
+ DefaultTemplate dt = (DefaultTemplate)this.GetType ().GetCustomAttributes (typeof(DefaultTemplate), true).FirstOrDefault();
+ this.SetChild (Interface.Load (dt.Path, this));
+ }else
+ this.SetChild (template);
+ }
protected override void loadDefaultValues ()
{
@@ -64,37 +83,48 @@ namespace go
}
public override void ReadXml(System.Xml.XmlReader reader)
{
+ //Template could be either an attribute containing path or expressed inlined
+ //as a Template Element
using (System.Xml.XmlReader subTree = reader.ReadSubtree())
{
subTree.Read ();
+
+ string template = reader.GetAttribute ("Template");
string tmp = subTree.ReadOuterXml ();
+ //Load template from path set as attribute in templated control
+ if (string.IsNullOrEmpty (template)) {
//seek for template tag first
- using (XmlReader xr = new XmlTextReader (tmp, XmlNodeType.Element, null)) {
- //load template first if inlined
+ using (XmlReader xr = new XmlTextReader (tmp, XmlNodeType.Element, null)) {
+ //load template first if inlined
- xr.Read (); //skip current node
+ xr.Read (); //skip current node
- while (!xr.EOF) {
- xr.Read (); //read first child
- if (!xr.IsStartElement ())
- continue;
- if (xr.Name == "Template") {
- xr.Read ();
+ while (!xr.EOF) {
+ xr.Read (); //read first child
+ if (!xr.IsStartElement ())
+ continue;
+ if (xr.Name == "Template") {
+ xr.Read ();
- Type t = Type.GetType ("go." + xr.Name);
- GraphicObject go = (GraphicObject)Activator.CreateInstance (t);
- (go as IXmlSerializable).ReadXml (xr);
+ Type t = Type.GetType ("go." + xr.Name);
+ GraphicObject go = (GraphicObject)Activator.CreateInstance (t);
+ (go as IXmlSerializable).ReadXml (xr);
- loadTemplate (go);
+ loadTemplate (go);
- xr.Read ();//go close tag
- xr.Read ();//Template close tag
- } else {
- xr.ReadInnerXml ();
+ xr.Read ();//go close tag
+ xr.Read ();//Template close tag
+ } else {
+ xr.ReadInnerXml ();
+ }
}
- }
- }
+ }
+ } else
+ loadTemplate (Interface.Load (template, this));
+
+
+ //normal xml read
using (XmlReader xr = new XmlTextReader (tmp, XmlNodeType.Element, null)) {
xr.Read ();
base.ReadXml(xr);