/// <summary> /// Removes a node from the children. /// </summary> /// <param name="childViewModel">The child to remove.</param> public void RemoveChild(CoverageNodeViewModel childViewModel) { if (Children.Remove(childViewModel)) { Model.RecountCoverage(); } }
/// <summary> /// Initializes a new instance of <see cref="CoverageNodeViewModel"/>. /// </summary> /// <param name="model">The model to initialize with.</param> /// <param name="parent">The parent coverage row's view model.</param> public CoverageNodeViewModel(CoverageNodeViewModel parent, CoverageNodeModel model) : base(model) { Parent = parent; IsExpanded = false; IsVisible = DetermineVisibility(); ToggleExpandedCmd = new RelayCommand(ToggleExpanded); SetupChildren(model); int depth = 0; var node = parent; while (node != null) { node = node.Parent; depth++; } RowDepth = depth; Messenger.Register <ThresholdChangedMessage>(this, HandleThresholdChanged); }
/// <summary> /// Appends a coverage node and all children in such a way as to flatten the coverage data tree. /// </summary> /// <param name="vm">The coverage data node.</param> /// <param name="flatList">The list to add rows to.</param> private static void AppendRows(CoverageNodeViewModel vm, List <CoverageNodeViewModel> flatList) { flatList.Add(vm); foreach (var child in vm.Children) { AppendRows(child, flatList); } }
/// <summary> /// Determines the visibility of this node. /// </summary> /// <returns>True if this node is visible, or false if not.</returns> private bool DetermineVisibility() { // check the parent chain for any collapsed nodes. bool parentsExpanded = true; CoverageNodeViewModel parent = Parent; while (parentsExpanded && parent != null) { parentsExpanded = parent.IsExpanded; parent = parent.Parent; } // a parent somewhere up the chain is collapsed; this is not visible. if (!parentsExpanded) { return(false); } return(true); }
/// <summary> /// Removes the selected node and all of its children. /// </summary> private void RemoveSelectedNode() { if (SelectedCoverageRow != null) { CoverageNodeViewModel parent = SelectedCoverageRow.Parent; if (parent != null) { // non-root node. parent.RemoveChild(SelectedCoverageRow); // rebuild the row list. RebuildRowList(); } else { // removing a root, just remove from CoverageRows and let the // CollectionChanged handler deal with updating the list. CoverageRows.Remove(SelectedCoverageRow); } } }