示例#1
0
 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;
         }
     }
 }
示例#2
0
        static public void CopyClipboardMissing(TreeView tv, bool missingOnly)
        {
            DocumentDescriptor desc = (DocumentDescriptor)tv.Nodes[0].Tag;
            XDocument          doc  = desc.Document;
            var d     = doc.Root.Elements("data");
            var lines = new List <string>();

            foreach (XElement e in d)
            {
                string name        = e.FirstAttribute.Value;
                var    valueNode   = e.Elements("value").FirstOrDefault();
                var    commentNode = e.Elements("comment").FirstOrDefault();
                if (!missingOnly || (missingOnly && (valueNode == null || valueNode.Value == "" || valueNode.Value.StartsWith("***"))))
                {
                    string valueText   = valueNode == null ? "NULL" : valueNode.Value;
                    string commentText = commentNode == null ? "NULL" : commentNode.Value;
                    lines.Add(name + '\t' + valueText + "\t" + commentText);
                }
            }
            StringBuilder sb = new StringBuilder();

            foreach (var line in lines)
            {
                sb.Append(line);
                sb.AppendLine();
            }
            Clipboard.SetText(sb.ToString(), TextDataFormat.UnicodeText);
        }
示例#3
0
        public static void AddResxToTreeView(bool isCombining, string baseResxFile, string addingResxFile, string language, TreeView treeView, bool generateMissing, bool merge, bool isMaster)
        {
            string baseResxFileLang   = LangToFileName(baseResxFile, language);
            string addingResxFileLang = LangToFileName(addingResxFile, language);

            // ensure file is created if generate missing is selected
            if (!File.Exists(baseResxFileLang))
            {
                if (generateMissing)
                {
                    File.Copy(baseResxFile, baseResxFileLang);
                }
                else
                {
                    return;
                }
            }

            string key = null;

            if (language != null) // working on language treeview
            {
                key = Path.GetFileName(baseResxFileLang);
            }
            else
            {
                key = Path.GetFileName(baseResxFile);
            }

            TreeNode  parentItem = treeView.Nodes[key];
            XDocument doc        = null;

            if (parentItem == null)
            {
                parentItem      = new TreeNode(Path.GetFileName(key));
                parentItem.Name = Path.GetFileName(key);
                doc             = XDocument.Load(addingResxFileLang);
                parentItem.Tag  = new DocumentDescriptor(doc, baseResxFileLang); // combining two files
                var d = doc.Root.Elements("data");
                MergeDocIntoTree(isCombining, merge, parentItem, d, isMaster);
                treeView.Nodes.Add(parentItem);
            }
            else
            {
                DocumentDescriptor dd = (DocumentDescriptor)parentItem.Tag;
                doc = dd.Document;
                var doc2 = XDocument.Load(addingResxFileLang);
                var d    = doc2.Root.Elements("data");
                MergeDocIntoTree(isCombining, merge, parentItem, d, isMaster);
            }
        }
示例#4
0
        static public void SaveAllFiles(TreeView tv1, TreeView tv2)
        {
            DocumentDescriptor desc     = (DocumentDescriptor)tv1.Nodes[0].Tag;
            XDocument          doc      = desc.Document;
            string             filename = desc.Filename;

            doc.Save(filename);
            foreach (TreeNode node in tv2.Nodes)
            {
                desc     = (DocumentDescriptor)node.Tag;
                doc      = desc.Document;
                filename = desc.Filename;
                doc.Save(filename);
            }
        }
示例#5
0
        public static void SaveFilesToJson(TreeView tv1, TreeView tv2)
        {
            DocumentDescriptor desc      = (DocumentDescriptor)tv1.Nodes[0].Tag;
            XDocument          doc       = desc.Document;
            string             filename  = desc.Filename;
            string             outputDir = Path.Combine(Path.GetDirectoryName(filename), "js");

            if (!Directory.Exists(outputDir))
            {
                Directory.CreateDirectory(outputDir);
            }
            ProcessFile(outputDir, filename);
            foreach (TreeNode node in tv2.Nodes)
            {
                desc     = (DocumentDescriptor)node.Tag;
                doc      = desc.Document;
                filename = desc.Filename;
                ProcessFile(outputDir, filename);
            }
        }
示例#6
0
        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);
        }
示例#7
0
        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;
        }
示例#8
0
        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);
        }
示例#9
0
        public static bool IsEnglishFromTag(object tag)
        {
            DocumentDescriptor desc = (DocumentDescriptor)tag;

            return(desc.IsEnglish);
        }
示例#10
0
        public static string FilenameFromTag(object tag)
        {
            DocumentDescriptor desc = (DocumentDescriptor)tag;

            return(desc.Filename);
        }
示例#11
0
        public static XDocument DocFromTag(object tag)
        {
            DocumentDescriptor desc = (DocumentDescriptor)tag;

            return(desc.Document);
        }