예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="item"></param>
        /// <param name="parent"></param>
        private void AddDockableItem(DockableItem item, TreeNode parent)
        {
            TreeNode node = new TreeNode(item.ToString());

            node.Tag = item;

            ChangeNodeIcon(node, item.Dock);

            // First node
            if (parent == null)
            {
                trvDockableItems.Nodes.Add(node);
            }
            else
            {
                parent.Nodes.Add(node);
            }



            foreach (DockableItem childItem in item.Items)
            {
                AddDockableItem(childItem, node);
            }
        }
예제 #2
0
 /// <summary>
 ///
 /// </summary>
 private void RemoveDockableItem()
 {
     if (trvDockableItems.SelectedNode != null)
     {
         DockableItem dockableItem = trvDockableItems.SelectedNode.Tag as DockableItem;
         if (trvDockableItems.SelectedNode.Parent != null)
         {
             (trvDockableItems.SelectedNode.Parent.Tag as DockableItem).Items.Remove(dockableItem);
         }
         else
         {
             this.Items.Remove(dockableItem);
         }
         trvDockableItems.SelectedNode.Remove();
     }
 }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="first"></param>
        /// <param name="second"></param>
        private void SwapNodes(TreeNode first, TreeNode second)
        {
            // First index will always greater than the second index.
            // So when removing we remove the item at first index then second index,
            // but when inserting just do the reverse.

            int          firstIndex  = first.Index;
            int          secondIndex = second.Index;
            DockableItem firstItem   = (first.Tag as DockableItem);
            DockableItem secondItem  = (second.Tag as DockableItem);



            // assumes both are in same level
            if (first.Parent != null)
            {
                TreeNode parentNode = first.Parent;
                DockableItemCollection itemCollection = (parentNode.Tag as DockableItem).Items;

                itemCollection.RemoveAt(firstIndex);
                itemCollection.RemoveAt(secondIndex);

                itemCollection.Insert(secondIndex, firstItem);
                itemCollection.Insert(firstIndex, secondItem);

                parentNode.Nodes.RemoveAt(firstIndex);
                parentNode.Nodes.RemoveAt(secondIndex);

                parentNode.Nodes.Insert(secondIndex, first);
                parentNode.Nodes.Insert(firstIndex, second);
            }
            else
            {
                this.Items.RemoveAt(firstIndex);
                this.Items.RemoveAt(secondIndex);

                this.Items.Insert(secondIndex, firstItem);
                this.Items.Insert(firstIndex, secondItem);


                trvDockableItems.Nodes.RemoveAt(firstIndex);
                trvDockableItems.Nodes.RemoveAt(secondIndex);

                trvDockableItems.Nodes.Insert(secondIndex, first);
                trvDockableItems.Nodes.Insert(firstIndex, second);
            }
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        private void AddNewDockableItem()
        {
            DockableItem dockableItem = new DockableItem();

            TreeNode node = new TreeNode(dockableItem.ToString(), IMAGEINDEXNONE, IMAGEINDEXNONE);

            node.Tag = dockableItem;

            if (trvDockableItems.SelectedNode != null)
            {
                (trvDockableItems.SelectedNode.Tag as DockableItem).Items.Add(dockableItem);
                trvDockableItems.SelectedNode.Nodes.Add(node);
            }
            else
            {
                this.items.Add(dockableItem);
                trvDockableItems.Nodes.Add(node);
            }
        }
예제 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="node"></param>
        private void MoveNodeRight(TreeNode node)
        {
            int          nodeIndex = node.Index;
            DockableItem nodeItem  = (node.Tag as DockableItem);
            TreeNode     prevNode  = node.PrevNode;

            if (node.Parent != null)
            {
                (node.Parent.Tag as DockableItem).Items.RemoveAt(nodeIndex);
                node.Parent.Nodes.RemoveAt(nodeIndex);
            }
            else
            {
                this.Items.RemoveAt(nodeIndex);
                trvDockableItems.Nodes.RemoveAt(nodeIndex);
            }
            (prevNode.Tag as DockableItem).Items.Add(nodeItem);
            prevNode.Nodes.Add(node);


            trvDockableItems.SelectedNode = node;
            trvDockableItems.Focus();
        }
예제 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="node"></param>
        private void MoveNodeLeft(TreeNode node)
        {
            int          nodeIndex  = node.Index;
            DockableItem nodeItem   = (node.Tag as DockableItem);
            TreeNode     parentNode = node.Parent;

            (node.Parent.Tag as DockableItem).Items.RemoveAt(nodeIndex);
            node.Parent.Nodes.RemoveAt(nodeIndex);

            if (parentNode.Parent != null)
            {
                TreeNode grandParent = parentNode.Parent;
                (grandParent.Tag as DockableItem).Items.Add(nodeItem);
                grandParent.Nodes.Add(node);
            }
            else
            {
                this.Items.Add(nodeItem);
                trvDockableItems.Nodes.Add(node);
            }

            trvDockableItems.SelectedNode = node;
            trvDockableItems.Focus();
        }