Exemplo n.º 1
0
 public HierarchicalTocContent(HierarchicalTocContent source)
     : base(source)
 {
     _rootNode    = source._rootNode;
     _dicItems    = source._dicItems;
     _nodeCreated = source._nodeCreated;
 }
Exemplo n.º 2
0
        /// <summary>
        /// This reads and sets its state or attributes stored in a <c>XML</c> format
        /// with the given reader.
        /// </summary>
        /// <param name="reader">
        /// The reader with which the <c>XML</c> attributes of this object are accessed.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If the <paramref name="reader"/> is <see langword="null"/>.
        /// </exception>
        public override void ReadXml(XmlReader reader)
        {
            BuildExceptions.NotNull(reader, "reader");

            Debug.Assert(reader.NodeType == XmlNodeType.Element);
            if (reader.NodeType != XmlNodeType.Element)
            {
                return;
            }

            if (!String.Equals(reader.Name, TagName,
                               StringComparison.OrdinalIgnoreCase))
            {
                Debug.Assert(false, String.Format(
                                 "The element name '{0}' does not match the expected '{1}'.",
                                 reader.Name, TagName));
                return;
            }

            if (reader.IsEmptyElement)
            {
                return;
            }

            this.Clear();

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (String.Equals(reader.Name, HierarchicalTocItem.TagName,
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        HierarchicalTocItem item = new HierarchicalTocItem();
                        item.Content = this;
                        item.ReadXml(reader);

                        this.Add(item);
                    }
                    else if (String.Equals(reader.Name, HierarchicalTocNode.TagName,
                                           StringComparison.OrdinalIgnoreCase))
                    {
                        if (_rootNode == null)
                        {
                            _rootNode = new HierarchicalTocNode();
                        }

                        _rootNode.ReadXml(reader);
                    }
                }
                else if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (String.Equals(reader.Name, TagName,
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void BeginItems(string projectName, string projectFile)
        {
            _nodeCreated = true;
            _rootNode    = new HierarchicalTocNode(null,
                                                   String.IsNullOrEmpty(projectName) ? "(root)" : projectName);

            this.Clear();
        }
Exemplo n.º 4
0
        private void FillNodes()
        {
            if (this.Count == 0)
            {
                return;
            }

            int maxParts = 0;

            for (int i = 0; i < this.Count; i++)
            {
                maxParts = Math.Max(maxParts, this[i].Count);
            }

            // Add the first items...
            for (int j = 0; j < this.Count; j++)
            {
                HierarchicalTocItem item = this[j];
                if (item.Count > 0)
                {
                    HierarchicalTocNode node = _rootNode.FindByText(item[0], true);
                    if (node == null)
                    {
                        _rootNode.AddNode(item[0]);
                    }
                }
            }

            for (int i = 1; i < maxParts; i++)
            {
                for (int j = 0; j < this.Count; j++)
                {
                    HierarchicalTocItem item = this[j];
                    if (i < item.Count)
                    {
                        string parentText = item[i - 1];
                        string nodeText   = item[i];

                        HierarchicalTocNode parentNode =
                            _rootNode.FindByText(parentText, true);

                        if (parentNode != null)
                        {
                            HierarchicalTocNode node =
                                parentNode.FindByText(nodeText, true);
                            if (node == null)
                            {
                                parentNode.AddNode(nodeText);
                            }
                        }
                    }
                }
            }

            _rootNode.Sort(new HierarchicalTocNodeComparer(false), true);
        }