static public void DeleteTreeNode(string key, TreeNode parentTn) { if (parentTn.Level == 2) { parentTn = parentTn.Parent.Parent; } else if (parentTn.Level == 1) { parentTn = parentTn.Parent; } foreach (TreeNode tNode in parentTn.Nodes) { if (key == tNode.Text) { XElement xNode = (XElement)tNode.Tag; XDocument doc = DocumentDescriptor.DocFromTag(parentTn.Tag); var elems = doc.Root.Descendants("data").ToArray(); var elem = elems.Where(d => (string)d.FirstAttribute.Value == key).FirstOrDefault(); if (elem != null) { elem.Remove(); } tNode.Remove(); break; } } }
static public void AddNewNodeToTreeNode(bool isCombining, NodeData data, TreeNode parentTn, bool isMaster) { if (parentTn.Level == 2) { parentTn = parentTn.Parent.Parent; } else if (parentTn.Level == 1) { parentTn = parentTn.Parent; } TreeNode newTvn = parentTn.Nodes.Add(data.KeyName, data.KeyName); TreeNode newTextTvn = new TreeNode(data.Text); newTvn.Nodes.Add(newTextTvn); bool isEnglish = DocumentDescriptor.IsEnglishFromTag(parentTn.Tag); if (isMaster || isEnglish) { TreeNode newCommentTvn = new TreeNode(data.Comment); newTvn.Nodes.Add(newCommentTvn); } else { TreeNode newCommentTvn = new TreeNode(data.TranslateComment); newTvn.Nodes.Add(newCommentTvn); } newTvn.Nodes[0].Name = "1"; newTvn.Nodes[1].Name = "2"; XDocument doc = DocumentDescriptor.DocFromTag(parentTn.Tag); // if we are combining a second document, we need to create a new element and add it to the resx document // note: otherwise we are just building the tree from the original document if (isCombining) { var newElement = new XElement("data"); var nameAttr = new XAttribute("name", data.KeyName); newElement.Add(nameAttr); var preserveAttr = new XAttribute(XNamespace.Xml + "space", "preserve"); newElement.Add(preserveAttr); var valueNode = new XElement("value", data.Text); newElement.Add(valueNode); if (isMaster || isEnglish) { var commentNode = new XElement("comment", data.Comment); newElement.Add(commentNode); } else { var commentNode = new XElement("comment", data.TranslateComment); newElement.Add(commentNode); } doc.Root.Add(newElement); } // we have either created a new element in the resx by combining, or are just building the tree // either way we want to save the document element in the treenode's tag. So find the // node (existing or newly created) in the resx file, and save it in the new treenode's tag var elems = doc.Root.Descendants("data").ToArray(); var elem = elems.Where(d => (string)d.FirstAttribute.Value == data.KeyName).FirstOrDefault(); newTvn.Tag = elem; }