Browse Source

Display a bit more info about props in devtools.

pull/4/head
Steven Kirk 12 years ago
parent
commit
b93997c1b8
  1. 30
      Perspex.Base/Diagnostics/PerspexPropertyValue.cs
  2. 1
      Perspex.Base/Perspex.Base.csproj
  3. 38
      Perspex.Base/PerspexObject.cs
  4. 2
      Perspex.Base/PerspexProperty.cs
  5. 3
      Perspex.Controls/Grid.cs
  6. 16
      Perspex.Diagnostics/DevTools.cs
  7. 1
      Perspex.Diagnostics/Perspex.Diagnostics.csproj
  8. 6
      Perspex.Diagnostics/ViewModels/ControlDetails.cs
  9. 44
      Perspex.Diagnostics/ViewModels/PropertyDetails.cs

30
Perspex.Base/Diagnostics/PerspexPropertyValue.cs

@ -0,0 +1,30 @@
// -----------------------------------------------------------------------
// <copyright file="PerspexPropertyValue.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
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; }
}
}

1
Perspex.Base/Perspex.Base.csproj

@ -36,6 +36,7 @@
<ItemGroup>
<Compile Include="Binding.cs" />
<Compile Include="Contract.cs" />
<Compile Include="Diagnostics\PerspexPropertyValue.cs" />
<Compile Include="IDescription.cs" />
<Compile Include="PerspexListExtensions.cs" />
<Compile Include="IObservableDescription.cs" />

38
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;
/// <summary>
@ -379,6 +380,43 @@ namespace Perspex
return (T)this.GetValue((PerspexProperty)property);
}
public IEnumerable<PerspexPropertyValue> 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<PerspexProperty> GetRegisteredProperties()
{
Type type = this.GetType();
while (type != null)
{
List<PerspexProperty> list;
if (registered.TryGetValue(type, out list))
{
foreach (var p in list)
{
yield return p;
}
}
type = type.GetTypeInfo().BaseType;
}
}
/// <summary>
/// Gets all of the <see cref="PerspexProperty"/> values explicitly set on this object.
/// </summary>

2
Perspex.Base/PerspexProperty.cs

@ -150,7 +150,7 @@ namespace Perspex
Contract.Requires<NullReferenceException>(name != null);
PerspexProperty<TValue> result = new PerspexProperty<TValue>(
name,
typeof(TOwner) + "." + name,
typeof(TOwner),
defaultValue,
inherits,

3
Perspex.Controls/Grid.cs

@ -18,9 +18,6 @@ namespace Perspex.Controls
public static readonly PerspexProperty<int> ColumnSpanProperty =
PerspexProperty.RegisterAttached<Grid, Control, int>("ColumnSpan", 1);
public static readonly PerspexProperty<bool> IsSharedSizeScopeProperty =
PerspexProperty.RegisterAttached<Grid, Control, bool>("IsSharedSizeScopeProperty");
public static readonly PerspexProperty<int> RowProperty =
PerspexProperty.RegisterAttached<Grid, Control, int>("Row");

16
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<PropertyDetails>(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,
};
}

1
Perspex.Diagnostics/Perspex.Diagnostics.csproj

@ -69,6 +69,7 @@
<Compile Include="DevTools.cs" />
<Compile Include="Debug.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ViewModels\PropertyDetails.cs" />
<Compile Include="ViewModels\ControlDetails.cs" />
<Compile Include="ViewModels\VisualTreeNode.cs" />
</ItemGroup>

6
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<Tuple<string, object>> Properties
public IEnumerable<PropertyDetails> Properties
{
get;
private set;

44
Perspex.Diagnostics/ViewModels/PropertyDetails.cs

@ -0,0 +1,44 @@
// -----------------------------------------------------------------------
// <copyright file="PropertyDetails.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
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;
}
}
}
Loading…
Cancel
Save