// Toggles an item's completion state and moves the item to the appropriate index. The normalized from/to indexes are returned in the AAPLListOperationInfo struct. public ListOperationInfo ToggleItem(ListItem item, int preferredDestinationIndex) { int fromIndex = items.IndexOf(item); if (fromIndex == -1) { throw new InvalidProgramException("Toggling an item that isn't in the list is undefined."); } items.RemoveAt(fromIndex); item.IsComplete = !item.IsComplete; int toIndex = preferredDestinationIndex; if (toIndex == -1) { toIndex = item.IsComplete ? Count : IndexOfFirstCompletedItem(); } items.Insert(toIndex, item); var toggleInfo = new ListOperationInfo { FromIndex = fromIndex, ToIndex = toIndex }; return(toggleInfo); }
public ListOperationInfo MoveItem(ListItem item, int toIndex) { int fromIndex = items.IndexOf(item); if (fromIndex == -1) { throw new InvalidProgramException("Moving an item that isn't in the list is undefined."); } items.RemoveAt(fromIndex); int normalizedToIndex = toIndex; if (fromIndex < toIndex) { normalizedToIndex--; } items.Insert(normalizedToIndex, item); var moveInfo = new ListOperationInfo { FromIndex = fromIndex, ToIndex = normalizedToIndex }; return(moveInfo); }
// Toggles an item's completion state and moves the item to the appropriate index. The normalized from/to indexes are returned in the ListOperationInfo struct. public ListOperationInfo ToggleItem(ListItem item, int preferredDestinationIndex) { int fromIndex = items.IndexOf (item); if (fromIndex == -1) throw new InvalidProgramException ("Toggling an item that isn't in the list is undefined."); items.RemoveAt (fromIndex); item.IsComplete = !item.IsComplete; int toIndex = preferredDestinationIndex; if (toIndex == -1) toIndex = item.IsComplete ? Count : IndexOfFirstCompletedItem(); items.Insert (toIndex, item); var toggleInfo = new ListOperationInfo { FromIndex = fromIndex, ToIndex = toIndex }; return toggleInfo; }
public ListOperationInfo MoveItem(ListItem item, int toIndex) { int fromIndex = items.IndexOf (item); if (fromIndex == -1) throw new InvalidProgramException ("Moving an item that isn't in the list is undefined."); items.RemoveAt (fromIndex); int normalizedToIndex = toIndex; if (fromIndex < toIndex) normalizedToIndex--; items.Insert (normalizedToIndex, item); var moveInfo = new ListOperationInfo { FromIndex = fromIndex, ToIndex = normalizedToIndex }; return moveInfo; }