Example #1
0
        /// <summary>
        /// Resets the flat children table.
        /// </summary>
        protected virtual void ResetFlatChildren()
        {
            UninstallAllHandlers();

            VisibleChildren.Clear();
            ExpandedChildren.Clear();
        }
Example #2
0
        private void LeftClickSelectExtendedShiftDown(object item)
        {
            int FirstIndex = VisibleChildren.IndexOf(item);
            int LastIndex  = LastSelectedItem != null && IsLastSelectedItemSet?VisibleChildren.IndexOf(LastSelectedItem) : FirstIndex;

            if (FirstIndex >= 0 && LastIndex >= 0)
            {
                if (FirstIndex > LastIndex)
                {
                    int Index = FirstIndex;
                    FirstIndex = LastIndex;
                    LastIndex  = Index;
                }

                BeginUpdateSelectedItems();

                if (!IsCtrlDown())
                {
                    SelectedItems.Clear();
                }
                for (int i = FirstIndex; i <= LastIndex; i++)
                {
                    AddSelectedItem(VisibleChildren[i]);
                }

                EndUpdateSelectedItems();

                if (!IsLastSelectedItemSet)
                {
                    SetLastSelectedItem(item);
                }
            }
        }
        /// <summary>
        /// Called when children have been added to an item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="startIndex">Index where the first child is added.</param>
        /// <param name="itemList">The list of children.</param>
        protected virtual void OnItemAddChildren(object item, int startIndex, IList itemList)
        {
            NotifyPreviewCollectionModified(TreeViewCollectionOperation.Insert);

            if (IsExpanded(item))
            {
                int ShownPreviousChildrenCount = VisibleChildren.IndexOf(item);
                ShownPreviousChildrenCount += CountPreviousChildrenExpanded(item, startIndex, -1);

                int ShownIndex = ShownPreviousChildrenCount;

                IInsertItemContext Context = CreateInsertItemContext(item, ShownIndex);
                Context.Start();

#if NETCOREAPP3_1
                foreach (object?ChildItem in itemList)
                {
                    if (ChildItem != null)
                    {
                        InsertChildren(Context, ChildItem, item);
                    }
                }
#else
                foreach (object ChildItem in itemList)
                {
                    InsertChildren(Context, ChildItem, item);
                }
#endif

                Context.Complete();
                Context.Close();
            }

            NotifyCollectionModified(TreeViewCollectionOperation.Insert);
        }
Example #4
0
        /// <summary>
        /// Collapses an item.
        /// </summary>
        /// <param name="item">The item.</param>
        public void SetItemCollapsed(object item)
        {
            ExpandedChildren.Remove(item);

            int Index = VisibleChildren.IndexOf(item) + 1;

            Collapse(item, Index);
        }
        /// <summary>
        /// Called when children of an item are reset.
        /// </summary>
        /// <param name="item">The item.</param>
        protected virtual void OnItemResetChildren(object item)
        {
            NotifyPreviewCollectionModified(TreeViewCollectionOperation.Remove);

            if (IsExpanded(item))
            {
                object?ParentItem = GetItemParent(item);

                int StartIndex;
                int RemoveCount;

                if (ParentItem != null)
                {
                    StartIndex = VisibleChildren.IndexOf(item) + 1;

                    IList Siblings  = GetItemChildren(ParentItem);
                    int   ItemIndex = Siblings.IndexOf(item);
                    if (ItemIndex + 1 < Siblings.Count)
                    {
                        object NextItem = Siblings[ItemIndex + 1] !;
                        int    EndIndex = VisibleChildren.IndexOf(NextItem);
                        RemoveCount = EndIndex - StartIndex;
                    }
                    else
                    {
                        RemoveCount = CountVisibleChildren(item);
                    }
                }
                else
                {
                    StartIndex  = 1;
                    RemoveCount = VisibleChildren.Count - 1;
                }

                IRemoveItemContext Context = CreateRemoveItemContext(item, StartIndex);
                Context.Start();

                for (int i = 0; i < RemoveCount; i++)
                {
                    object RemovedItem = VisibleChildren[Context.ShownIndex];

                    InternalRemove(Context.ShownIndex, RemovedItem);
                    Context.NextIndex();

                    if (ExpandedChildren.ContainsKey(RemovedItem))
                    {
                        ExpandedChildren.Remove(RemovedItem);
                    }
                }

                Context.Complete();
                Context.Close();
            }

            NotifyCollectionModified(TreeViewCollectionOperation.Remove);
        }
Example #6
0
        /// <summary>
        /// Sets an item to be expanded.
        /// </summary>
        /// <param name="item">The item.</param>
        public void SetItemExpanded(object item)
        {
            IList Children = GetItemChildren(item);

            ExpandedChildren.Add(item, Children);

            int Index = VisibleChildren.IndexOf(item) + 1;

            Expand(item, Index);
        }
        private void OnItemMoveChildrenPreviousAfter(object item, int oldIndex, int newIndex, IList itemList)
        {
            int ShownPreviousChildrenCount = VisibleChildren.IndexOf(item);

            int RemoveIndex = ShownPreviousChildrenCount;

            RemoveIndex += CountPreviousChildrenExpanded(item, oldIndex + 1, newIndex);

            IRemoveItemContext RemoveContext = CreateRemoveItemContext(item, RemoveIndex);

            RemoveContext.Start();

#if NETCOREAPP3_1
            foreach (object?ChildItem in itemList)
            {
                if (ChildItem != null)
                {
                    RemoveChildren(RemoveContext, ChildItem);
                }
            }
#else
            foreach (object ChildItem in itemList)
            {
                RemoveChildren(RemoveContext, ChildItem);
            }
#endif

            RemoveContext.Complete();
            RemoveContext.Close();

            int InsertIndex = ShownPreviousChildrenCount;
            InsertIndex += CountPreviousChildrenExpanded(item, newIndex, -1);

            IInsertItemContext InsertContext = CreateInsertItemContext(item, InsertIndex);
            InsertContext.Start();

#if NETCOREAPP3_1
            foreach (object?ChildItem in itemList)
            {
                if (ChildItem != null)
                {
                    InsertChildren(InsertContext, ChildItem, item);
                }
            }
#else
            foreach (object ChildItem in itemList)
            {
                InsertChildren(InsertContext, ChildItem, item);
            }
#endif

            InsertContext.Complete();
            InsertContext.Close();
        }
