Browse Source

Added a diagnostic to print the visual tree.

pull/4/head
Steven Kirk 12 years ago
parent
commit
37d29816fb
  1. 57
      Perspex/Diagnostics/Debug.cs
  2. 1
      Perspex/Perspex.csproj
  3. 14
      Perspex/PerspexObject.cs
  4. 21
      Perspex/PriorityValue.cs
  5. 2
      TestApplication/Program.cs

57
Perspex/Diagnostics/Debug.cs

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Perspex.Diagnostics
{
public static class Debug
{
public static string PrintVisualTree(IVisual visual)
{
StringBuilder result = new StringBuilder();
PrintVisualTree(visual, result, 0);
return result.ToString();
}
private static void PrintVisualTree(IVisual visual, StringBuilder builder, int indent)
{
builder.Append(Indent(indent - 1));
if (indent > 0)
{
builder.Append(" +- ");
}
builder.AppendLine(visual.GetType().Name);
PerspexObject p = visual as PerspexObject;
if (p != null)
{
foreach (var value in p.GetSetValues())
{
builder.Append(Indent(indent));
builder.Append(" | ");
builder.Append(value.Item1.Name);
builder.Append(" = ");
builder.Append(value.Item2);
builder.Append(" (");
builder.Append(value.Item3);
builder.AppendLine(")");
}
}
foreach (var child in visual.VisualChildren)
{
PrintVisualTree(child, builder, indent + 1);
}
}
private static string Indent(int indent)
{
return string.Join("", Enumerable.Repeat(" ", Math.Max(indent, 0)));
}
}
}

1
Perspex/Perspex.csproj

@ -94,6 +94,7 @@
<Compile Include="Controls\Panel.cs" /> <Compile Include="Controls\Panel.cs" />
<Compile Include="Controls\StackPanel.cs" /> <Compile Include="Controls\StackPanel.cs" />
<Compile Include="IHeadered.cs" /> <Compile Include="IHeadered.cs" />
<Compile Include="Diagnostics\Debug.cs" />
<Compile Include="Input\InputElement.cs" /> <Compile Include="Input\InputElement.cs" />
<Compile Include="Input\IFocusManager.cs" /> <Compile Include="Input\IFocusManager.cs" />
<Compile Include="Input\FocusManager.cs" /> <Compile Include="Input\FocusManager.cs" />

14
Perspex/PerspexObject.cs

@ -321,6 +321,20 @@ namespace Perspex
return (T)this.GetValue((PerspexProperty)property); return (T)this.GetValue((PerspexProperty)property);
} }
/// <summary>
/// Gets all of the <see cref="PerspexProperty"/> values explicitly set on this object.
/// </summary>
public IEnumerable<Tuple<PerspexProperty, object, BindingPriority>> GetSetValues()
{
foreach (var value in this.values)
{
yield return Tuple.Create(
value.Key,
value.Value.Value,
(BindingPriority)value.Value.ValuePriority);
}
}
/// <summary> /// <summary>
/// Checks whether a <see cref="PerspexProperty"/> is set on this object. /// Checks whether a <see cref="PerspexProperty"/> is set on this object.
/// </summary> /// </summary>

21
Perspex/PriorityValue.cs

@ -40,17 +40,13 @@ namespace Perspex
/// </summary> /// </summary>
private object value; private object value;
/// <summary>
/// The priority of the binding that is currently active.
/// </summary>
private int valuePriority = int.MaxValue;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PriorityValue"/> class. /// Initializes a new instance of the <see cref="PriorityValue"/> class.
/// </summary> /// </summary>
public PriorityValue() public PriorityValue()
{ {
this.value = PerspexProperty.UnsetValue; this.value = PerspexProperty.UnsetValue;
this.ValuePriority = int.MaxValue;
} }
/// <summary> /// <summary>
@ -69,6 +65,15 @@ namespace Perspex
get { return this.value; } get { return this.value; }
} }
/// <summary>
/// Gets the priority of the binding that is currently active.
/// </summary>
public int ValuePriority
{
get;
private set;
}
/// <summary> /// <summary>
/// Adds a new binding. /// Adds a new binding.
/// </summary> /// </summary>
@ -127,7 +132,7 @@ namespace Perspex
item = next; item = next;
} }
if (removed && priority <= this.valuePriority) if (removed && priority <= this.ValuePriority)
{ {
this.UpdateValue(); this.UpdateValue();
} }
@ -148,7 +153,7 @@ namespace Perspex
/// <param name="changed">The changed entry.</param> /// <param name="changed">The changed entry.</param>
private void EntryChanged(BindingEntry changed) private void EntryChanged(BindingEntry changed)
{ {
if (changed.Priority <= this.valuePriority) if (changed.Priority <= this.ValuePriority)
{ {
this.UpdateValue(); this.UpdateValue();
} }
@ -172,7 +177,7 @@ namespace Perspex
{ {
object old = this.value; object old = this.value;
this.valuePriority = priority; this.ValuePriority = priority;
if (!EqualityComparer<object>.Default.Equals(old, value)) if (!EqualityComparer<object>.Default.Equals(old, value))
{ {

2
TestApplication/Program.cs

@ -82,6 +82,8 @@ namespace TestApplication
} }
}; };
System.Console.WriteLine(Perspex.Diagnostics.Debug.PrintVisualTree(window));
window.Show(); window.Show();
Dispatcher.Run(); Dispatcher.Run();
} }

Loading…
Cancel
Save