void DisplayObjectService_DisplayObjectVisibleChanged(object sender, DisplayObjectEventArgs e) { string[] groups = DisplayObjectService.GetGroups(e.DisplayObject); string name = DisplayObjectService.GetDisplayName(e.DisplayObject); TreeNodeCollection parentCollection = this.Nodes; for (int i = 0; i < groups.Length; i++) { // if the group node doesn't exist, get out if (!parentCollection.ContainsKey(groups[i])) { return; } parentCollection = parentCollection[groups[i]].Nodes; } // we have the collection for the immediate parent if (parentCollection.ContainsKey(name)) { if (Services.DisplayObjectService.IsVisible(e.DisplayObject)) { parentCollection[name].NodeFont = boldFont; } else { parentCollection[name].NodeFont = this.Font; } } }
void DisplayObjectService_DisplayObjectAdded(object sender, DisplayObjectEventArgs e) { // add to the nodes string[] groups = DisplayObjectService.GetGroups(e.DisplayObject); string name = DisplayObjectService.GetDisplayName(e.DisplayObject); TreeNodeCollection parentCollection = this.Nodes; for (int i = 0; i < groups.Length; i++) { TreeNode node = null; if (parentCollection.ContainsKey(groups[i])) { node = parentCollection[groups[i]]; } else { node = new TreeNode(groups[i]); node.SelectedImageKey = node.ImageKey = "folder closed"; node.Name = groups[i]; parentCollection.Add(node); } node.Expand(); parentCollection = node.Nodes; } // we have the collection for the immediate parent // add the node if it doesn't exist if (!parentCollection.ContainsKey(name)) { TreeNode node = new TreeNode(name); node.Name = name; node.Tag = e.DisplayObject; node.SelectedImageKey = node.ImageKey = "display object"; if (Services.DisplayObjectService.IsVisible(e.DisplayObject)) { node.NodeFont = boldFont; } parentCollection.Add(node); // walk to the root and expand all while (node.Parent != null) { node = node.Parent; node.Expand(); } } }
void DisplayObjectService_DisplayObjectRemoved(object sender, DisplayObjectEventArgs e) { string[] groups = DisplayObjectService.GetGroups(e.DisplayObject); string name = DisplayObjectService.GetDisplayName(e.DisplayObject); TreeNode parentNode = null; TreeNodeCollection parentCollection = this.Nodes; for (int i = 0; i < groups.Length; i++) { // if the group node doesn't exist, get out if (!parentCollection.ContainsKey(groups[i])) { return; } parentNode = parentCollection[groups[i]]; parentCollection = parentNode.Nodes; } // we have the collection for the immediate parent if (parentCollection.ContainsKey(name)) { parentCollection.RemoveByKey(name); } // walk up the parents and see if the folder is empty while (parentNode != null) { if (parentCollection.Count == 0) { // get the parent node and it's collection TreeNode removeNode = parentNode; parentNode = parentNode.Parent; if (parentNode == null) { parentCollection = this.Nodes; } else { parentCollection = parentNode.Nodes; } parentCollection.Remove(removeNode); } else { break; } } }