Browse Source

Use ReactiveUI for DevTools.

Not sure we want a dep on ReactiveUI but for now works as a integration
test with it...
pull/4/head
Steven Kirk 12 years ago
parent
commit
cedb55fcdc
  1. 41
      Perspex.Base/PerspexList.cs
  2. 28
      Perspex.Diagnostics/DevTools.cs
  3. 4
      Perspex.Diagnostics/Perspex.Diagnostics.csproj
  4. 22
      Perspex.Diagnostics/ViewModels/VisualTreeNode.cs
  5. 2
      Perspex.Diagnostics/packages.config
  6. 8
      TestApplication/TestApplication.csproj
  7. 3
      TestApplication/packages.config

41
Perspex.Base/PerspexList.cs

@ -100,21 +100,21 @@ namespace Perspex
{
int index = this.inner.Count;
this.inner.Add(item);
this.NotifyAdd(new[] { item });
this.NotifyAdd(new[] { item }, index);
}
public void AddRange(IEnumerable<T> items)
{
int index = this.inner.Count;
this.inner.AddRange(items);
this.NotifyAdd((items as IList) ?? items.ToList());
this.NotifyAdd((items as IList) ?? items.ToList(), index);
}
public void Clear()
{
var old = this.inner;
this.inner = new List<T>();
this.NotifyRemove(old);
this.NotifyRemove(old, 0);
}
public bool Contains(T item)
@ -140,20 +140,27 @@ namespace Perspex
public void Insert(int index, T item)
{
this.inner.Insert(index, item);
this.NotifyAdd(new[] { item });
this.NotifyAdd(new[] { item }, index);
}
public void InsertRange(int index, IEnumerable<T> items)
{
this.inner.InsertRange(index, items);
this.NotifyAdd((items as IList) ?? items.ToList());
this.NotifyAdd((items as IList) ?? items.ToList(), index);
}
public bool Remove(T item)
{
bool result = this.inner.Remove(item);
this.NotifyRemove(new[] { item });
return result;
int index = this.inner.IndexOf(item);
if (index != -1)
{
this.inner.RemoveAt(index);
this.NotifyRemove(new[] { item }, index);
return true;
}
return false;
}
public void RemoveAll(IEnumerable<T> items)
@ -162,20 +169,16 @@ namespace Perspex
foreach (var i in items)
{
if (this.inner.Remove(i))
{
removed.Add(i);
}
// TODO: Optimize to only send as many notifications as necessary.
this.Remove(i);
}
this.NotifyRemove(removed);
}
public void RemoveAt(int index)
{
T item = this.inner[index];
this.inner.RemoveAt(index);
this.NotifyRemove(new[] { item });
this.NotifyRemove(new[] { item }, index);
}
int IList.Add(object value)
@ -225,11 +228,11 @@ namespace Perspex
return this.inner.GetEnumerator();
}
private void NotifyAdd(IList t)
private void NotifyAdd(IList t, int index)
{
if (this.CollectionChanged != null)
{
var e = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, t);
var e = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, t, index);
this.CollectionChanged(this, e);
}
@ -244,11 +247,11 @@ namespace Perspex
}
}
private void NotifyRemove(IList t)
private void NotifyRemove(IList t, int index)
{
if (this.CollectionChanged != null)
{
var e = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, t);
var e = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, t, index);
this.CollectionChanged(this, e);
}

28
Perspex.Diagnostics/DevTools.cs

