From b93997c1b8a3dd7bf3ac7b6f8fdab68e987782cc Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Fri, 3 Oct 2014 13:26:29 +0200 Subject: [PATCH] Display a bit more info about props in devtools. --- .../Diagnostics/PerspexPropertyValue.cs | 30 +++++++++++++ Perspex.Base/Perspex.Base.csproj | 1 + Perspex.Base/PerspexObject.cs | 38 ++++++++++++++++ Perspex.Base/PerspexProperty.cs | 2 +- Perspex.Controls/Grid.cs | 3 -- Perspex.Diagnostics/DevTools.cs | 16 +++++++ .../Perspex.Diagnostics.csproj | 1 + .../ViewModels/ControlDetails.cs | 6 +-- .../ViewModels/PropertyDetails.cs | 44 +++++++++++++++++++ 9 files changed, 133 insertions(+), 8 deletions(-) create mode 100644 Perspex.Base/Diagnostics/PerspexPropertyValue.cs create mode 100644 Perspex.Diagnostics/ViewModels/PropertyDetails.cs diff --git a/Perspex.Base/Diagnostics/PerspexPropertyValue.cs b/Perspex.Base/Diagnostics/PerspexPropertyValue.cs new file mode 100644 index 0000000000..ac82fce932 --- /dev/null +++ b/Perspex.Base/Diagnostics/PerspexPropertyValue.cs @@ -0,0 +1,30 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2014 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- + +namespace Perspex.Diagnostics +{ + public class PerspexPropertyValue + { + public PerspexPropertyValue(PerspexProperty property, object value) + { + this.Property = property; + this.CurrentValue = value; + } + + public PerspexPropertyValue(PerspexProperty property, PriorityValue priorityValue) + { + this.Property = property; + this.CurrentValue = priorityValue.Value; + this.PriorityValue = priorityValue; + } + + public PerspexProperty Property { get; private set; } + + public object CurrentValue { get; private set; } + + public PriorityValue PriorityValue { get; private set; } + } +} diff --git a/Perspex.Base/Perspex.Base.csproj b/Perspex.Base/Perspex.Base.csproj index 2cb1dd0369..b302c49aef 100644 --- a/Perspex.Base/Perspex.Base.csproj +++ b/Perspex.Base/Perspex.Base.csproj @@ -36,6 +36,7 @@ + diff --git a/Perspex.Base/PerspexObject.cs b/Perspex.Base/PerspexObject.cs index b5febbdbdd..be12367034 100644 --- a/Perspex.Base/PerspexObject.cs +++ b/Perspex.Base/PerspexObject.cs @@ -12,6 +12,7 @@ namespace Perspex using System.Linq; using System.Reactive.Linq; using System.Reflection; + using Perspex.Diagnostics; using Splat; /// @@ -379,6 +380,43 @@ namespace Perspex return (T)this.GetValue((PerspexProperty)property); } + public IEnumerable GetAllValues() + { + foreach (PerspexProperty property in this.GetRegisteredProperties()) + { + PriorityValue value; + + if (this.values.TryGetValue(property, out value)) + { + yield return new PerspexPropertyValue(property, value); + } + else + { + yield return new PerspexPropertyValue(property, this.GetValue(property)); + } + } + } + + public IEnumerable GetRegisteredProperties() + { + Type type = this.GetType(); + + while (type != null) + { + List list; + + if (registered.TryGetValue(type, out list)) + { + foreach (var p in list) + { + yield return p; + } + } + + type = type.GetTypeInfo().BaseType; + } + } + /// /// Gets all of the values explicitly set on this object. /// diff --git a/Perspex.Base/PerspexProperty.cs b/Perspex.Base/PerspexProperty.cs index 05828ad6f9..da1526c4be 100644 --- a/Perspex.Base/PerspexProperty.cs +++ b/Perspex.Base/PerspexProperty.cs @@ -150,7 +150,7 @@ namespace Perspex Contract.Requires(name != null); PerspexProperty result = new PerspexProperty( - name, + typeof(TOwner) + "." + name, typeof(TOwner), defaultValue, inherits, diff --git a/Perspex.Controls/Grid.cs b/Perspex.Controls/Grid.cs index 617cc50982..650a323d57 100644 --- a/Perspex.Controls/Grid.cs +++ b/Perspex.Controls/Grid.cs @@ -18,9 +18,6 @@ namespace Perspex.Controls public static readonly PerspexProperty ColumnSpanProperty = PerspexProperty.RegisterAttached("ColumnSpan", 1); - public static readonly PerspexProperty IsSharedSizeScopeProperty = - PerspexProperty.RegisterAttached("IsSharedSizeScopeProperty"); - public static readonly PerspexProperty RowProperty = PerspexProperty.RegisterAttached("Row"); diff --git a/Perspex.Diagnostics/DevTools.cs b/Perspex.Diagnostics/DevTools.cs index 17f35f08a2..5cd0e2e60d 100644 --- a/Perspex.Diagnostics/DevTools.cs +++ b/Perspex.Diagnostics/DevTools.cs @@ -9,6 +9,7 @@ namespace Perspex.Diagnostics using Perspex.Controls; using System.Reactive.Linq; using Perspex.Diagnostics.ViewModels; + using System; public class DevTools : Decorator { @@ -82,6 +83,21 @@ namespace Perspex.Diagnostics { return new ItemsControl { + DataTemplates = new DataTemplates + { + new DataTemplate(x => + new StackPanel + { + Gap = 16, + Orientation = Orientation.Horizontal, + Children = new Controls + { + new TextBlock { Text = x.Name }, + new TextBlock { Text = Convert.ToString(x.Value) }, + new TextBlock { Text = x.Priority }, + }, + }), + }, Items = i.Properties, }; } diff --git a/Perspex.Diagnostics/Perspex.Diagnostics.csproj b/Perspex.Diagnostics/Perspex.Diagnostics.csproj index 8c39f8cd8c..d57d5f7da3 100644 --- a/Perspex.Diagnostics/Perspex.Diagnostics.csproj +++ b/Perspex.Diagnostics/Perspex.Diagnostics.csproj @@ -69,6 +69,7 @@ + diff --git a/Perspex.Diagnostics/ViewModels/ControlDetails.cs b/Perspex.Diagnostics/ViewModels/ControlDetails.cs index 0dd3cfaf77..bd4829b593 100644 --- a/Perspex.Diagnostics/ViewModels/ControlDetails.cs +++ b/Perspex.Diagnostics/ViewModels/ControlDetails.cs @@ -6,10 +6,8 @@ namespace Perspex.Diagnostics.ViewModels { - using System; using System.Collections.Generic; using System.Linq; - using Perspex.Controls; using ReactiveUI; internal class ControlDetails : ReactiveObject @@ -20,11 +18,11 @@ namespace Perspex.Diagnostics.ViewModels if (po != null) { - this.Properties = po.GetSetValues().Select(x => Tuple.Create(x.Item1.Name, x.Item2)); + this.Properties = po.GetAllValues().Select(x => new PropertyDetails(x)); } } - public IEnumerable> Properties + public IEnumerable Properties { get; private set; diff --git a/Perspex.Diagnostics/ViewModels/PropertyDetails.cs b/Perspex.Diagnostics/ViewModels/PropertyDetails.cs new file mode 100644 index 0000000000..8dc3284e57 --- /dev/null +++ b/Perspex.Diagnostics/ViewModels/PropertyDetails.cs @@ -0,0 +1,44 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2014 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- + +namespace Perspex.Diagnostics.ViewModels +{ + using System; + using System.Collections.Generic; + using System.Linq; + using Perspex.Controls; + using ReactiveUI; + + internal class PropertyDetails : ReactiveObject + { + public PropertyDetails(PerspexPropertyValue value) + { + this.Name = value.Property.Name; + this.Value = value.CurrentValue; + this.Priority = (value.PriorityValue != null) ? + Enum.GetName(typeof(BindingPriority), value.PriorityValue.ValuePriority) : + value.Property.Inherits ? "Inherited" : "Unset"; + } + + public string Name + { + get; + private set; + } + + public object Value + { + get; + private set; + } + + public string Priority + { + get; + private set; + } + } +}