static public NodeData GetNodeData(TreeNode tNode, bool isMaster) { var nodeData = new NodeData(); if (tNode.Level == 2) { tNode = tNode.Parent; } if (tNode.Level == 0) { return(null); } var tnParent = tNode.Parent; bool isEnglish = DocumentDescriptor.IsEnglishFromTag(tnParent.Tag); XElement node = (XElement)tNode.Tag; switch (node.Name.LocalName) { case "value": case "comment": node = node.Parent; break; } nodeData.KeyName = node.Attribute("name").Value; nodeData.Text = node.Element("value").Value; XElement commentElem = node.Element("comment"); if (isMaster || isEnglish) { nodeData.Comment = commentElem != null ? commentElem.Value : ""; } else { nodeData.TranslateComment = commentElem != null ? commentElem.Value : ""; } return(nodeData); }
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; }
static public bool SetNodeData(NodeData data, TreeNode parentTn, bool isMaster) { if (parentTn.Level == 2) { parentTn = parentTn.Parent.Parent; } else if (parentTn.Level == 1) { parentTn = parentTn.Parent; } bool found = false; var tNode = parentTn.Nodes[data.KeyName]; if (tNode != null) { XElement xNode = (XElement)tNode.Tag; if (xNode == null) { return(found); } found = true; if (xNode.Element("comment") != null && xNode.Element("comment").Value == "TAPS not in Trima") { return(found); } var isEnglish = DocumentDescriptor.IsEnglishFromTag(parentTn.Tag); if (data.Text != "") { xNode.Element("value").Value = data.Text; } if (data.Text != "") { tNode.Nodes[0].Text = data.Text; tNode.Nodes[0].ForeColor = System.Drawing.Color.Red; tNode.ForeColor = System.Drawing.Color.Red; parentTn.ForeColor = System.Drawing.Color.Red; } if (isMaster || isEnglish) { if (data.Comment != null && data.Comment != "") { if (xNode.Element("comment") == null) { xNode.Add(new XElement("comment", data.Comment)); } else { xNode.Element("comment").Value = data.Comment; } tNode.Nodes[1].Text = data.Comment; tNode.Nodes[1].ForeColor = System.Drawing.Color.Red; tNode.ForeColor = System.Drawing.Color.Red; parentTn.ForeColor = System.Drawing.Color.Red; tNode.Nodes[0].Name = "1"; // for sorting tNode.Nodes[1].Name = "2"; } } else { if (data.TranslateComment != null && data.TranslateComment != "") { if (xNode.Element("comment") == null) { xNode.Add(new XElement("comment", data.TranslateComment)); } else { xNode.Element("comment").Value = data.TranslateComment; } tNode.Nodes[1].Text = data.TranslateComment; tNode.Nodes[1].ForeColor = System.Drawing.Color.Red; tNode.ForeColor = System.Drawing.Color.Red; parentTn.ForeColor = System.Drawing.Color.Red; tNode.Nodes[0].Name = "1"; // for sorting tNode.Nodes[1].Name = "2"; } } } return(found); }