@ -8,6 +8,7 @@ namespace Perspex.Diagnostics
{
using Perspex.Controls;
using System.Reactive.Linq;
using Perspex.Diagnostics.ViewModels;
public class DevTools : Decorator
{
@ -29,9 +30,19 @@ namespace Perspex.Diagnostics
{
DataTemplates = new DataTemplates
{
new TreeDataTemplate<IVisual>(GetHeader, x => x.VisualChildren),
new TreeDataTemplate<VisualTreeNode>(GetHeader, x => x.Children),
},
[!TreeView.ItemsProperty] = this[!DevTools.RootProperty].Select(x => new[] { x }),
[!TreeView.ItemsProperty] = this[!DevTools.RootProperty].Select(x =>
{
if (x != null)
{
return new[] { new VisualTreeNode((IVisual)x) };
}
else
{
return null;
}
}),
}
}
};
@ -43,16 +54,15 @@ namespace Perspex.Diagnostics
set { this.SetValue(RootProperty, value); }
}
private static Control GetHeader(IVisual visual)
private static Control GetHeader(VisualTreeNode node)
{
Control control = visual as Control;
TextBlock result = new TextBlock();
result.Text = visual.GetType().Name;
result.Text = node.Type;
if (control != null && control.TemplatedParent != null)
{
result.FontStyle = Media.FontStyle.Italic;
}
//if (control != null && control.TemplatedParent != null)
//{
// result.FontStyle = Media.FontStyle.Italic;
//}
return result;
}

4
Perspex.Diagnostics/Perspex.Diagnostics.csproj

@ -69,8 +69,12 @@
<Compile Include="DevTools.cs" />
<Compile Include="Debug.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ViewModels\VisualTreeNode.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="ReactiveUI">
<HintPath>..\packages\reactiveui-core.6.0.7\lib\Portable-Net45+Win8+WP8+WPA81\ReactiveUI.dll</HintPath>
</Reference>
<Reference Include="Splat">
<HintPath>..\packages\Splat.1.5.0\lib\Portable-net45+win+wpa81+wp80\Splat.dll</HintPath>
</Reference>

22
Perspex.Diagnostics/ViewModels/VisualTreeNode.cs

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ReactiveUI;
namespace Perspex.Diagnostics.ViewModels
{
internal class VisualTreeNode : ReactiveObject
{
public VisualTreeNode(IVisual visual)
{
this.Children = visual.VisualChildren.CreateDerivedCollection(x => new VisualTreeNode(x));
this.Type = visual.GetType().Name;
}
public IReactiveDerivedList<VisualTreeNode> Children { get; private set; }
public string Type { get; private set; }
}
}

2
Perspex.Diagnostics/packages.config

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="reactiveui" version="6.0.7" targetFramework="portable-net45+win" />
<package id="reactiveui-core" version="6.0.7" targetFramework="portable-net45+win" />
<package id="Rx-Core" version="2.2.5" targetFramework="portable-net45+win" />
<package id="Rx-Interfaces" version="2.2.5" targetFramework="portable-net45+win" />
<package id="Rx-Linq" version="2.2.5" targetFramework="portable-net45+win" />

8
TestApplication/TestApplication.csproj

@ -36,6 +36,10 @@
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="ReactiveUI, Version=6.0.7.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\reactiveui-core.6.0.7\lib\Net45\ReactiveUI.dll</HintPath>
</Reference>
<Reference Include="SharpDX, Version=2.6.2.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(SharpDXPackageBinDir)\SharpDX.dll</HintPath>
@ -71,12 +75,16 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Rx-PlatformServices.2.2.5\lib\net45\System.Reactive.PlatformServices.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.Windows.Threading">
<HintPath>..\packages\Rx-XAML.2.2.5\lib\net45\System.Reactive.Windows.Threading.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="App.cs" />

3
TestApplication/packages.config

@ -1,10 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="reactiveui" version="6.0.7" targetFramework="net45" />
<package id="reactiveui-core" version="6.0.7" targetFramework="net45" />
<package id="Rx-Core" version="2.2.5" targetFramework="net45" />
<package id="Rx-Interfaces" version="2.2.5" targetFramework="net45" />
<package id="Rx-Linq" version="2.2.5" targetFramework="net45" />
<package id="Rx-Main" version="2.2.5" targetFramework="net45" />
<package id="Rx-PlatformServices" version="2.2.5" targetFramework="net45" />
<package id="Rx-XAML" version="2.2.5" targetFramework="net45" />
<package id="SharpDX" version="2.6.2" targetFramework="net45" />
<package id="SharpDX.Direct2D1" version="2.6.2" targetFramework="net45" />
<package id="SharpDX.DXGI" version="2.6.2" targetFramework="net45" />

Loading…
Cancel
Save