void UpdateNode(XamlOutlineNode node, AXmlObject dataNode) { if (dataNode == null || node == null) return; if (dataNode is AXmlElement) { var item = (AXmlElement)dataNode; node.Name = item.GetAttributeValue("Name") ?? item.GetAttributeValue(XamlConst.XamlNamespace, "Name"); node.ElementName = item.Name; } node.Marker = editor.Document.CreateAnchor(Utils.MinMax(dataNode.StartOffset, 0, editor.Document.TextLength)); node.EndMarker = editor.Document.CreateAnchor(Utils.MinMax(dataNode.EndOffset, 0, editor.Document.TextLength)); var dataChildren = dataNode.Children.OfType<AXmlElement>().ToList(); int childrenCount = node.Children.Count; int dataCount = dataChildren.Count; for (int i = 0; i < Math.Max(childrenCount, dataCount); i++) { if (i >= childrenCount) { node.Children.Add(BuildNode(dataChildren[i])); } else if (i >= dataCount) { while (node.Children.Count > dataCount) node.Children.RemoveAt(dataCount); } else { UpdateNode(node.Children[i] as XamlOutlineNode, dataChildren[i]); } } }
void UpdateNode(XamlOutlineNode node, NodeWrapper dataNode) { if (dataNode != null && node != null) { node.Name = dataNode.Name; node.ElementName = dataNode.ElementName; node.Marker = editor.Document.CreateAnchor(Utils.MinMax(dataNode.StartOffset, 0, editor.Document.TextLength)); node.EndMarker = editor.Document.CreateAnchor(Utils.MinMax(dataNode.EndOffset, 0, editor.Document.TextLength)); int childrenCount = node.Children.Count; int dataCount = dataNode.Children.Count; for (int i = 0; i < Math.Max(childrenCount, dataCount); i++) { if (i >= childrenCount) { node.Children.Add(BuildNode(dataNode.Children[i])); } else if (i >= dataCount) { while (node.Children.Count > dataCount) { node.Children.RemoveAt(dataCount); } } else { UpdateNode(node.Children[i] as XamlOutlineNode, dataNode.Children[i]); } } } }
void TreeViewMouseDoubleClick(object sender, MouseButtonEventArgs e) { XamlOutlineNode node = treeView.SelectedItem as XamlOutlineNode; if (node == null) { return; } editor.Select(node.Marker.Offset, node.EndMarker.Offset - node.Marker.Offset); }
XamlOutlineNode BuildNode(NodeWrapper item) { XamlOutlineNode node = new XamlOutlineNode() { Name = item.Name, ElementName = item.ElementName, Marker = editor.Document.CreateAnchor(Utils.MinMax(item.StartOffset, 0, editor.Document.TextLength - 1)), EndMarker = editor.Document.CreateAnchor(Utils.MinMax(item.EndOffset, 0, editor.Document.TextLength - 1)), Editor = editor }; foreach (var child in item.Children) node.Children.Add(BuildNode(child)); return node; }
XamlOutlineNode BuildNode(AXmlElement item) { XamlOutlineNode node = new XamlOutlineNode { Name = item.GetAttributeValue("Name") ?? item.GetAttributeValue(XamlConst.XamlNamespace, "Name"), ElementName = item.Name, Marker = editor.Document.CreateAnchor(Utils.MinMax(item.StartOffset, 0, editor.Document.TextLength - 1)), EndMarker = editor.Document.CreateAnchor(Utils.MinMax(item.EndOffset, 0, editor.Document.TextLength - 1)), Editor = editor }; foreach (var child in item.Children.OfType <AXmlElement>()) { node.Children.Add(BuildNode(child)); } return(node); }
XamlOutlineNode BuildNode(NodeWrapper item) { XamlOutlineNode node = new XamlOutlineNode() { Name = item.Name, ElementName = item.ElementName, Marker = editor.Document.CreateAnchor(Utils.MinMax(item.StartOffset, 0, editor.Document.TextLength - 1)), EndMarker = editor.Document.CreateAnchor(Utils.MinMax(item.EndOffset, 0, editor.Document.TextLength - 1)), Editor = editor }; foreach (var child in item.Children) { node.Children.Add(BuildNode(child)); } return(node); }
void UpdateNode(XamlOutlineNode node, AXmlObject dataNode) { if (dataNode == null || node == null) { return; } if (dataNode is AXmlElement) { var item = (AXmlElement)dataNode; node.Name = item.GetAttributeValue("Name") ?? item.GetAttributeValue(XamlConst.XamlNamespace, "Name"); node.ElementName = item.Name; } node.Marker = editor.Document.CreateAnchor(Utils.MinMax(dataNode.StartOffset, 0, editor.Document.TextLength)); node.EndMarker = editor.Document.CreateAnchor(Utils.MinMax(dataNode.EndOffset, 0, editor.Document.TextLength)); var dataChildren = dataNode.Children.OfType <AXmlElement>().ToList(); int childrenCount = node.Children.Count; int dataCount = dataChildren.Count; for (int i = 0; i < Math.Max(childrenCount, dataCount); i++) { if (i >= childrenCount) { node.Children.Add(BuildNode(dataChildren[i])); } else if (i >= dataCount) { while (node.Children.Count > dataCount) { node.Children.RemoveAt(dataCount); } } else { UpdateNode(node.Children[i] as XamlOutlineNode, dataChildren[i]); } } }
void UpdateNode(XamlOutlineNode node, NodeWrapper dataNode) { if (dataNode != null && node != null) { node.Name = dataNode.Name; node.ElementName = dataNode.ElementName; node.Marker = editor.Document.CreateAnchor(Utils.MinMax(dataNode.StartOffset, 0, editor.Document.TextLength)); node.EndMarker = editor.Document.CreateAnchor(Utils.MinMax(dataNode.EndOffset, 0, editor.Document.TextLength)); int childrenCount = node.Children.Count; int dataCount = dataNode.Children.Count; for (int i = 0; i < Math.Max(childrenCount, dataCount); i++) { if (i >= childrenCount) { node.Children.Add(BuildNode(dataNode.Children[i])); } else if (i >= dataCount) { while (node.Children.Count > dataCount) node.Children.RemoveAt(dataCount); } else { UpdateNode(node.Children[i] as XamlOutlineNode, dataNode.Children[i]); } } } }
XamlOutlineNode BuildNode(AXmlElement item) { XamlOutlineNode node = new XamlOutlineNode { Name = item.GetAttributeValue("Name") ?? item.GetAttributeValue(XamlConst.XamlNamespace, "Name"), ElementName = item.Name, Marker = editor.Document.CreateAnchor(Utils.MinMax(item.StartOffset, 0, editor.Document.TextLength - 1)), EndMarker = editor.Document.CreateAnchor(Utils.MinMax(item.EndOffset, 0, editor.Document.TextLength - 1)), Editor = editor }; foreach (var child in item.Children.OfType<AXmlElement>()) node.Children.Add(BuildNode(child)); return node; }
void SelectActiveTreeNode() { if (!optionSelectActiveTreeNode) return; // prevent unnecessary looping, when both CaretLocationChanged and ParseUpdateChanged are fired. if (this.lastCaretLocation.HasValue && this.lastCaretLocation == this.editor.Caret.Location) return; this.lastCaretLocation = this.editor.Caret.Location; selectedNode = null; FindNodeFromLocation(this.editor.Caret.Location, treeView.Root as XamlOutlineNode); if (selectedNode != null && treeView.SelectedItem != selectedNode) { treeView.SelectedItem = selectedNode; if (!scrollToNodeTimer.IsEnabled) { scrollToNodeTimer.Start(); } } }
public void Dispose() { SD.ParserService.ParseInformationUpdated -= ParseInfoUpdated; if (this.editor != null) { if (this.editor.Caret != null) this.editor.Caret.LocationChanged -= CaretLocationChanged; this.editor = null; } this.document = null; this.lastCaretLocation = null; this.selectedNode = null; if (this.updateTreeTimer != null) { this.updateTreeTimer.Stop(); this.updateTreeTimer.Tick -= this.UpdateTreeTimer_Tick; this.updateTreeTimer = null; } if (this.scrollToNodeTimer != null) { this.scrollToNodeTimer.Stop(); this.scrollToNodeTimer.Tick -= this.ScrollToNodeTimer_Tick; this.scrollToNodeTimer = null; } }
XamlOutlineNode BuildNode(AXmlElement item) { XamlOutlineNode node = new XamlOutlineNode { Name = item.GetAttributeValue("Name") ?? item.GetAttributeValue(XamlConst.XamlNamespace, "Name"), ElementName = item.Name, StartMarker = editor.Document.CreateAnchor(Utils.MinMax(item.StartOffset, 0, editor.Document.TextLength - 1)), EndMarker = editor.Document.CreateAnchor(Utils.MinMax(item.EndOffset, 0, editor.Document.TextLength - 1)), Editor = editor, XmlNodeItem = item }; node.StartLocation = new TextLocation(node.StartMarker.Line, node.StartMarker.Column); node.EndLocation = new TextLocation(node.EndMarker.Line, node.EndMarker.Column); node.IsExpanded = true; foreach (var child in item.Children.OfType<AXmlElement>()) node.Children.Add(BuildNode(child)); return node; }
void FindNodeFromLocation(TextLocation location, XamlOutlineNode node) { if (node == null) return; if (node.StartMarker.IsDeleted || node.EndMarker.IsDeleted) return; if (location.IsInside(node.StartMarker.Location, node.EndMarker.Location) && (selectedNode == null || IsRangeInside(selectedNode.StartLocation, selectedNode.EndLocation, node.StartLocation, node.EndLocation))) { selectedNode = node; } foreach(var child in node.Children) { FindNodeFromLocation(location, child as XamlOutlineNode); } }