Example #8
0
 /// <summary>
 /// Clicks the item after <paramref name="item"/>.
 /// </summary>
 /// <param name="item">The item.</param>
 public void ClickNextItem(object item)
 {
     if (!IsCtrlDown())
     {
         int ItemIndex = VisibleChildren.IndexOf(item);
         if (ItemIndex >= 0 && ItemIndex + 1 < VisibleChildren.Count)
         {
             LeftClickSelect(VisibleChildren[ItemIndex + 1]);
         }
     }
 }
Example #9
0
 /// <summary>
 /// Clicks the item before <paramref name="item"/>.
 /// </summary>
 /// <param name="item">The item.</param>
 public void ClickPreviousItem(object item)
 {
     if (!IsCtrlDown())
     {
         int ItemIndex = VisibleChildren.IndexOf(item);
         if (ItemIndex > 0)
         {
             LeftClickSelect(VisibleChildren[ItemIndex - 1]);
         }
     }
 }
        /// <summary>
        /// Updates the target of a drag drop operation.
        /// </summary>
        /// <param name="e">The event data.</param>
        /// <param name="isLeaving">True if the operation is to leave the target.</param>
        protected virtual void UpdateCurrentDropTarget(DragEventArgs e, bool isLeaving)
        {
            ExtendedTreeViewItemBase?DropTarget;

            if (isLeaving)
            {
                DropTarget = null;
            }
            else
            {
                DropTarget = GetEventSourceItem(e);
            }

            if (DropTargetContainer != DropTarget)
            {
                ExtendedTreeViewItemBase?OldDropTarget = DropTargetContainer;
                DropTargetContainer = DropTarget;
                ExtendedTreeViewItemBase?NewDropTarget = DropTargetContainer;

                if (OldDropTarget != null)
                {
                    OldDropTarget.UpdateIsDropOver();
                }
                if (NewDropTarget != null)
                {
                    NewDropTarget.UpdateIsDropOver();

                    object NewItem = NewDropTarget.Content;
                    if (NewItem != null)
                    {
                        int NewIndex = VisibleChildren.IndexOf(NewItem);
                        if (NewIndex != -1 && DropTargetContainerIndex != -1)
                        {
                            if (NewIndex > DropTargetContainerIndex && NewIndex + 1 < VisibleChildren.Count)
                            {
                                ScrollIntoView(VisibleChildren[NewIndex + 1]);
                            }
                            if (NewIndex < DropTargetContainerIndex && NewIndex > 0)
                            {
                                ScrollIntoView(VisibleChildren[NewIndex - 1]);
                            }
                        }

                        DropTargetContainerIndex = NewIndex;
                    }
                }
            }
        }
Example #11
0
        public override void RemoveChild(int childId)
        {
            //Remove View
            var timeEntryViewToRemove = Children.SingleOrDefault(task => ((ListTimeEntryViewModel)task).TimeEntry.Id == childId);

            if (timeEntryViewToRemove != null)
            {
                Children.Remove(timeEntryViewToRemove);
                if (VisibleChildren.Contains(timeEntryViewToRemove))
                {
                    VisibleChildren.Remove(timeEntryViewToRemove);
                }
            }

            Reload();
        }
Example #12
0
 /// <summary>
 /// Checks if an item is visible in the scrolled view.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <returns>True if visible; Otherwise, false.</returns>
 public virtual bool IsItemVisible(object item)
 {
     return(VisibleChildren.Contains(item));
 }
Example #13
0
 /// <summary>
 /// Performs the remove operation.
 /// </summary>
 /// <param name="index">The item index in the list of visible children.</param>
 /// <param name="item">The item to remove.</param>
 protected virtual void InternalRemove(int index, object item)
 {
     UninstallHandlers(item);
     VisibleChildren.RemoveAt(index);
 }
Example #14
0
 /// <summary>
 /// Performs the insertion operation.
 /// </summary>
 /// <param name="index">The item index in the list of visible children.</param>
 /// <param name="item">The item to insert.</param>
 protected virtual void InternalInsert(int index, object item)
 {
     VisibleChildren.Insert(index, item);
     InstallHandlers(item);
 }
Example #15
0
 /// <summary>
 /// Sorts two items by index.
 /// </summary>
 /// <param name="item1">The first item.</param>
 /// <param name="item2">The second item.</param>
 /// <returns>The sort result.</returns>
 protected virtual int SortByIndex(object item1, object item2)
 {
     return(VisibleChildren.IndexOf(item1) - VisibleChildren.IndexOf(item2));
 }