void VisualChildren_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (e.OldItems != null) { foreach (HeliosVisual visual in e.OldItems) { ProfileExplorerTreeItem child = GetChildObject(visual); if (child != null) { child.Disconnect(); Children.Remove(child); } } } if (e.NewItems != null) { foreach (HeliosVisual child in e.NewItems) { if ((child is HeliosPanel && _includeTypes.HasFlag(ProfileExplorerTreeItemType.Panel)) || (child is HeliosVisual && _includeTypes.HasFlag(ProfileExplorerTreeItemType.Visual))) { Children.Add(new ProfileExplorerTreeItem(child, this, _includeTypes)); } } } }
void Bindings_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (e.OldItems != null) { foreach (HeliosBinding binding in e.OldItems) { ProfileExplorerTreeItem child = GetChildObject(binding); if (child != null) { child.Disconnect(); Children.Remove(child); } } } if (e.NewItems != null) { foreach (HeliosBinding child in e.NewItems) { if (child.Action == ContextItem || child.Trigger == ContextItem) { ProfileExplorerTreeItem childItem = new ProfileExplorerTreeItem(child, this, _includeTypes); if (_includeTypes.HasFlag(ProfileExplorerTreeItemType.Binding)) { IsExpanded = true; Children.Add(childItem); } } } } }
/// <summary> /// common code for handling collection changes to tree item collections that are represented as a named folder /// rather than just directly adding children under the current node /// /// this type of folder is not removed when empty /// </summary> /// <typeparam name="THeliosObject"></typeparam> /// <param name="folderName"></param> /// <param name="removedChildren"></param> /// <param name="addedChildren"></param> /// <param name="factory"></param> private void FolderContentsChanged <THeliosObject>(string folderName, IEnumerable removedChildren, IEnumerable addedChildren, Func <THeliosObject, ProfileExplorerTreeItem> factory) { bool newFolder = false; ProfileExplorerTreeItem childrenFolder; // lazy create folder if (HasFolder(folderName)) { childrenFolder = GetFolder(folderName); } else { childrenFolder = new ProfileExplorerTreeItem(folderName, "", this, _includeTypes); newFolder = true; } if (removedChildren != null) { foreach (THeliosObject removedChild in removedChildren) { ProfileExplorerTreeItem childItem = childrenFolder.GetChildObject(removedChild); if (childItem == null) { // not found continue; } // remove from folder, but never remove the folder itself, as it is considered part of the UI childItem.Disconnect(); childrenFolder.Children.Remove(childItem); } } if (addedChildren != null) { foreach (THeliosObject addedChild in addedChildren) { ProfileExplorerTreeItem childItem = factory(addedChild); childrenFolder.Children.Add(childItem); } } if (newFolder && childrenFolder.HasChildren) { Children.Add(childrenFolder); } }
void Interfaces_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { bool newFolder = false; ProfileExplorerTreeItem interfaces; if (HasFolder("Interfaces")) { interfaces = GetFolder("Interfaces"); } else { interfaces = new ProfileExplorerTreeItem("Interfaces", "", this, _includeTypes); newFolder = true; } if (e.OldItems != null) { foreach (HeliosInterface heliosInterface in e.OldItems) { ProfileExplorerTreeItem child = interfaces.GetChildObject(heliosInterface); if (child != null) { child.Disconnect(); interfaces.Children.Remove(child); } } } if (e.NewItems != null) { foreach (HeliosInterface heliosInterface in e.NewItems) { ProfileExplorerTreeItem childItem = new ProfileExplorerTreeItem(heliosInterface, this, _includeTypes); interfaces.Children.Add(childItem); } } if (newFolder && interfaces.HasChildren) { Children.Add(interfaces); } }