diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/NodeWrapper.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/NodeWrapper.cs deleted file mode 100644 index d7b8335b8d..0000000000 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/NodeWrapper.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Collections.Generic; - -namespace ICSharpCode.XamlBinding -{ - public class NodeWrapper { - public string ElementName { get; set; } - public string Name { get; set; } - - public int StartOffset { get; set; } - public int EndOffset { get; set; } - - public IList Children { get; set; } - } -} diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlBinding.csproj b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlBinding.csproj index 975f82cfe2..b42dc3f77d 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlBinding.csproj +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlBinding.csproj @@ -91,7 +91,6 @@ - CodeCompletion.xaml Code diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineContentHost.xaml.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineContentHost.xaml.cs index e20bab95b9..e7345fdf25 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineContentHost.xaml.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineContentHost.xaml.cs @@ -2,10 +2,13 @@ // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; +using System.IO; +using System.Linq; using System.Windows.Controls; using System.Windows.Input; using ICSharpCode.Core; +using ICSharpCode.NRefactory.Xml; using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Gui; @@ -34,56 +37,64 @@ namespace ICSharpCode.XamlBinding if (this.editor == null || !FileUtility.IsEqualFileName(this.editor.FileName, e.FileName)) return; - #warning Reimplement XAML outline -// var cu = e.NewSyntaxTree as XamlSyntaxTree; -// -// if (cu != null && cu.TreeRootNode != null) -// UpdateTree(cu.TreeRootNode); + var parseInfo = e.NewParseInformation as XamlFullParseInformation; + if (parseInfo != null && parseInfo.Document != null) + UpdateTree(parseInfo.Document); } - void UpdateTree(NodeWrapper root) + void UpdateTree(AXmlDocument root) { - if (this.treeView.Root == null) - this.treeView.Root = BuildNode(root); - else - UpdateNode(this.treeView.Root as XamlOutlineNode, root); + if (treeView.Root == null) { + treeView.Root = new XamlOutlineNode { + ElementName = "Document Root", + Name = Path.GetFileName(editor.FileName), + Editor = editor + }; + } + + UpdateNode(treeView.Root as XamlOutlineNode, root); } - void UpdateNode(XamlOutlineNode node, NodeWrapper dataNode) + void UpdateNode(XamlOutlineNode node, AXmlObject 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]); - } + 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().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]); } } } - XamlOutlineNode BuildNode(NodeWrapper item) + XamlOutlineNode BuildNode(AXmlElement item) { - XamlOutlineNode node = new XamlOutlineNode() { - Name = item.Name, - ElementName = item.ElementName, + 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) + foreach (var child in item.Children.OfType()) node.Children.Add(BuildNode(child)); return node; @@ -96,9 +107,7 @@ namespace ICSharpCode.XamlBinding } public object OutlineContent { - get { - return this; - } + get { return this; } } public void Dispose() diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineNode.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineNode.cs index 5c209e9422..4498ae1172 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineNode.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineNode.cs @@ -11,7 +11,8 @@ using ICSharpCode.TreeView; namespace ICSharpCode.XamlBinding { - class XamlOutlineNode : SharpTreeNode { + class XamlOutlineNode : SharpTreeNode + { string elementName, name; public string ElementName { diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlUnresolvedFile.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlUnresolvedFile.cs index e1e4297054..f72284a4c8 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlUnresolvedFile.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlUnresolvedFile.cs @@ -31,9 +31,10 @@ namespace ICSharpCode.XamlBinding public static XamlUnresolvedFile Create(FileName fileName, ITextSource fileContent, AXmlDocument document) { XamlUnresolvedFile file = new XamlUnresolvedFile(fileName); + ReadOnlyDocument textDocument = new ReadOnlyDocument(fileContent, fileName); - file.errors.AddRange(document.SyntaxErrors.Select(err => new Error(ErrorType.Error, err.Description))); - var visitor = new XamlDocumentVisitor(file, fileContent); + file.errors.AddRange(document.SyntaxErrors.Select(err => new Error(ErrorType.Error, err.Description, textDocument.GetLocation(err.StartOffset)))); + var visitor = new XamlDocumentVisitor(file, textDocument); visitor.VisitDocument(document); if (visitor.TypeDefinition != null) file.topLevel = new[] { visitor.TypeDefinition }; @@ -130,10 +131,10 @@ namespace ICSharpCode.XamlBinding AXmlDocument currentDocument; ReadOnlyDocument textDocument; - public XamlDocumentVisitor(IUnresolvedFile file, ITextSource fileContent) + public XamlDocumentVisitor(IUnresolvedFile file, ReadOnlyDocument textDocument) { this.file = file; - textDocument = new ReadOnlyDocument(fileContent, file.FileName); + this.textDocument = textDocument; } public override void VisitDocument(AXmlDocument document)