예제 #1
0
 public virtual void SetIsDragPossible(CanonicSelection canonicSelectedItemList)
 {
     if (canonicSelectedItemList != null)
     {
         this.DragParentItem = canonicSelectedItemList.DraggedItemParent;
         this.ItemList       = canonicSelectedItemList.ItemList;
         this.AllowDropCopy  = canonicSelectedItemList.AllItemsCloneable;
     }
 }
        /// <summary>
        /// Gets the list of selected ims.
        /// </summary>
        /// <param name="canonicSelectedItemList">The list to fill.</param>
        /// <returns>True if successful; otherwise, false.</returns>
        protected virtual bool GetCanonicSelectedItemList(CanonicSelection canonicSelectedItemList)
        {
            if (SelectedItems.Count == 0)
            {
                return(false);
            }

            List <object> SortedSelectedItems = new List <object>();

#if NETCOREAPP3_1
            foreach (object?Item in SelectedItems)
            {
                if (Item != null)
                {
                    SortedSelectedItems.Add(Item);
                }
            }
#else
            foreach (object Item in SelectedItems)
            {
                SortedSelectedItems.Add(Item);
            }
#endif

            SortedSelectedItems.Sort(SortByIndex);

            object FirstItem = SortedSelectedItems[0];
            if (IsContent(FirstItem))
            {
                return(false);
            }

            object?FirstItemParent = GetItemParent(FirstItem);

            if (FirstItemParent != null)
            {
                if (GetItemsWithSameParent(SortedSelectedItems, FirstItemParent, canonicSelectedItemList))
                {
                    canonicSelectedItemList.SetDraggedItemParent(FirstItemParent);
                    return(true);
                }

                if (GetItemsInSameBranch(SortedSelectedItems, FirstItemParent, canonicSelectedItemList))
                {
                    canonicSelectedItemList.SetDraggedItemParent(FirstItemParent);
                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        /// Updates the drag drop allowed properties.
        /// </summary>
        protected virtual void UpdateIsDragDropPossible()
        {
            CanonicSelection CanonicSelectedItemList = new CanonicSelection(CreateItemList());

            if (GetCanonicSelectedItemList(CanonicSelectedItemList))
            {
                DragSource.SetIsDragPossible(CanonicSelectedItemList);
            }
            else
            {
                DragSource.ClearIsDragPossible();
                DragSource.ClearFlatDraggedItemList();
            }
        }
예제 #4
0
 /// <summary>
 /// Changes the drag activity.
 /// </summary>
 /// <param name="canonicSelectedItemList">The lost of selected items.</param>
 public virtual void SetIsDragPossible(CanonicSelection canonicSelectedItemList)
 {
     DraggedItemParent = canonicSelectedItemList.DraggedItemParent;
     ItemList          = canonicSelectedItemList.ItemList;
     AllowDropCopy     = canonicSelectedItemList.AllItemsCloneable;
 }
        /// <summary>
        /// Gets the list of selected items with the same parent.
        /// </summary>
        /// <param name="sortedSelectedItems">The list of selected items, sorted.</param>
        /// <param name="firstItemParent">The parent of the first item.</param>
        /// <param name="canonicSelectedItemList">The list of selected items, unsorted.</param>
        /// <returns>True if successful; otherwise, false.</returns>
        protected virtual bool GetItemsWithSameParent(IList sortedSelectedItems, object firstItemParent, CanonicSelection canonicSelectedItemList)
        {
            if (sortedSelectedItems == null || canonicSelectedItemList == null)
            {
                return(false);
            }

            canonicSelectedItemList.AllItemsCloneable = true;

#if NETCOREAPP3_1
            foreach (object?Item in sortedSelectedItems)
            {
                if (Item != null)
                {
                    if (GetItemParent(Item) != firstItemParent)
                    {
                        return(false);
                    }

                    canonicSelectedItemList.ItemList.Add(Item);

                    if (!IsItemCloneable(Item))
                    {
                        canonicSelectedItemList.AllItemsCloneable = false;
                    }
                }
            }
#else
            foreach (object Item in sortedSelectedItems)
            {
                if (GetItemParent(Item) != firstItemParent)
                {
                    return(false);
                }

                canonicSelectedItemList.ItemList.Add(Item);

                if (!IsItemCloneable(Item))
                {
                    canonicSelectedItemList.AllItemsCloneable = false;
                }
            }
#endif

            return(true);
        }
        /// <summary>
        /// Checks if all items of a branch are selected.
        /// </summary>
        /// <param name="sortedSelectedItems">The list of selected items, sorted.</param>
        /// <param name="item">The parent item.</param>
        /// <param name="canonicSelectedItemList">The list of selected items, unsorted.</param>
        /// <returns>True if in the same branch; otherwise, false.</returns>
        protected virtual bool IsEntireBranchSelected(IList sortedSelectedItems, object item, CanonicSelection canonicSelectedItemList)
        {
            if (sortedSelectedItems == null || canonicSelectedItemList == null)
            {
                return(false);
            }

            if (!IsItemCloneable(item))
            {
                canonicSelectedItemList.AllItemsCloneable = false;
            }

            canonicSelectedItemList.RecordCount++;

            if (IsExpanded(item))
            {
                IList Children = GetItemChildren(item);

#if NETCOREAPP3_1
                foreach (object?ChildItem in Children)
                {
                    if (ChildItem != null)
                    {
                        if (!sortedSelectedItems.Contains(ChildItem))
                        {
                            return(false);
                        }

                        if (!IsEntireBranchSelected(sortedSelectedItems, ChildItem, canonicSelectedItemList))
                        {
                            return(false);
                        }
                    }
                }
#else
                foreach (object ChildItem in Children)
                {
                    if (!sortedSelectedItems.Contains(ChildItem))
                    {
                        return(false);
                    }

                    if (!IsEntireBranchSelected(sortedSelectedItems, ChildItem, canonicSelectedItemList))
                    {
                        return(false);
                    }
                }
#endif
            }

            return(true);
        }
        /// <summary>
        /// Gets the list of selected items in the same branch.
        /// </summary>
        /// <param name="sortedSelectedItems">The list of selected items, sorted.</param>
        /// <param name="firstItemParent">The parent of the first item.</param>
        /// <param name="canonicSelectedItemList">The list of selected items, unsorted.</param>
        /// <returns>True if successful; otherwise, false.</returns>
        protected virtual bool GetItemsInSameBranch(IList sortedSelectedItems, object firstItemParent, CanonicSelection canonicSelectedItemList)
        {
            if (sortedSelectedItems == null || canonicSelectedItemList == null)
            {
                return(false);
            }

            IList Children = GetItemChildren(firstItemParent);

#if NETCOREAPP3_1
            foreach (object?ChildItem in Children)
            {
                if (ChildItem != null)
                {
                    if (sortedSelectedItems.Contains(ChildItem))
                    {
                        if (!canonicSelectedItemList.ItemList.Contains(ChildItem))
                        {
                            canonicSelectedItemList.ItemList.Add(ChildItem);
                        }
                        if (!IsEntireBranchSelected(sortedSelectedItems, ChildItem, canonicSelectedItemList))
                        {
                            return(false);
                        }
                    }
                }
            }
#else
            foreach (object ChildItem in Children)
            {
                if (sortedSelectedItems.Contains(ChildItem))
                {
                    if (!canonicSelectedItemList.ItemList.Contains(ChildItem))
                    {
                        canonicSelectedItemList.ItemList.Add(ChildItem);
                    }
                    if (!IsEntireBranchSelected(sortedSelectedItems, ChildItem, canonicSelectedItemList))
                    {
                        return(false);
                    }
                }
            }
#endif

            if (canonicSelectedItemList.RecordCount < sortedSelectedItems.Count)
            {
                return(false);
            }

            return(true);
        }