Beispiel #1
0
        public void CheckForUngroup(DnDContainer <TListItem, TItem, TGroup> containerToCheck = null, int indexInParentContainer = -1)
        {
            var overrideDebug = false;

            if (DnDState.ShowDebugInfo || overrideDebug)
            {
                Console.WriteLine($"Checking for ungroup for {Address}");
            }

            if (containerToCheck is null)
            {
                containerToCheck = (DnDContainer <TListItem, TItem, TGroup>) this;
            }
            if (containerToCheck == DnDState.BaseContainer)
            {
                if (DnDState.ShowDebugInfo || overrideDebug)
                {
                    Console.WriteLine("The container being checked for ungroup is the Base Container and will not be ungrouped.");
                }
                return;
            }

            if (containerToCheck.List.Count() > 1)
            {
                if (DnDState.ShowDebugInfo || overrideDebug)
                {
                    Console.WriteLine("The container has more than 1 element and should not be ungrouped.");
                }
                return;
            }

            if (DnDState.ShowDebugInfo || overrideDebug)
            {
                Console.WriteLine($"Passed in indexInParentContainer: {indexInParentContainer}");
                Console.WriteLine($"containerToCheck's address: {containerToCheck.Address}");
            }

            if (indexInParentContainer < 0 && !int.TryParse(containerToCheck.Address.Split('.').Last(), out indexInParentContainer))
            {
                Console.Error.WriteLine("Could not determine the container's index in the parent container during ungroup.");
            }
            var parent = containerToCheck.Parent;

            if (parent is null)
            {
                Console.Error.WriteLine("The parent container could not be determined.");
                return;
            }
            // Remove the item from the group and place it at the group's original index
            if (DnDState.ShowDebugInfo || overrideDebug)
            {
                Console.WriteLine($"Removing item at index {indexInParentContainer} from {parent.Address} due to ungroup");
            }
            parent.List.RemoveAt(indexInParentContainer);
            if (containerToCheck.List.Count() == 1)
            {
                var item = containerToCheck.List[0];
                parent.List.Insert(indexInParentContainer, item);
            }
        }
Beispiel #2
0
        public async Task SetPayload(DnDContainer <TListItem, TItem, TGroup> fromContainer, int index, string address = null, bool isContainer = false)
        {
            var overrideDebug = false;

            if (DnDState.ShowDebugInfo || overrideDebug)
            {
                Console.WriteLine($"Setting payload to {(string.IsNullOrWhiteSpace(address) ? "{empty}" : address)}");
            }
            await DnDState.SetPayload(fromContainer, index, address, isContainer);
        }
        public async Task SetPayload(DnDContainer <TListItem, TItem, TGroup> fromContainer, int index, string address = null, bool isContainer = false)
        {
            var overrideDebug = false;

            if (ShowDebugInfo || overrideDebug)
            {
                Console.WriteLine($"Setting payload to {(string.IsNullOrWhiteSpace(address) ? "{empty}" : address)}");
            }
            Payload.FromContainer = fromContainer;
            Payload.FromIndex     = index;
            Payload.Address       = address;
            Payload.IsContainer   = isContainer;
            await BaseContainer.NotifyStateChanged();
        }
Beispiel #4
0
        protected async Task HandleDragStart(DragEventArgs e, int index, DnDContainer <TListItem, TItem, TGroup> fromContainer, string address = null, bool isContainer = false)
        {
            var overrideDebug = false;

            if (DnDState.ShowDebugInfo || overrideDebug)
            {
                Console.WriteLine($"Drag started for {address}");
            }
            if (index >= fromContainer.List.Count())
            {
                Console.WriteLine("Item index was out of range"); return;
            }
            // Pause before setting the payload to allow the Drag event to register in the browser for the default action of picking up the item.
            await Task.Delay(20);

            await SetPayload(fromContainer, index, address, isContainer);

            DnDState.ShowDropAtEnd = true;
        }