public HeadingTreeNodeWrapper(HeadingsNavigator navigator, TreeNode node, TreeNode.Section section, HeadingTreeNodeWrapper parent) { m_parent = parent; m_navigator = navigator; m_isExpanded = false; m_TreeNodeHeading = null; m_TreeNodeLevel = null; m_Section = section; if ((node == null && m_Section == null) || m_navigator == null) { return; } CommandExpandAll = m_navigator.ViewModel.CommandExpandAll; CommandCollapseAll = m_navigator.ViewModel.CommandCollapseAll; Tuple <TreeNode, TreeNode> nodes = ComputeLevelNodes(node, m_Section); m_TreeNodeLevel = nodes.Item1; m_TreeNodeHeading = nodes.Item2; }
private static Tuple <TreeNode, TreeNode> ComputeLevelNodes(TreeNode node, TreeNode.Section section) { TreeNode level = null; TreeNode heading = null; if (section != null) { DebugFix.Assert(node == null); level = section.RealSectioningRootOrContent; heading = section.GetRealHeading(); } else { DebugFix.Assert(node != null); if (!node.HasXmlProperty) { #if NET40 return(new Tuple <TreeNode, TreeNode>(null, null)); #else return(new Tuple <TreeNode, TreeNode>()); #endif } string localName = node.GetXmlElementLocalName(); if (TreeNode.IsLevel(localName)) { level = node; if (level.Children.Count > 0) { TreeNode nd = level.Children.Get(0); if (nd != null) { localName = nd.HasXmlProperty ? nd.GetXmlElementLocalName() : null; if (localName != null && (localName == "pagenum" || localName == "img") && level.Children.Count > 1) { nd = level.Children.Get(1); if (nd != null) { localName = nd.GetXmlElementLocalName(); } } if (localName != null && (TreeNode.IsHeading(localName))) { heading = nd; } else { if (localName != null && (localName == "pagenum" || localName == "img") && level.Children.Count > 2) { nd = level.Children.Get(2); if (nd != null) { localName = nd.GetXmlElementLocalName(); } } if (localName != null && (TreeNode.IsHeading(localName))) { heading = nd; } } } } } else if (TreeNode.IsHeading(localName)) { heading = node; } } return(new Tuple <TreeNode, TreeNode>(level, heading)); }
private bool CheckMatches(TreeNode baseNode, TreeNode.Section section) { //TreeNode nody = WrappedTreeNode_Level ?? WrappedTreeNode_LevelHeading; //bool html5_outlining = nody.Presentation.RootNode.GetXmlElementLocalName().Equals("body", StringComparison.OrdinalIgnoreCase); bool bResult = false; if (section != null) { DebugFix.Assert(baseNode == null); foreach (var subSection in section.SubSections) { var tuple = ComputeLevelNodes(null, subSection); string sText = ComputeNodeText(tuple.Item1, tuple.Item2); if (string.IsNullOrEmpty(sText)) { continue; } bResult |= sText.IndexOf(m_navigator.SearchTerm, StringComparison.OrdinalIgnoreCase) >= 0; if (!bResult) { bResult |= CheckMatches(null, subSection); } if (bResult) { break; } } } else { DebugFix.Assert(baseNode != null); int n = m_navigator.GetChildCount(baseNode); for (int index = 0; index < n; index++) { TreeNode node = m_navigator.GetChild(baseNode, index); if (WrappedTreeNode_LevelHeading != null && WrappedTreeNode_LevelHeading == node) { continue; } var tuple = ComputeLevelNodes(node, null); string sText = ComputeNodeText(tuple.Item1, tuple.Item2); if (string.IsNullOrEmpty(sText)) { continue; } bResult |= sText.IndexOf(m_navigator.SearchTerm, StringComparison.OrdinalIgnoreCase) >= 0; if (!bResult) { bResult |= CheckMatches(node, null); } if (bResult) { break; } } } return(bResult); }