From 6fd6f186ec136522cf113ea39c4e66ac7cfccd32 Mon Sep 17 00:00:00 2001 From: grokys Date: Tue, 4 Feb 2014 22:56:26 +0100 Subject: [PATCH] Added ITemplatedControl interface. --- Perspex.UnitTests/Perspex.UnitTests.csproj | 1 + Perspex.UnitTests/Styling/SelectorTests_Id.cs | 6 +--- .../Styling/SelectorTests_InTemplateOf.cs | 12 ++----- .../Styling/SelectorTests_Template.cs | 34 +++++++++++++++++++ Perspex.UnitTests/Styling/SubscribeCheck.cs | 2 +- Perspex/ControlTemplate.cs | 10 +++--- Perspex/Controls/Control.cs | 2 +- Perspex/Controls/ITemplatedControl.cs | 12 +++++++ Perspex/Controls/TemplatedControl.cs | 2 +- Perspex/Perspex.csproj | 1 + Perspex/Styling/IStyleable.cs | 2 +- Perspex/Styling/Selectors.cs | 2 +- 12 files changed, 61 insertions(+), 25 deletions(-) create mode 100644 Perspex.UnitTests/Styling/SelectorTests_Template.cs create mode 100644 Perspex/Controls/ITemplatedControl.cs diff --git a/Perspex.UnitTests/Perspex.UnitTests.csproj b/Perspex.UnitTests/Perspex.UnitTests.csproj index 5ad3e218e1..db28dc5fee 100644 --- a/Perspex.UnitTests/Perspex.UnitTests.csproj +++ b/Perspex.UnitTests/Perspex.UnitTests.csproj @@ -69,6 +69,7 @@ + diff --git a/Perspex.UnitTests/Styling/SelectorTests_Id.cs b/Perspex.UnitTests/Styling/SelectorTests_Id.cs index c1fa84395b..873bf4a00b 100644 --- a/Perspex.UnitTests/Styling/SelectorTests_Id.cs +++ b/Perspex.UnitTests/Styling/SelectorTests_Id.cs @@ -78,12 +78,8 @@ namespace Perspex.UnitTests.Styling { } - public class TemplatedControl1 : TemplatedControl + public class TemplatedControl1 : ITemplatedControl { - protected override Size MeasureContent(Size availableSize) - { - throw new NotImplementedException(); - } } } } diff --git a/Perspex.UnitTests/Styling/SelectorTests_InTemplateOf.cs b/Perspex.UnitTests/Styling/SelectorTests_InTemplateOf.cs index 0547c2bd42..a27de04fd5 100644 --- a/Perspex.UnitTests/Styling/SelectorTests_InTemplateOf.cs +++ b/Perspex.UnitTests/Styling/SelectorTests_InTemplateOf.cs @@ -60,20 +60,12 @@ namespace Perspex.UnitTests.Styling { } - public class TemplatedControl1 : TemplatedControl + public class TemplatedControl1 : ITemplatedControl { - protected override Size MeasureContent(Size availableSize) - { - throw new NotImplementedException(); - } } - public class TemplatedControl2 : TemplatedControl + public class TemplatedControl2 : ITemplatedControl { - protected override Size MeasureContent(Size availableSize) - { - throw new NotImplementedException(); - } } } } diff --git a/Perspex.UnitTests/Styling/SelectorTests_Template.cs b/Perspex.UnitTests/Styling/SelectorTests_Template.cs new file mode 100644 index 0000000000..3faa8eaca4 --- /dev/null +++ b/Perspex.UnitTests/Styling/SelectorTests_Template.cs @@ -0,0 +1,34 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2014 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- + +namespace Perspex.UnitTests.Styling +{ + using System.Linq; + using System.Reactive.Linq; + using Microsoft.VisualStudio.TestTools.UnitTesting; + using Perspex.Styling; + + [TestClass] + public class SelectorTests_Template + { + [TestMethod] + public void Foo() + { + var control = new Control1 + { + Classes = new Classes { "foo" }, + }; + + var target = control.Select().Class("foo"); + + CollectionAssert.AreEqual(new[] { true }, target.GetActivator().Take(1).ToEnumerable().ToArray()); + } + + public class Control1 : SubscribeCheck + { + } + } +} diff --git a/Perspex.UnitTests/Styling/SubscribeCheck.cs b/Perspex.UnitTests/Styling/SubscribeCheck.cs index b9eb1ddf86..5bd0fd0d78 100644 --- a/Perspex.UnitTests/Styling/SubscribeCheck.cs +++ b/Perspex.UnitTests/Styling/SubscribeCheck.cs @@ -38,7 +38,7 @@ namespace Perspex.UnitTests.Styling public TestObservable SubscribeCheckObservable { get; private set; } - public TemplatedControl TemplatedParent + public ITemplatedControl TemplatedParent { get; set; diff --git a/Perspex/ControlTemplate.cs b/Perspex/ControlTemplate.cs index 904cfe376f..1d22e2d775 100644 --- a/Perspex/ControlTemplate.cs +++ b/Perspex/ControlTemplate.cs @@ -13,16 +13,16 @@ namespace Perspex public class ControlTemplate { - private Func build; + private Func build; - public ControlTemplate(Func build) + public ControlTemplate(Func build) { Contract.Requires(build != null); this.build = build; } - public Control Build(TemplatedControl templatedParent) + public Control Build(ITemplatedControl templatedParent) { Contract.Requires(templatedParent != null); @@ -32,14 +32,14 @@ namespace Perspex } public static ControlTemplate Create(Func build) - where TControl : TemplatedControl + where TControl : ITemplatedControl { Contract.Requires(build != null); return new ControlTemplate(c => build((TControl)c)); } - private void SetTemplatedParent(Control control, TemplatedControl templatedParent) + private void SetTemplatedParent(Control control, ITemplatedControl templatedParent) { Contract.Requires(control != null); Contract.Requires(templatedParent != null); diff --git a/Perspex/Controls/Control.cs b/Perspex/Controls/Control.cs index e5dcb712b9..1781cdd79e 100644 --- a/Perspex/Controls/Control.cs +++ b/Perspex/Controls/Control.cs @@ -218,7 +218,7 @@ namespace Perspex.Controls } } - public TemplatedControl TemplatedParent + public ITemplatedControl TemplatedParent { get; internal set; diff --git a/Perspex/Controls/ITemplatedControl.cs b/Perspex/Controls/ITemplatedControl.cs new file mode 100644 index 0000000000..f46b808098 --- /dev/null +++ b/Perspex/Controls/ITemplatedControl.cs @@ -0,0 +1,12 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2014 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- + +namespace Perspex.Controls +{ + public interface ITemplatedControl + { + } +} diff --git a/Perspex/Controls/TemplatedControl.cs b/Perspex/Controls/TemplatedControl.cs index 2f32c793de..02cb9287ff 100644 --- a/Perspex/Controls/TemplatedControl.cs +++ b/Perspex/Controls/TemplatedControl.cs @@ -11,7 +11,7 @@ namespace Perspex.Controls using System.Linq; using Perspex.Media; - public abstract class TemplatedControl : Control + public abstract class TemplatedControl : Control, ITemplatedControl { public static readonly PerspexProperty TemplateProperty = PerspexProperty.Register("Template"); diff --git a/Perspex/Perspex.csproj b/Perspex/Perspex.csproj index 66d646050d..8f6c49131a 100644 --- a/Perspex/Perspex.csproj +++ b/Perspex/Perspex.csproj @@ -76,6 +76,7 @@ + diff --git a/Perspex/Styling/IStyleable.cs b/Perspex/Styling/IStyleable.cs index 3bd2eb1d33..2dc2a983cd 100644 --- a/Perspex/Styling/IStyleable.cs +++ b/Perspex/Styling/IStyleable.cs @@ -27,7 +27,7 @@ namespace Perspex.Styling /// /// Gets the template parent of this element if the control comes from a template. /// - TemplatedControl TemplatedParent { get; } + ITemplatedControl TemplatedParent { get; } /// /// Binds a to a style. diff --git a/Perspex/Styling/Selectors.cs b/Perspex/Styling/Selectors.cs index a0d4713c08..c13f8902b7 100644 --- a/Perspex/Styling/Selectors.cs +++ b/Perspex/Styling/Selectors.cs @@ -54,7 +54,7 @@ namespace Perspex.Styling return match; } - public static Match InTemplateOf(this Match match) where T : TemplatedControl + public static Match InTemplateOf(this Match match) where T : ITemplatedControl { Contract.Requires(match != null);