private void SaveAs(TmNode node) { saveFileDialog1.FileName = node.Name; if (saveFileDialog1.ShowDialog(this) == DialogResult.OK) { try { if (node.IsThemeList) node.SaveAs(saveFileDialog1.FileName); else if (node.IsCategory) { themesTreeView.Add(node.CopyAsThemeList(saveFileDialog1.FileName)); } else MessageBox.Show("Save As... is only valid on a Theme List or a Category"); } catch (Exception ex) { MessageBox.Show(string.Format("Unable to save Theme List '{0}'\n in file '{1}'\n{2}", node.Name, saveFileDialog1.FileName, ex.Message), "Oh no!"); } } }
/// <summary> /// Creates a new Theme List Node based on the contents of the current Category Node /// </summary> /// <param name="path"></param> /// <returns></returns> internal TmNode CopyAsThemeList(string path) { Debug.Assert(this.IsCategory, "Should only be called on a Category Node"); TmNode newNode = new TmNode(TmNodeType.ThemeList, this.Name, null, new ThemeData(path), this.Metadata.Clone() as Metadata, this.Description, null); ThemeListAuthor author = new ThemeListAuthor(); author["Name"] = Environment.UserName; newNode.Author = author; foreach (var child in Children) newNode.Add(child.Copy()); newNode.SaveAs(path); return newNode; }