public static string GetText(TreeNode node) { TreeNode.StringChunkRange txtChunkRange = node.GetText(); TreeNode.StringChunk textLocal = txtChunkRange != null ? txtChunkRange.First : null; //node.GetTextChunk(); if (textLocal != null) { //DebugFix.Assert(textMedia.First.IsAbstractTextMedia); //DebugFix.Assert(range.Last == null); return(textLocal.Str); } //else //{ // QualifiedName qname = node.GetXmlElementQName(); // if (qname != null && qname.LocalName.Equals("img", StringComparison.OrdinalIgnoreCase)) // { // property.xml.XmlAttribute xmlAttr = node.GetXmlProperty().GetAttribute("alt"); // if (xmlAttr != null) // { // return xmlAttr.Value; // } // } //} return(null); }
private void OnBreadCrumbSeparatorClick(object sender, RoutedEventArgs e) { var ui = sender as Button; if (ui == null) { return; } var n = ui.Tag as TreeNode; if (n == null) { return; } if (ui.ContextMenu == null) { ui.ContextMenu = new ContextMenu(); foreach (TreeNode child in n.Children.ContentsAs_Enumerable) { bool childIsInPath = PathToCurrentTreeNode.Contains(child); MenuItem menuItem = null; string label = getTreeNodeLabel(child); if (child.HasXmlProperty) { menuItem = new MenuItem(); if (childIsInPath) { var runMenuItem = new Run(label) { FontWeight = FontWeights.ExtraBold }; var textBlock = new TextBlock(runMenuItem); //textBlock.SetValue(AutomationProperties.NameProperty, qnameChild.LocalName); menuItem.Header = textBlock; } else { menuItem.Header = label; } } else { TreeNode.StringChunkRange txtChunkRange = child.GetText(); TreeNode.StringChunk txtChunk = txtChunkRange != null ? txtChunkRange.First : null; //child.GetTextChunk(); bool isWhiteSpace = txtChunk != null && txtChunk.Str == @" "; if (!isWhiteSpace) { menuItem = new MenuItem(); if (childIsInPath) { var runMenuItem = new Run(label) { FontWeight = FontWeights.ExtraBold }; var textBlock = new TextBlock(runMenuItem); //textBlock.SetValue(AutomationProperties.NameProperty, "TXT"); menuItem.Header = textBlock; } else { menuItem.Header = label; } } } if (menuItem != null) { menuItem.Tag = child; menuItem.Click += menuItem_Click; ui.ContextMenu.Items.Add(menuItem); } } } ui.ContextMenu.PlacementTarget = ui; ui.ContextMenu.Placement = PlacementMode.Bottom; //ui.ContextMenu.PlacementRectangle=ui. ui.ContextMenu.IsOpen = true; //var node = (TreeNode)ui.Tag; //var popup = new Popup { IsOpen = false, Width = 120, Height = 150 }; //BreadcrumbPanel.Children.Add(popup); //popup.PlacementTarget = ui; //popup.LostFocus += OnPopupLostFocus; //popup.LostMouseCapture += OnPopupLostFocus; //popup.LostKeyboardFocus += OnPopupLostKeyboardFocus; //var listOfNodes = new ListView(); //listOfNodes.SelectionChanged += OnListOfNodesSelectionChanged; //foreach (TreeNode child in node.Children.ContentsAs_YieldEnumerable) //{ // listOfNodes.Items.Add(new TreeNodeWrapper() // { // Popup = popup, // TreeNode = child // }); //} //var scroll = new ScrollViewer //{ // HorizontalScrollBarVisibility = ScrollBarVisibility.Auto, // VerticalScrollBarVisibility = ScrollBarVisibility.Auto, // Content = listOfNodes //}; //popup.Child = scroll; //popup.IsOpen = true; //FocusHelper.FocusBeginInvoke(listOfNodes); }
private static void SetText(TreeNode node, string txt) { TreeNode.StringChunkRange txtChunkRange = node.GetText(); TreeNode.StringChunk textLocal = txtChunkRange != null ? txtChunkRange.First : null; //node.GetTextChunk(); DebugFix.Assert(textLocal != null); if (textLocal != null) { if (textLocal.IsAbstractTextMedia) { DebugFix.Assert(textLocal.m_TextMedia != null); #if DEBUG media.AbstractTextMedia textMedia = node.GetTextMedia(); DebugFix.Assert(textLocal.m_TextMedia == textMedia); #endif //DEBUG textLocal.m_TextMedia.Text = txt; } else { DebugFix.Assert(textLocal.m_XmlAttribute != null); #if DEBUG if (node.HasXmlProperty) { string localName = node.GetXmlElementLocalName(); bool isMath = localName.Equals("math", StringComparison.OrdinalIgnoreCase); if (localName.Equals("img", StringComparison.OrdinalIgnoreCase) || localName.Equals("video", StringComparison.OrdinalIgnoreCase) || isMath ) { urakawa.property.xml.XmlAttribute xmlAttr = node.GetXmlProperty().GetAttribute(isMath ? "alttext" : "alt"); if (xmlAttr != null) { DebugFix.Assert(textLocal.m_XmlAttribute == xmlAttr); } } else if (node.Children.Count == 0) { urakawa.property.xml.XmlAttribute xmlAttr = node.GetXmlProperty().GetAttribute("title"); if (xmlAttr != null) { DebugFix.Assert(textLocal.m_XmlAttribute == xmlAttr); } } } #endif //DEBUG textLocal.m_XmlAttribute.Value = txt; } DebugFix.Assert(textLocal.Str == txt); //DebugFix.Assert(textLocal.IsAbstractTextMedia); //DebugFix.Assert(range.Last == null); } //media.AbstractTextMedia textMedia = node.GetTextMedia(); //if (textMedia != null) //{ // textMedia.Text = txt; // TreeNode.StringChunk textLocal = node.GetTextMedia(true); // DebugFix.Assert(textLocal != null); // if (textLocal != null) // { // DebugFix.Assert(textLocal.Str == txt); // DebugFix.Assert(textLocal.IsAbstractTextMedia); // //DebugFix.Assert(range.Last == null); // } // return; //} //else //{ // QualifiedName qname = node.GetXmlElementQName(); // if (qname != null && qname.LocalName.Equals("img", StringComparison.OrdinalIgnoreCase)) // { // urakawa.property.xml.XmlAttribute xmlAttr = node.GetXmlProperty().GetAttribute("alt"); // if (xmlAttr != null) // { // xmlAttr.Value = txt; // TreeNode.StringChunk textLocal = node.GetTextMedia(true); // DebugFix.Assert(textLocal != null); // if (textLocal != null) // { // DebugFix.Assert(textLocal.Str == txt); // DebugFix.Assert(!textLocal.IsAbstractTextMedia); // //DebugFix.Assert(range.Last == null); // } // return; // } // } //} //Debug.Fail("WTF ??"); }