void CHelpSystemCore::MergeTopicsTree(
	CChm &chmRef, chmTopicsTreeIter chmBegin, chmTopicsTreeIter chmEnd,
	CTopicsTree * parent, CTopicsTree::CHILDREN &topicsTree
)
{
	for (; chmBegin != chmEnd; ++chmBegin)
	{
		const std::string *nodeTitle = &(*chmBegin)->title;
		CTopicsTree::CHILDREN::iterator node;
		// Search for node with same name.
		for (node = topicsTree.begin(); node != topicsTree.end(); ++node)
		{
			if (node->GetTitle() == *nodeTitle)
			{
				break;
			}
		}
		if (node == topicsTree.end())
		{
			topicsTree.push_back(CTopicsTree(parent, nodeTitle, NULL));
			node = topicsTree.end();
			--node;
		}
		if (!(*chmBegin)->path.empty())
		{
			if (node->GetDocument())
			{
				// TODO: Error! Can't merge nodes with non-empty topic.
			}
			else
			{
				CDocument * doc = chmRef.GetDocument(&(*chmBegin)->path);
				doc->SetTopicsTree(&(*node));
				node->SetDocument(doc);
			}
		}
		if (!(*chmBegin)->children.empty())
		{
			MergeTopicsTree(
				chmRef, (*chmBegin)->children.begin(), (*chmBegin)->children.end(),
				&(*node), node->GetChildren()
			);
		}
	}
}