public virtual void UpdateTitle() { Text = ProjectObject.ToString(); if (ParentForm != null) { ParentForm.Text = ProjectObject.ToString(); } }
/// <summary> /// Adds a new object to the allObjects view. /// </summary> private void AddObject(ProjectObject obj) { if (obj.HideFromHierarchy) { return; } string parentKey = GetParentKey(obj); TreeNodeCollection addTo; if (!string.IsNullOrEmpty(parentKey)) { TreeNode parentNode = GetTreeNode(parentKey, true); addTo = parentNode.Nodes; } else { addTo = allObjectsTreeView.Nodes; } string uniqueId = obj.UniqueId.ToString(); // see if there is a Windows folder node that corresponds to this newly-added Unity folder node TreeNode existingFolderNode = null; UnityFolder folderObj = obj as UnityFolder; if (folderObj != null) { string folderPath = folderObj.FolderPath; m_treeNodes.TryGetValue(folderPath, out existingFolderNode); } // see if there is an existing node of any kind for this object TreeNode node; m_treeNodes.TryGetValue(uniqueId, out node); if (existingFolderNode != null) // there is a Windows folder node { if (node == null) // there isn't a Unity node { // recycle the Windows folder node as a Unity folder node if (!m_treeNodes.Remove(existingFolderNode.Name)) { throw new InvalidOperationException("Programming error"); } m_treeNodes.Add(folderObj.UniqueId, existingFolderNode); node = existingFolderNode; } else // there is a Unity node { // trash the Windows folder node and use the existing Unity folder node if (!m_treeNodes.Remove(existingFolderNode.Name)) { throw new InvalidOperationException("Programming error"); } foreach (TreeNode childNode in existingFolderNode.Nodes) { if (childNode != null) //HACK: why? { childNode.Remove(); node.Nodes.Add(childNode); } } existingFolderNode.Remove(); existingFolderNode = null; } } if (node != null) { // ensure the existing node is parented correctly node.Remove(); addTo.Add(node); // update node info node.Text = obj.ToString(); node.Name = obj.UniqueId.ToString(); string imageKey = obj.GetIconKey(); int imageIndex = IconImages.GetImageIndex(imageKey); node.ImageIndex = node.SelectedImageIndex = imageIndex; node.ImageKey = node.SelectedImageKey = imageKey; } else { // create a new node string imageKey = obj.GetIconKey(); int imageIndex = IconImages.GetImageIndex(imageKey); node = new TreeNode(obj.ToString(), imageIndex, imageIndex) { Name = obj.UniqueId.ToString(), ImageKey = imageKey, SelectedImageKey = imageKey, }; AddTreeNode(addTo, node); } UpdateParseProgress(); }