コード例 #1
0
ファイル: TreeManager.cs プロジェクト: rinavin/RCJS
        /// <summary>
        /// create parent row
        /// </summary>
        /// <param name="parentIdx">index of parent</param>
        /// <param name="afterSibling">add new node after this sibling, if equals 0, add node as first child</param>
        /// <param name="mgRow">idx of new node</param>
        internal void createNode(int parentIdx, int afterSiblingIdx, int mgRow)
        {
            Debug.Assert(Misc.IsGuiThread());
            TreeNode item   = null;
            Object   parent = controlsMap.object2Widget(_mgTreeControl, parentIdx);

            Debug.Assert(parent != null);
            int       idx          = 0;
            TreeChild afterSibling = null;

            if (afterSiblingIdx > 0)
            {
                afterSibling = (TreeChild)controlsMap.object2Widget(_mgTreeControl, afterSiblingIdx);
                idx          = afterSibling.getIndex() + 1;
            }

            if (parent is TreeView)
            {
                item = ((TreeView)parent).Nodes.Insert(idx, "");
                // ensure that the root is visible even if the tree is not visible.
                // if not ensured, set expand might not work on nodes and when tree is visible
                // it will be collapsed.
                item.EnsureVisible();
            }
            else if (parent is TreeChild)
            {
                ((TreeChild)parent).removeDummyItem();
                item = (((TreeChild)parent).getTreeNode()).Nodes.Insert(idx, "");
            }
            else
            {
                Debug.Assert(false);
            }

            TreeChild treeChild = new TreeChild(this, _mgTreeControl, 0, mgRow, item);

            // check that we do not add node twice
            Debug.Assert(controlsMap.object2Widget(_mgTreeControl, mgRow) == null);
            // add treechild to madding
            controlsMap.add(_mgTreeControl, mgRow, treeChild);
            // set map data on tree item
            item.Tag = new TagData();
            controlsMap.setMapData(_mgTreeControl, mgRow, item);
        }
コード例 #2
0
ファイル: TreeManager.cs プロジェクト: rinavin/RCJS
        /// <summary>
        /// move node under parent to a location after 'afterSiblingIdx'.
        /// </summary>
        /// <param name="parentIdx">The parent node under which we are moving the node</param>
        /// <param name="afterSiblingIdx">The new location is after that sibling</param>
        /// <param name="nodeId">The node to move</param>
        internal void moveNode(int parentIdx, int afterSiblingIdx, int nodeId)
        {
            Debug.Assert(Misc.IsGuiThread());
            Object parent = controlsMap.object2Widget(_mgTreeControl, parentIdx);

            Debug.Assert(parent != null);
            int       idx          = 0;
            TreeChild afterSibling = null;
            TreeChild nodeToMove   = null;

            //get the treeChild of the node to move
            nodeToMove = (TreeChild)controlsMap.object2Widget(_mgTreeControl, nodeId);

            // get the new index under the parent
            if (afterSiblingIdx > 0)
            {
                afterSibling = (TreeChild)controlsMap.object2Widget(_mgTreeControl, afterSiblingIdx);
                idx          = afterSibling.getIndex() + 1;
            }

            //inserting an open node, raises the before expand. avoid it.
            _treeControl.BeforeExpand -= TreeHandler.getInstance().BeforeExpandHandler;

            // remove from the nodes collection and add at the new location.
            if (parent is TreeView)
            {
                //remove and insert of a root (The parent is the tree itself)
                ((TreeView)parent).Nodes.Remove(nodeToMove.getTreeNode());
                ((TreeView)parent).Nodes.Insert(idx, nodeToMove.getTreeNode());
            }
            else if (parent is TreeChild)
            {
                //remove and insert of a node with another node as a parent.
                (((TreeChild)parent).getTreeNode()).Nodes.Remove(nodeToMove.getTreeNode());
                (((TreeChild)parent).getTreeNode()).Nodes.Insert(idx, nodeToMove.getTreeNode());
            }
            else
            {
                Debug.Assert(false);
            }

            // resume handling 'Before expand'.
            _treeControl.BeforeExpand += TreeHandler.getInstance().BeforeExpandHandler;
        }