Ejemplo n.º 1
0
 public PluginUI(PluginMain pluginMain)
 {
     this.pluginMain  = pluginMain;
     this.treeControl = new DataTreeControl();
     this.treeControl.Tree.BorderStyle = BorderStyle.None;
     this.treeControl.Resize          += new EventHandler(this.TreeControlResize);
     this.treeControl.Tree.Font        = PluginBase.Settings.DefaultFont;
     this.treeControl.Dock             = DockStyle.Fill;
     this.AutoScaleDimensions          = new System.Drawing.SizeF(6F, 13F);
     this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     this.Controls.Add(this.treeControl);
 }
        public string GetTreeAsText(ValueNode dataNode, string levelSep, DataTreeControl control, int levelLimit)
        {
            StringBuilder sb = new StringBuilder();

            // ensure expanded
            control.ListChildItems(dataNode);

            // add children nodes
            GetTreeItemsAsText(new List <Node> {
                dataNode
            }, new HashSet <string>(), levelSep, 0, sb, control, levelLimit);

            return(sb.ToString());
        }
        private void GetTreeItemsAsText(IList <Node> dataNodes, HashSet <string> visited, string levelSep, int level, StringBuilder sb, DataTreeControl control, int levelLimit)
        {
            // per node
            int len = dataNodes.Count;

            for (int c = 0; c < len; c++)
            {
                ValueNode child = (ValueNode)dataNodes[c];

                // skip if unwanted item
                if (!IsWantedChild(child))
                {
                    continue;
                }

                // ensure expanded
                if (!child.IsLeaf)
                {
                    control.ListChildItems(child);
                }

                // add node
                AppendTimes(sb, levelSep, level);

                // stop recursion if too long
                if (sb.Length > CopyTreeMaxChars)
                {
                    sb.AppendLine("......");
                    return;
                }

                if (child.IsPrimitive)
                {
                    sb.Append(child.Text + " : " + child.Value + " ");
                }
                else
                {
                    sb.Append(child.Text + " : " + child.ClassPath + " ");
                }

                // recurse for children .. but skip if unwanted items
                if (child.Nodes.Count > 0 && IsWantedParent(child))
                {
                    // opening brace
                    sb.AppendLine("{");

                    string childId = child.Id;

                    // add error if too many levels of recursion
                    if (level <= levelLimit || levelLimit == 0)
                    {
                        // check if encountered before
                        bool isNew = childId == "" || !visited.Contains(childId);
                        if (!isNew)
                        {
                            // error
                            AppendTimes(sb, levelSep, level + 1);
                            sb.AppendLine(String.Format(TextHelper.GetString("TreeExporter.DuplicatedObject"), child.Value));
                        }
                        else if (level > CopyTreeMaxRecursion)
                        {
                            // error
                            AppendTimes(sb, levelSep, level + 1);
                            sb.AppendLine(TextHelper.GetString("TreeExporter.MaxDepthReached"));
                        }
                        else
                        {
                            // add to list
                            if (childId != "")
                            {
                                visited.Add(childId);
                            }

                            // children
                            try
                            {
                                GetTreeItemsAsText(child.Nodes, visited, levelSep, level + 1, sb, control, levelLimit);
                            }
                            catch (Exception) { }
                        }
                    }

                    // closing brace
                    AppendTimes(sb, levelSep, level);
                    sb.AppendLine("}");
                }
                else
                {
                    sb.AppendLine();
                }
            }
        }