Skip to content

Commit

Permalink
Silverlight? No Move for you!
Browse files Browse the repository at this point in the history
  • Loading branch information
niik committed Jun 25, 2013
1 parent fb7300d commit 7224331
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ReactiveUI/ReactiveCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ protected void RemoveItem(int index)
if (ChangeTrackingEnabled) removeItemFromPropertyTracking(item);
}

#if !SILVERLIGHT
protected void MoveItem(int oldIndex, int newIndex)
{
var item = _inner[oldIndex];
Expand All @@ -186,7 +187,7 @@ protected void MoveItem(int oldIndex, int newIndex)

_changed.OnNext(ea);
}

#endif
protected void SetItem(int index, T item)
{
if (_suppressionRefCount > 0) {
Expand Down Expand Up @@ -559,10 +560,12 @@ public virtual void RemoveAt(int index)
RemoveItem(index);
}

#if !SILVERLIGHT
public virtual void Move(int oldIndex, int newIndex)
{
MoveItem(oldIndex, newIndex);
}
#endif

public virtual T this[int index] {
get { return _inner[index]; }
Expand Down
9 changes: 9 additions & 0 deletions ReactiveUI/ReactiveCollectionMixins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ protected virtual void internalRemoveAt(int index)
base.RemoveAt(index);
}

#if !SILVERLIGHT
public override void Move(int oldIndex, int newIndex)
{
throw new InvalidOperationException(readonlyExceptionMessage);
Expand All @@ -113,6 +114,7 @@ protected virtual void internalMove(int oldIndex, int newIndex)
{
base.Move(oldIndex, newIndex);
}
#endif

public override void RemoveRange(int index, int count)
{
Expand Down Expand Up @@ -288,6 +290,7 @@ void onItemChanged(TSource changedItem)
internalReplace(destinationIndex, newItem);
}
} else {
#if !SILVERLIGHT
// The change is forcing us to reorder. We'll use a move operation if the item hasn't
// changed (ie it's the same object) and we'll implement it as a remove and add if the
// object has changed (ie the selector is not an identity function).
Expand All @@ -313,6 +316,10 @@ void onItemChanged(TSource changedItem)
internalRemoveAt(destinationIndex);
internalInsertAndMap(sourceIndex, newItem);
}
#else
internalRemoveAt(destinationIndex);
internalInsertAndMap(sourceIndex, newItem);
#endif
}
}
}
Expand Down Expand Up @@ -388,6 +395,7 @@ void onSourceCollectionChanged(NotifyCollectionChangedEventArgs args)
return;
}

#if !SILVERLIGHT
if (args.Action == NotifyCollectionChangedAction.Move) {
Debug.Assert(args.OldItems.Count == 1);
Debug.Assert(args.NewItems.Count == 1);
Expand Down Expand Up @@ -435,6 +443,7 @@ void onSourceCollectionChanged(NotifyCollectionChangedEventArgs args)

return;
}
#endif

if (args.OldItems != null) {

Expand Down

0 comments on commit 7224331

Please sign in to comment.