From 31783bbaa2ee72adad827499e66d7ac25c6ee33a Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Tue, 31 Jan 2017 15:58:52 +0100 Subject: [PATCH] move recurrent 'Caption' property in Templated Control --- Default.style | 18 ++++++++++++++---- Templates/Expandable.template | 2 +- src/GraphicObjects/Button.cs | 11 ----------- src/GraphicObjects/CheckBox.cs | 16 ++-------------- src/GraphicObjects/Expandable.cs | 25 +++++++------------------ src/GraphicObjects/GroupBox.cs | 16 ++-------------- src/GraphicObjects/MenuItem.cs | 15 ++++----------- src/GraphicObjects/Popper.cs | 19 ++++--------------- src/GraphicObjects/RadioButton.cs | 12 ------------ src/GraphicObjects/TabItem.cs | 11 +---------- src/GraphicObjects/TemplatedControl.cs | 24 +++++++++++++++++------- 11 files changed, 52 insertions(+), 117 deletions(-) diff --git a/Default.style b/Default.style index 5b39bc02..489783f5 100644 --- a/Default.style +++ b/Default.style @@ -3,10 +3,19 @@ MessageBox, Popper, Slider, Spinner, TextBox { Focusable = true; Height = Fit; } +Border { + Foreground = Gray; +} +CheckBox { Caption = CheckBox; } +RadioButton { Caption = RadioButton; } +Expandable { Caption = Expandable; } +Popper { Caption = Popper; } +GroupBox { Caption = Group Box; } Wrapper { Orientation = Vertical; } Button { + Caption = Button; Width = Fit; } Label { @@ -22,6 +31,7 @@ Menu { VerticalAlignment = Top; } MenuItem { + Caption = MenuItem; Width = Stretched; Height = Fit; Background = Transparent; @@ -50,6 +60,7 @@ TabView { CacheEnabled = false; } TabItem { + Caption = TabItem; Focusable = true; CacheEnabled = false; } @@ -61,12 +72,14 @@ TextBox { Margin = 1; } Window { + Caption = Window; Focusable = true; MinimumSize=5,5; Width = 150; Height = 150; } ToolWindow { + Caption = Window; Template = #Crow.ToolWindow.template; Focusable = true; MinimumSize=50,50; @@ -79,9 +92,6 @@ FileDialog { Width = 500; Height = 300; } -Border { - Foreground = Gray; -} ProgressBar { Foreground = vgradient|0:BlueCrayola|0.5:SkyBlue|1:BlueCrayola; } @@ -92,7 +102,7 @@ ScrollBar { Icon { Margin=1; Width=12; - Height=12; + Height=12; } Control { Margin=0; diff --git a/Templates/Expandable.template b/Templates/Expandable.template index dd058f9d..2360063a 100755 --- a/Templates/Expandable.template +++ b/Templates/Expandable.template @@ -6,7 +6,7 @@ MouseEnter="{Background=LightGray}" MouseLeave="{Background=Transparent}"> diff --git a/src/GraphicObjects/Button.cs b/src/GraphicObjects/Button.cs index c73062f0..8fc7a1ad 100644 --- a/src/GraphicObjects/Button.cs +++ b/src/GraphicObjects/Button.cs @@ -14,7 +14,6 @@ namespace Crow { public class Button : TemplatedContainer { - string caption; string image; bool isPressed; Container _contentContainer; @@ -66,16 +65,6 @@ namespace Crow } #endregion - [XmlAttributeAttribute][DefaultValue("Button")] - public string Caption { - get { return caption; } - set { - if (caption == value) - return; - caption = value; - NotifyValueChanged ("Caption", caption); - } - } [XmlAttributeAttribute][DefaultValue("#Crow.Images.button.svg")] public string Image { get { return image; } diff --git a/src/GraphicObjects/CheckBox.cs b/src/GraphicObjects/CheckBox.cs index 46d77e76..19bbb9b9 100644 --- a/src/GraphicObjects/CheckBox.cs +++ b/src/GraphicObjects/CheckBox.cs @@ -27,28 +27,16 @@ namespace Crow { public class CheckBox : TemplatedControl { - string caption; - string image; bool isChecked; #region CTOR public CheckBox() : base() - {} + {} #endregion public event EventHandler Checked; public event EventHandler Unchecked; - [XmlAttributeAttribute()][DefaultValue("Checkbox")] - public string Caption { - get { return caption; } - set { - if (caption == value) - return; - caption = value; - NotifyValueChanged ("Caption", caption); - } - } [XmlAttributeAttribute()][DefaultValue(false)] public bool IsChecked { @@ -57,7 +45,7 @@ namespace Crow { if (isChecked == value) return; - + isChecked = value; NotifyValueChanged ("IsChecked", value); diff --git a/src/GraphicObjects/Expandable.cs b/src/GraphicObjects/Expandable.cs index 38506de8..92cf1640 100644 --- a/src/GraphicObjects/Expandable.cs +++ b/src/GraphicObjects/Expandable.cs @@ -35,7 +35,6 @@ namespace Crow #region Private fields bool _isExpanded; - string caption; string image; Container _contentContainer; #endregion @@ -70,26 +69,16 @@ namespace Crow } #region Public properties - [XmlAttributeAttribute][DefaultValue("Expandable")] - public string Caption { - get { return caption; } - set { - if (caption == value) - return; - caption = value; - NotifyValueChanged ("Caption", caption); - } - } [XmlAttributeAttribute][DefaultValue("#Crow.Images.Icons.expandable.svg")] public string Image { - get { return image; } + get { return image; } set { if (image == value) return; - image = value; + image = value; NotifyValueChanged ("Image", image); } - } + } [XmlAttributeAttribute][DefaultValue(false)] public bool IsExpanded { @@ -120,11 +109,11 @@ namespace Crow [XmlIgnore]public bool IsExpandable { get { try { - return GetIsExpandable == null ? true : GetIsExpandable (this); + return GetIsExpandable == null ? true : GetIsExpandable (this); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine ("Not Expandable error: " + ex.ToString ()); return false; - } + } } } #endregion @@ -133,14 +122,14 @@ namespace Crow { if (_contentContainer != null) _contentContainer.Visible = true; - + Expand.Raise (this, e); } public virtual void onCollapse(object sender, EventArgs e) { if (_contentContainer != null) _contentContainer.Visible = false; - + Collapse.Raise (this, e); } } diff --git a/src/GraphicObjects/GroupBox.cs b/src/GraphicObjects/GroupBox.cs index db457282..34094703 100644 --- a/src/GraphicObjects/GroupBox.cs +++ b/src/GraphicObjects/GroupBox.cs @@ -26,12 +26,11 @@ using System.ComponentModel; namespace Crow { public class GroupBox : TemplatedContainer - { - string caption; + { Container _contentContainer; #region CTOR - public GroupBox() : base(){} + public GroupBox() : base(){} #endregion #region Template overrides @@ -50,16 +49,5 @@ namespace Crow _contentContainer = this.child.FindByName ("Content") as Container; } #endregion - - [XmlAttributeAttribute][DefaultValue("Groupbox")] - public string Caption { - get { return caption; } - set { - if (caption == value) - return; - caption = value; - NotifyValueChanged ("Caption", caption); - } - } } } diff --git a/src/GraphicObjects/MenuItem.cs b/src/GraphicObjects/MenuItem.cs index adec326f..b277194e 100644 --- a/src/GraphicObjects/MenuItem.cs +++ b/src/GraphicObjects/MenuItem.cs @@ -78,17 +78,10 @@ namespace Crow NotifyValueChanged ("Command", command); } } - [XmlAttributeAttribute][DefaultValue("MenuItem")] - public string Caption { - get { return Command == null ? caption : Command.Caption; } - set { - if (caption == value) - return; - caption = value; - - if (command == null)//raise value changed only if not bound to a command - NotifyValueChanged ("Caption", caption); - } + [XmlAttributeAttribute] + public override string Caption { + get { return Command == null ? base.Caption : Command.Caption; } + set { base.Caption = value; } } [XmlAttributeAttribute] public Picture Icon { diff --git a/src/GraphicObjects/Popper.cs b/src/GraphicObjects/Popper.cs index 0b022842..10d5d30e 100644 --- a/src/GraphicObjects/Popper.cs +++ b/src/GraphicObjects/Popper.cs @@ -35,25 +35,14 @@ namespace Crow #endregion bool _isPopped, _canPop; - string caption; Alignment popDirection; GraphicObject _content; Measure popWidth, popHeight; - public event EventHandler Pop; - public event EventHandler Unpop; + public event EventHandler Popped; + public event EventHandler Unpoped; #region Public Properties - [XmlAttributeAttribute()][DefaultValue("Popper")] - public string Caption { - get { return caption; } - set { - if (caption == value) - return; - caption = value; - NotifyValueChanged ("Caption", caption); - } - } [XmlAttributeAttribute()][DefaultValue("Fit")] public virtual Measure PopWidth { get { return popWidth; } @@ -234,14 +223,14 @@ namespace Crow CurrentInterface.PutOnTop (Content, true); _content_LayoutChanged (this, new LayoutingEventArgs (LayoutingType.Sizing)); } - Pop.Raise (this, e); + Popped.Raise (this, e); } public virtual void onUnpop(object sender, EventArgs e) { if (Content != null) { Content.Visible = false; } - Unpop.Raise (this, e); + Unpoped.Raise (this, e); } } } diff --git a/src/GraphicObjects/RadioButton.cs b/src/GraphicObjects/RadioButton.cs index ede16475..9ead433b 100644 --- a/src/GraphicObjects/RadioButton.cs +++ b/src/GraphicObjects/RadioButton.cs @@ -27,8 +27,6 @@ namespace Crow { public class RadioButton : TemplatedControl { - string caption; - string image; bool isChecked; #region CTOR @@ -56,16 +54,6 @@ namespace Crow } #endregion - [XmlAttributeAttribute()][DefaultValue("RadioButton")] - public string Caption { - get { return caption; } - set { - if (caption == value) - return; - caption = value; - NotifyValueChanged ("Caption", caption); - } - } [XmlAttributeAttribute()][DefaultValue(false)] public bool IsChecked { diff --git a/src/GraphicObjects/TabItem.cs b/src/GraphicObjects/TabItem.cs index aca033d9..923aa51e 100644 --- a/src/GraphicObjects/TabItem.cs +++ b/src/GraphicObjects/TabItem.cs @@ -89,16 +89,7 @@ namespace Crow RegisterForGraphicUpdate (); } } - [XmlAttributeAttribute][DefaultValue("TabItem")] - public string Caption { - get { return caption; } - set { - if (caption == value) - return; - caption = value; - NotifyValueChanged ("Caption", caption); - } - } + [XmlAttributeAttribute][DefaultValue(false)] public virtual bool IsSelected { get { return isSelected; } diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs index cd645dd3..37a220cc 100644 --- a/src/GraphicObjects/TemplatedControl.cs +++ b/src/GraphicObjects/TemplatedControl.cs @@ -39,13 +39,9 @@ namespace Crow } #endregion - public override void Initialize () - { - loadTemplate (); - base.Initialize (); - } - string _template; + string caption; + [XmlAttributeAttribute][DefaultValue(null)] public string Template { get { return _template; } @@ -60,8 +56,22 @@ namespace Crow loadTemplate (CurrentInterface.Load (_template)); } } - + [XmlAttributeAttribute()][DefaultValue("Templated Control")] + public virtual string Caption { + get { return caption; } + set { + if (caption == value) + return; + caption = value; + NotifyValueChanged ("Caption", caption); + } + } #region GraphicObject overrides + public override void Initialize () + { + loadTemplate (); + base.Initialize (); + } public override GraphicObject FindByName (string nameToFind) { //prevent name searching in template -- 2.47.3