Browse Source

Removed PerspexReadOnlyListView<T>

I can't see why it was needed, just assigning the control's logical
child to the presenter's should work? No? Doesn't seem like it breaks
anything....
pull/58/head
Steven Kirk 11 years ago
parent
commit
0359f8c9a3
  1. 128
      Perspex.Base/Collections/PerspexReadOnlyListView.cs
  2. 8
      Perspex.Controls/ContentControl.cs
  3. 4
      Perspex.Controls/DropDown.cs
  4. 5
      Perspex.Controls/TabControl.cs

128
Perspex.Base/Collections/PerspexReadOnlyListView.cs

@ -13,134 +13,6 @@ namespace Perspex.Collections
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
public class PerspexReadOnlyListView<T> : IPerspexReadOnlyList<T>, IDisposable
{
private IPerspexReadOnlyList<T> source;
public PerspexReadOnlyListView()
: this(null)
{
}
public PerspexReadOnlyListView(IPerspexReadOnlyList<T> source)
{
this.source = source;
if (source != null)
{
this.source.CollectionChanged += this.SourceCollectionChanged;
}
}
public event NotifyCollectionChangedEventHandler CollectionChanged;
public event PropertyChangedEventHandler PropertyChanged;
public int Count
{
get { return this.source?.Count ?? 0; }
}
public IPerspexReadOnlyList<T> Source
{
get
{
return this.source;
}
set
{
if (this.source != null)
{
this.source.CollectionChanged -= this.SourceCollectionChanged;
if (this.CollectionChanged != null)
{
var ev = new NotifyCollectionChangedEventArgs(
NotifyCollectionChangedAction.Remove,
this.source,
0);
this.CollectionChanged(this, ev);
}
}
this.source = value;
if (this.source != null)
{
this.source.CollectionChanged += this.SourceCollectionChanged;
if (this.CollectionChanged != null)
{
var ev = new NotifyCollectionChangedEventArgs(
NotifyCollectionChangedAction.Add,
this.source.ToList(),
0);
this.CollectionChanged(this, ev);
}
}
}
}
public T this[int index]
{
get { return this.source[index]; }
}
public void Dispose()
{
this.source.CollectionChanged -= this.SourceCollectionChanged;
}
public IEnumerator<T> GetEnumerator()
{
return (this.source != null) ?
this.source.GetEnumerator() :
Enumerable.Empty<T>().GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
private void SourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (this.CollectionChanged != null)
{
NotifyCollectionChangedEventArgs ev;
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
ev = new NotifyCollectionChangedEventArgs(
NotifyCollectionChangedAction.Add,
e.NewItems,
e.NewStartingIndex);
break;
case NotifyCollectionChangedAction.Remove:
ev = new NotifyCollectionChangedEventArgs(
NotifyCollectionChangedAction.Remove,
e.OldItems,
e.OldStartingIndex);
break;
case NotifyCollectionChangedAction.Replace:
ev = new NotifyCollectionChangedEventArgs(
NotifyCollectionChangedAction.Replace,
e.NewItems,
e.OldItems,
e.OldStartingIndex);
break;
default:
throw new NotSupportedException("Action not yet implemented.");
}
this.CollectionChanged(this, ev);
}
}
}
public class PerspexReadOnlyListView<TIn, TOut> : IPerspexReadOnlyList<TOut>, IDisposable public class PerspexReadOnlyListView<TIn, TOut> : IPerspexReadOnlyList<TOut>, IDisposable
{ {
private IPerspexReadOnlyList<TIn> source; private IPerspexReadOnlyList<TIn> source;

8
Perspex.Controls/ContentControl.cs

@ -24,7 +24,7 @@ namespace Perspex.Controls
public static readonly PerspexProperty<VerticalAlignment> VerticalContentAlignmentProperty = public static readonly PerspexProperty<VerticalAlignment> VerticalContentAlignmentProperty =
PerspexProperty.Register<ContentControl, VerticalAlignment>("VerticalContentAlignment"); PerspexProperty.Register<ContentControl, VerticalAlignment>("VerticalContentAlignment");
private PerspexReadOnlyListView<ILogical> logicalChildren = new PerspexReadOnlyListView<ILogical>(); private IPerspexReadOnlyList<ILogical> logicalChildren = new PerspexList<ILogical>();
public ContentControl() public ContentControl()
{ {
@ -63,11 +63,7 @@ namespace Perspex.Controls
if (presenter != null) if (presenter != null)
{ {
this.logicalChildren.Source = ((ILogical)presenter).LogicalChildren; this.logicalChildren = ((ILogical)presenter)?.LogicalChildren;
}
else
{
this.logicalChildren.Source = null;
} }
} }

4
Perspex.Controls/DropDown.cs

@ -28,7 +28,7 @@ namespace Perspex.Controls
public static readonly PerspexProperty<bool> IsDropDownOpenProperty = public static readonly PerspexProperty<bool> IsDropDownOpenProperty =
PerspexProperty.Register<DropDown, bool>("IsDropDownOpen"); PerspexProperty.Register<DropDown, bool>("IsDropDownOpen");
private PerspexReadOnlyListView<ILogical> logicalChildren = new PerspexReadOnlyListView<ILogical>(); private IPerspexReadOnlyList<ILogical> logicalChildren = new PerspexSingleItemList<ILogical>();
public DropDown() public DropDown()
{ {
@ -77,7 +77,7 @@ namespace Perspex.Controls
{ {
var container = this.GetTemplateChild<Panel>("container"); var container = this.GetTemplateChild<Panel>("container");
((IItemsPanel)container).ChildLogicalParent = this; ((IItemsPanel)container).ChildLogicalParent = this;
this.logicalChildren.Source = ((ILogical)container).LogicalChildren; this.logicalChildren = ((ILogical)container).LogicalChildren;
} }
private void SetContentParent(Tuple<object, object> change) private void SetContentParent(Tuple<object, object> change)

5
Perspex.Controls/TabControl.cs

@ -25,8 +25,7 @@ namespace Perspex.Controls
public static readonly PerspexProperty<IPageTransition> TransitionProperty = public static readonly PerspexProperty<IPageTransition> TransitionProperty =
Deck.TransitionProperty.AddOwner<TabControl>(); Deck.TransitionProperty.AddOwner<TabControl>();
private PerspexReadOnlyListView<ILogical> logicalChildren = private IPerspexReadOnlyList<ILogical> logicalChildren = new PerspexSingleItemList<ILogical>();
new PerspexReadOnlyListView<ILogical>();
static TabControl() static TabControl()
{ {
@ -81,7 +80,7 @@ namespace Perspex.Controls
base.OnTemplateApplied(); base.OnTemplateApplied();
this.deck = this.GetTemplateChild<Deck>("deck"); this.deck = this.GetTemplateChild<Deck>("deck");
this.logicalChildren.Source = ((ILogical)deck).LogicalChildren; this.logicalChildren = ((ILogical)deck).LogicalChildren;
} }
} }
} }

Loading…
Cancel
Save