コード例 #1
0
        // 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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: List.cs プロジェクト: CBrauer/monotouch-samples
		// 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;
		}
コード例 #4
0
ファイル: List.cs プロジェクト: CBrauer/monotouch-samples
		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;
		}