/// <summary> /// Removes the provided Curve from Bender. /// </summary> internal void RemoveCurve(Curve curve) { CurveTreeLeaf leaf = FindContainerLeaf(Root, curve); if (leaf != null) { RemoveNodeAndCurves(leaf); leaf.Parent.Children.Remove(leaf); } }
/// <summary> /// Will remove the whole subtree of nodes below the provided node (from the control). /// The provided node must be removed from the tree by the calling code. /// </summary> private void RemoveNodeAndCurves(CurveTreeNode node) { for (int i = node.Children.Count - 1; i >= 0; i--) { RemoveNodeAndCurves(node.Children[i]); } CurveTreeLeaf leaf = node as CurveTreeLeaf; if (leaf != null) { Control.Curves.Remove(leaf.Curve); } }
private CurveTreeLeaf FindContainerLeaf(CurveTreeNode node, Curve curve) { for (int i = node.Children.Count - 1; i >= 0; i--) { CurveTreeLeaf leaf = node.Children[i] as CurveTreeLeaf; if (leaf != null && Object.ReferenceEquals(curve, leaf.Curve.Curve)) { return(leaf); } // Call recursively on this child; leaf = FindContainerLeaf(node.Children[i], curve); if (leaf != null) { return(leaf); } } return(null); }
private void SaveCurve_Click(object sender, RoutedEventArgs e) { CurveTreeLeaf leaf = ((FrameworkElement)sender).DataContext as CurveTreeLeaf; if (leaf == null) { return; } // Get the actual curve to save. Curve curve = leaf.Curve.Curve; if (curve == null) { return; } // Configure save file dialog box Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); dlg.FileName = leaf.Curve.Name; // Default file name dlg.DefaultExt = ".xml"; // Default file extension dlg.Filter = "Xml files (.xml)|*.xml"; // Filter files by extension // Show save file dialog box Nullable <bool> result = dlg.ShowDialog(); // Process save file dialog box results if (result != true) { return; } // Write! using (var streamOut = new FileStream(dlg.FileName, FileMode.Create)) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = " "; XmlWriter writer = XmlWriter.Create(streamOut, settings); IntermediateSerializer.Serialize <Curve>(writer, curve, dlg.FileName); writer.Close(); } }