Пример #1
0
        public void CreateParentNode()
        {
            if (Parent == null)
            {
                return;
            }

            CreateNode();
            TreeView.BeginUpdate();
            BaseWrapper parent    = Parent as BaseWrapper;
            BaseWrapper newParent = Nodes[Nodes.Count - 1] as BaseWrapper;

            newParent.Remove();
            Remove();
            parent.Nodes.Insert(Index, newParent);
            newParent.Nodes.Add(this);
            newParent.Resource.Parent = parent.Resource;
            _resource.Parent          = newParent.Resource;
            _resource.OnMoved();
            TreeView.SelectedNode = this;
            TreeView.EndUpdate();
            EnsureVisible();
        }
Пример #2
0
        public void Link(ResourceNode res)
        {
            Unlink();
            if (res != null)
            {
                Text = res.Name;
                TreeNodeCollection nodes = Nodes;

                //Should we continue down the tree?
                if (IsExpanded && res.HasChildren)
                {
                    //Add/link each resource node
                    foreach (ResourceNode n in res.Children)
                    {
                        bool found = false;
                        foreach (BaseWrapper tn in nodes)
                        {
                            if (tn.Text == n.Name)
                            {
                                tn.Link(n);
                                found = true;
                                // Move node to bottom, to ensure that nodes are shown and saved in the same order as in the original data
                                nodes.Remove(tn);
                                nodes.Add(tn);
                                break;
                            }
                        }

                        if (!found)
                        {
                            nodes.Add(Wrap(_owner, n));
                        }
                    }

                    //Remove empty nodes
                    for (int i = 0; i < nodes.Count;)
                    {
                        BaseWrapper n = nodes[i] as BaseWrapper;
                        if (n._resource == null)
                        {
                            n.Remove();
                        }
                        else
                        {
                            i++;
                        }
                    }

                    _discovered = true;
                }
                else
                {
                    //Node will be reset and undiscovered
                    nodes.Clear();
                    //Collapse();
                    if (res.HasChildren)
                    {
                        nodes.Add(new GenericWrapper());
                        _discovered = false;
                    }
                    else
                    {
                        _discovered = true;
                    }
                }

                SelectedImageIndex = ImageIndex = (int)res.ResourceFileType & 0xFF;

                res.SelectChild     += OnSelectChild;
                res.ChildAdded      += OnChildAdded;
                res.ChildRemoved    += OnChildRemoved;
                res.ChildInserted   += OnChildInserted;
                res.Replaced        += OnReplaced;
                res.Restored        += OnRestored;
                res.Renamed         += OnRenamed;
                res.MovedUp         += OnMovedUp;
                res.MovedDown       += OnMovedDown;
                res.PropertyChanged += OnPropertyChanged;
                res.UpdateProps     += OnUpdateProperties;
                res.UpdateControl   += OnUpdateCurrentControl;
            }

            _resource = res;
        }