Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Xamarin.PropertyEditing.Tests/Helpers.cs9
-rw-r--r--Xamarin.PropertyEditing.Tests/SolidBrushPropertyViewModelTests.cs23
-rw-r--r--Xamarin.PropertyEditing/Drawing/CommonSolidBrush.cs12
-rw-r--r--Xamarin.PropertyEditing/ISolidBrushPropertyInfo.cs10
-rw-r--r--Xamarin.PropertyEditing/Reflection/ReflectionObjectEditor.cs9
-rw-r--r--Xamarin.PropertyEditing/Reflection/ReflectionSolidBrushPropertyInfo.cs17
-rw-r--r--Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs3
-rw-r--r--Xamarin.PropertyEditing/ViewModels/SolidBrushPropertyViewModel.cs21
-rw-r--r--Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj3
9 files changed, 98 insertions, 9 deletions
diff --git a/Xamarin.PropertyEditing.Tests/Helpers.cs b/Xamarin.PropertyEditing.Tests/Helpers.cs
index ee27a91..738cac2 100644
--- a/Xamarin.PropertyEditing.Tests/Helpers.cs
+++ b/Xamarin.PropertyEditing.Tests/Helpers.cs
@@ -28,10 +28,13 @@ namespace Xamarin.PropertyEditing.Tests
static char GetConsonnant (this Random rand) => consonnants[rand.Next (0, vowels.Length)];
public static string NextFilename (this Random rand, string extension)
- => string.Concat(
- rand.GetConsonnant(), rand.GetVowel(),
+ => rand.NextString () + extension;
+
+ public static string NextString (this Random rand)
+ => string.Concat (
rand.GetConsonnant (), rand.GetVowel (),
rand.GetConsonnant (), rand.GetVowel (),
- extension);
+ rand.GetConsonnant (), rand.GetVowel ()
+ );
}
}
diff --git a/Xamarin.PropertyEditing.Tests/SolidBrushPropertyViewModelTests.cs b/Xamarin.PropertyEditing.Tests/SolidBrushPropertyViewModelTests.cs
index 5aeb7c3..2803278 100644
--- a/Xamarin.PropertyEditing.Tests/SolidBrushPropertyViewModelTests.cs
+++ b/Xamarin.PropertyEditing.Tests/SolidBrushPropertyViewModelTests.cs
@@ -1,6 +1,10 @@
using System;
using System.Drawing;
+using Moq;
+using NUnit.Framework;
+using NUnit.Framework.Constraints;
using Xamarin.PropertyEditing.Drawing;
+using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Tests
{
@@ -9,9 +13,26 @@ namespace Xamarin.PropertyEditing.Tests
protected override CommonBrush GetRandomTestValue (Random rand)
{
var color = rand.NextColor();
+ var colorSpace = rand.NextString ();
var opacity = rand.NextDouble ();
- return new CommonSolidBrush (color, opacity);
+ return new CommonSolidBrush (color, colorSpace, opacity);
+ }
+
+ static readonly string[] SampleColorSpaces = new[] {
+ "genericRGBLinear", "genericCMYK"
+ };
+
+ [Test]
+ public void ColorSpaces ()
+ {
+ var mockProperty = new Mock<ISolidBrushPropertyInfo> ();
+ mockProperty.SetupGet (pi => pi.Type).Returns (typeof (SolidBrush));
+ mockProperty.SetupGet (pi => pi.ColorSpaces).Returns (SampleColorSpaces);
+ var mockEditor = new Mock<IObjectEditor> ();
+
+ var vm = new SolidBrushPropertyViewModel(mockProperty.Object, new[] { mockEditor.Object });
+ Assert.That (vm.ColorSpaces, new CollectionEquivalentConstraint (SampleColorSpaces));
}
}
}
diff --git a/Xamarin.PropertyEditing/Drawing/CommonSolidBrush.cs b/Xamarin.PropertyEditing/Drawing/CommonSolidBrush.cs
index 7a5ba27..6feae7b 100644
--- a/Xamarin.PropertyEditing/Drawing/CommonSolidBrush.cs
+++ b/Xamarin.PropertyEditing/Drawing/CommonSolidBrush.cs
@@ -9,10 +9,11 @@ namespace Xamarin.PropertyEditing.Drawing
/// </summary>
public class CommonSolidBrush : CommonBrush, IEquatable<CommonSolidBrush>
{
- public CommonSolidBrush(Color color, double opacity = 1.0)
+ public CommonSolidBrush(Color color, string colorSpace = null, double opacity = 1.0)
: base(opacity)
{
Color = color;
+ ColorSpace = colorSpace;
}
/// <summary>
@@ -20,6 +21,11 @@ namespace Xamarin.PropertyEditing.Drawing
/// </summary>
public Color Color { get; }
+ /// <summary>
+ /// The color space the brush is defined in.
+ /// </summary>
+ public string ColorSpace { get; }
+
public override bool Equals (object obj)
{
var brush = obj as CommonSolidBrush;
@@ -30,7 +36,8 @@ namespace Xamarin.PropertyEditing.Drawing
public bool Equals (CommonSolidBrush other)
{
return other != null &&
- EqualityComparer<Color>.Default.Equals (Color, other.Color) &&
+ Color.Equals(other.Color) &&
+ ColorSpace == other.ColorSpace &&
Opacity == other.Opacity;
}
@@ -39,6 +46,7 @@ namespace Xamarin.PropertyEditing.Drawing
var hashCode = base.GetHashCode ();
unchecked {
hashCode = hashCode * -1521134295 + Color.GetHashCode ();
+ hashCode = hashCode * -1521134295 + ColorSpace.GetHashCode ();
}
return hashCode;
}
diff --git a/Xamarin.PropertyEditing/ISolidBrushPropertyInfo.cs b/Xamarin.PropertyEditing/ISolidBrushPropertyInfo.cs
new file mode 100644
index 0000000..c797459
--- /dev/null
+++ b/Xamarin.PropertyEditing/ISolidBrushPropertyInfo.cs
@@ -0,0 +1,10 @@
+using System.Collections.Generic;
+
+namespace Xamarin.PropertyEditing
+{
+ // TODO: Add support for predefined color values
+ public interface ISolidBrushPropertyInfo : IPropertyInfo
+ {
+ IReadOnlyList<string> ColorSpaces { get; }
+ }
+}
diff --git a/Xamarin.PropertyEditing/Reflection/ReflectionObjectEditor.cs b/Xamarin.PropertyEditing/Reflection/ReflectionObjectEditor.cs
index 67123f7..56e946a 100644
--- a/Xamarin.PropertyEditing/Reflection/ReflectionObjectEditor.cs
+++ b/Xamarin.PropertyEditing/Reflection/ReflectionObjectEditor.cs
@@ -1,9 +1,10 @@
-using System;
+using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Linq;
using System.Threading.Tasks;
+using System.Drawing;
namespace Xamarin.PropertyEditing.Reflection
{
@@ -27,7 +28,11 @@ namespace Xamarin.PropertyEditing.Reflection
if (CheckAvailability (property)) {
if (property.PropertyType.IsEnum) {
this.properties.Add ((ReflectionPropertyInfo)Activator.CreateInstance (typeof(ReflectionEnumPropertyInfo<>).MakeGenericType (Enum.GetUnderlyingType (property.PropertyType)), property));
- } else
+ } else if (typeof (SolidBrush).IsAssignableFrom(property.PropertyType)) {
+ // Note: this only supports `System.Drawing`'s `SolidBrush` for now. Do we need more for the reflection model?
+ this.properties.Add (new ReflectionSolidBrushPropertyInfo (property));
+ }
+ else
this.properties.Add (new ReflectionPropertyInfo (property));
}
}
diff --git a/Xamarin.PropertyEditing/Reflection/ReflectionSolidBrushPropertyInfo.cs b/Xamarin.PropertyEditing/Reflection/ReflectionSolidBrushPropertyInfo.cs
new file mode 100644
index 0000000..6bc94b2
--- /dev/null
+++ b/Xamarin.PropertyEditing/Reflection/ReflectionSolidBrushPropertyInfo.cs
@@ -0,0 +1,17 @@
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+
+namespace Xamarin.PropertyEditing.Reflection
+{
+ public class ReflectionSolidBrushPropertyInfo : ReflectionPropertyInfo, ISolidBrushPropertyInfo
+ {
+ public ReflectionSolidBrushPropertyInfo (PropertyInfo propertyInfo, IEnumerable<string> colorSpaces = null)
+ : base (propertyInfo)
+ {
+ ColorSpaces = colorSpaces.ToArray();
+ }
+
+ public IReadOnlyList<string> ColorSpaces { get; }
+ }
+}
diff --git a/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs b/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs
index 1819e91..d5a9733 100644
--- a/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs
+++ b/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -429,6 +429,7 @@ namespace Xamarin.PropertyEditing.ViewModels
{ typeof(Point), (p,e) => new PropertyViewModel<Point> (p, e) },
{ typeof(Size), (p,e) => new PropertyViewModel<Size> (p, e) },
{ typeof(Rectangle), (p,e) => new PropertyViewModel<Rectangle> (p, e) },
+ { typeof(CommonSolidBrush), (p, e) => new SolidBrushPropertyViewModel(p, e) },
{ typeof(CommonBrush), (p, e) => new BrushPropertyViewModel(p, e) },
};
}
diff --git a/Xamarin.PropertyEditing/ViewModels/SolidBrushPropertyViewModel.cs b/Xamarin.PropertyEditing/ViewModels/SolidBrushPropertyViewModel.cs
new file mode 100644
index 0000000..c592369
--- /dev/null
+++ b/Xamarin.PropertyEditing/ViewModels/SolidBrushPropertyViewModel.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using Xamarin.PropertyEditing.Drawing;
+
+namespace Xamarin.PropertyEditing.ViewModels
+{
+ internal class SolidBrushPropertyViewModel : PropertyViewModel<CommonSolidBrush>
+ {
+ public SolidBrushPropertyViewModel(IPropertyInfo property, IEnumerable<IObjectEditor> editors)
+ : base(property, editors)
+ {
+ var solidBrushPropertyInfo = property as ISolidBrushPropertyInfo;
+ if (solidBrushPropertyInfo == null)
+ throw new ArgumentException ("Property doesn't implement ISolidBrushPropertyInfo", nameof (property));
+
+ ColorSpaces = solidBrushPropertyInfo.ColorSpaces;
+ }
+
+ public IReadOnlyList<string> ColorSpaces { get; }
+ }
+}
diff --git a/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj b/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj
index 5cabafe..abcac8f 100644
--- a/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj
+++ b/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj
@@ -70,6 +70,7 @@
<Compile Include="IPropertyInfo.cs" />
<Compile Include="IResourceProvider.cs" />
<Compile Include="ISelfConstrainedPropertyInfo.cs" />
+ <Compile Include="ISolidBrushPropertyInfo.cs" />
<Compile Include="NotifyingObject.cs" />
<Compile Include="ObservableCollectionEx.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -81,6 +82,7 @@
</Compile>
<Compile Include="PropertyVariation.cs" />
<Compile Include="Reflection\ReflectionEditorProvider.cs" />
+ <Compile Include="Reflection\ReflectionSolidBrushPropertyInfo.cs" />
<Compile Include="Reflection\ReflectionEnumPropertyInfo.cs" />
<Compile Include="Reflection\ReflectionEventInfo.cs" />
<Compile Include="Reflection\ReflectionObjectEditor.cs" />
@@ -101,6 +103,7 @@
<Compile Include="ViewModels\PropertiesViewModel.cs" />
<Compile Include="ViewModels\PropertyViewModel.cs" />
<Compile Include="ViewModels\RelayCommand.cs" />
+ <Compile Include="ViewModels\SolidBrushPropertyViewModel.cs" />
<Compile Include="ViewModels\StringPropertyViewModel.cs" />
<Compile Include="PropertyArrangeMode.cs" />
<Compile Include="IGroupingList.cs" />