diff --git a/Perspex.Base/PerspexList.cs b/Perspex.Base/PerspexList.cs index 80fdaeb37d..d0e975427c 100644 --- a/Perspex.Base/PerspexList.cs +++ b/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 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(); - 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 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 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); } diff --git a/Perspex.Diagnostics/DevTools.cs b/Perspex.Diagnostics/DevTools.cs index dcdb030ef6..0fa9c56ca1 100644 --- a/Perspex.Diagnostics/DevTools.cs +++ b/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(GetHeader, x => x.VisualChildren), + new TreeDataTemplate(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; } diff --git a/Perspex.Diagnostics/Perspex.Diagnostics.csproj b/Perspex.Diagnostics/Perspex.Diagnostics.csproj index ed7c41e824..d90cf13d74 100644 --- a/Perspex.Diagnostics/Perspex.Diagnostics.csproj +++ b/Perspex.Diagnostics/Perspex.Diagnostics.csproj @@ -69,8 +69,12 @@ + + + ..\packages\reactiveui-core.6.0.7\lib\Portable-Net45+Win8+WP8+WPA81\ReactiveUI.dll + ..\packages\Splat.1.5.0\lib\Portable-net45+win+wpa81+wp80\Splat.dll diff --git a/Perspex.Diagnostics/ViewModels/VisualTreeNode.cs b/Perspex.Diagnostics/ViewModels/VisualTreeNode.cs new file mode 100644 index 0000000000..43238c1c48 --- /dev/null +++ b/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 Children { get; private set; } + + public string Type { get; private set; } + } +} diff --git a/Perspex.Diagnostics/packages.config b/Perspex.Diagnostics/packages.config index e99a951913..feccef7220 100644 --- a/Perspex.Diagnostics/packages.config +++ b/Perspex.Diagnostics/packages.config @@ -1,5 +1,7 @@  + + diff --git a/TestApplication/TestApplication.csproj b/TestApplication/TestApplication.csproj index 5712670957..35a86bae38 100644 --- a/TestApplication/TestApplication.csproj +++ b/TestApplication/TestApplication.csproj @@ -36,6 +36,10 @@ + + False + ..\packages\reactiveui-core.6.0.7\lib\Net45\ReactiveUI.dll + False $(SharpDXPackageBinDir)\SharpDX.dll @@ -71,12 +75,16 @@ False ..\packages\Rx-PlatformServices.2.2.5\lib\net45\System.Reactive.PlatformServices.dll + + ..\packages\Rx-XAML.2.2.5\lib\net45\System.Reactive.Windows.Threading.dll + + diff --git a/TestApplication/packages.config b/TestApplication/packages.config index b24375491e..ab650ab5ac 100644 --- a/TestApplication/packages.config +++ b/TestApplication/packages.config @@ -1,10 +1,13 @@  + + +