Beispiel #1
0
        private void AttemptSwap(IDragContainer <T> destination, IDragContainer <T> source)
        {
            // Provisionally remove item from both sides.
            var removedSourceNumber      = source.GetNumber();
            var removedSourceItem        = source.GetItem();
            var removedDestinationNumber = destination.GetNumber();
            var removedDestinationItem   = destination.GetItem();

            source.RemoveItems(removedSourceNumber);
            destination.RemoveItems(removedDestinationNumber);

            var sourceTakeBackNumber      = CalculateTakeBack(removedSourceItem, removedSourceNumber, source, destination);
            var destinationTakeBackNumber = CalculateTakeBack(removedDestinationItem, removedDestinationNumber, destination, source);

            // Do take backs (if needed)
            if (sourceTakeBackNumber > 0)
            {
                source.AddItemsByDragging(removedSourceItem, sourceTakeBackNumber);
                removedSourceNumber -= sourceTakeBackNumber;
            }
            if (destinationTakeBackNumber > 0)
            {
                destination.AddItemsByDragging(removedDestinationItem, destinationTakeBackNumber);
                removedDestinationNumber -= destinationTakeBackNumber;
            }

            // Abort if we can't do a successful swap
            if (source.MaxAcceptable(removedDestinationItem) < removedDestinationNumber ||
                destination.MaxAcceptable(removedSourceItem) < removedSourceNumber ||
                destination.MaxAcceptable(removedSourceItem) == 0 ||
                source.MaxAcceptable(removedSourceItem) == 0)
            {
                destination.AddItemsByDragging(removedDestinationItem, removedDestinationNumber);
                source.AddItemsByDragging(removedSourceItem, removedSourceNumber);
                return;
            }

            // Do swaps
            if (removedDestinationNumber > 0)
            {
                source.AddItemsByDragging(removedDestinationItem, removedDestinationNumber);
            }
            if (removedSourceNumber > 0)
            {
                destination.AddItemsByDragging(removedSourceItem, removedSourceNumber);
            }
        }