Browse Source

reimplemented XAML outline view

pull/59/merge
Siegfried Pammer 12 years ago
parent
commit
6ecf847cf7
  1. 18
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/NodeWrapper.cs
  2. 1
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlBinding.csproj
  3. 83
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineContentHost.xaml.cs
  4. 3
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineNode.cs
  5. 9
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlUnresolvedFile.cs

18
src/AddIns/BackendBindings/XamlBinding/XamlBinding/NodeWrapper.cs

@ -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<NodeWrapper> Children { get; set; }
}
}

1
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlBinding.csproj

@ -91,7 +91,6 @@
</Compile> </Compile>
<Compile Include="MarkupExtensionTokenKind.cs"> <Compile Include="MarkupExtensionTokenKind.cs">
</Compile> </Compile>
<Compile Include="NodeWrapper.cs" />
<Compile Include="Options\CodeCompletion.xaml.cs"> <Compile Include="Options\CodeCompletion.xaml.cs">
<DependentUpon>CodeCompletion.xaml</DependentUpon> <DependentUpon>CodeCompletion.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>

83
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) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using System.IO;
using System.Linq;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.NRefactory.Xml;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
@ -34,56 +37,64 @@ namespace ICSharpCode.XamlBinding
if (this.editor == null || !FileUtility.IsEqualFileName(this.editor.FileName, e.FileName)) if (this.editor == null || !FileUtility.IsEqualFileName(this.editor.FileName, e.FileName))
return; return;
#warning Reimplement XAML outline var parseInfo = e.NewParseInformation as XamlFullParseInformation;
// var cu = e.NewSyntaxTree as XamlSyntaxTree; if (parseInfo != null && parseInfo.Document != null)
// UpdateTree(parseInfo.Document);
// if (cu != null && cu.TreeRootNode != null)
// UpdateTree(cu.TreeRootNode);
} }
void UpdateTree(NodeWrapper root) void UpdateTree(AXmlDocument root)
{ {
if (this.treeView.Root == null) if (treeView.Root == null) {
this.treeView.Root = BuildNode(root); treeView.Root = new XamlOutlineNode {
else ElementName = "Document Root",
UpdateNode(this.treeView.Root as XamlOutlineNode, 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) { if (dataNode == null || node == null)
node.Name = dataNode.Name; return;
node.ElementName = dataNode.ElementName; if (dataNode is AXmlElement) {
node.Marker = editor.Document.CreateAnchor(Utils.MinMax(dataNode.StartOffset, 0, editor.Document.TextLength)); var item = (AXmlElement)dataNode;
node.EndMarker = editor.Document.CreateAnchor(Utils.MinMax(dataNode.EndOffset, 0, editor.Document.TextLength)); node.Name = item.GetAttributeValue("Name") ?? item.GetAttributeValue(XamlConst.XamlNamespace, "Name");
node.ElementName = item.Name;
int childrenCount = node.Children.Count; }
int dataCount = dataNode.Children.Count; 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));
for (int i = 0; i < Math.Max(childrenCount, dataCount); i++) {
if (i >= childrenCount) { var dataChildren = dataNode.Children.OfType<AXmlElement>().ToList();
node.Children.Add(BuildNode(dataNode.Children[i]));
} else if (i >= dataCount) { int childrenCount = node.Children.Count;
while (node.Children.Count > dataCount) int dataCount = dataChildren.Count;
node.Children.RemoveAt(dataCount);
} else { for (int i = 0; i < Math.Max(childrenCount, dataCount); i++) {
UpdateNode(node.Children[i] as XamlOutlineNode, dataNode.Children[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() { XamlOutlineNode node = new XamlOutlineNode {
Name = item.Name, Name = item.GetAttributeValue("Name") ?? item.GetAttributeValue(XamlConst.XamlNamespace, "Name"),
ElementName = item.ElementName, ElementName = item.Name,
Marker = editor.Document.CreateAnchor(Utils.MinMax(item.StartOffset, 0, editor.Document.TextLength - 1)), 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)), EndMarker = editor.Document.CreateAnchor(Utils.MinMax(item.EndOffset, 0, editor.Document.TextLength - 1)),
Editor = editor Editor = editor
}; };
foreach (var child in item.Children) foreach (var child in item.Children.OfType<AXmlElement>())
node.Children.Add(BuildNode(child)); node.Children.Add(BuildNode(child));
return node; return node;
@ -96,9 +107,7 @@ namespace ICSharpCode.XamlBinding
} }
public object OutlineContent { public object OutlineContent {
get { get { return this; }
return this;
}
} }
public void Dispose() public void Dispose()

3
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineNode.cs

@ -11,7 +11,8 @@ using ICSharpCode.TreeView;
namespace ICSharpCode.XamlBinding namespace ICSharpCode.XamlBinding
{ {
class XamlOutlineNode : SharpTreeNode { class XamlOutlineNode : SharpTreeNode
{
string elementName, name; string elementName, name;
public string ElementName { public string ElementName {

9
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlUnresolvedFile.cs

@ -31,9 +31,10 @@ namespace ICSharpCode.XamlBinding
public static XamlUnresolvedFile Create(FileName fileName, ITextSource fileContent, AXmlDocument document) public static XamlUnresolvedFile Create(FileName fileName, ITextSource fileContent, AXmlDocument document)
{ {
XamlUnresolvedFile file = new XamlUnresolvedFile(fileName); XamlUnresolvedFile file = new XamlUnresolvedFile(fileName);
ReadOnlyDocument textDocument = new ReadOnlyDocument(fileContent, fileName);
file.errors.AddRange(document.SyntaxErrors.Select(err => new Error(ErrorType.Error, err.Description))); file.errors.AddRange(document.SyntaxErrors.Select(err => new Error(ErrorType.Error, err.Description, textDocument.GetLocation(err.StartOffset))));
var visitor = new XamlDocumentVisitor(file, fileContent); var visitor = new XamlDocumentVisitor(file, textDocument);
visitor.VisitDocument(document); visitor.VisitDocument(document);
if (visitor.TypeDefinition != null) if (visitor.TypeDefinition != null)
file.topLevel = new[] { visitor.TypeDefinition }; file.topLevel = new[] { visitor.TypeDefinition };
@ -130,10 +131,10 @@ namespace ICSharpCode.XamlBinding
AXmlDocument currentDocument; AXmlDocument currentDocument;
ReadOnlyDocument textDocument; ReadOnlyDocument textDocument;
public XamlDocumentVisitor(IUnresolvedFile file, ITextSource fileContent) public XamlDocumentVisitor(IUnresolvedFile file, ReadOnlyDocument textDocument)
{ {
this.file = file; this.file = file;
textDocument = new ReadOnlyDocument(fileContent, file.FileName); this.textDocument = textDocument;
} }
public override void VisitDocument(AXmlDocument document) public override void VisitDocument(AXmlDocument document)

Loading…
Cancel
Save