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

61
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineContentHost.xaml.cs

@ -2,10 +2,13 @@ @@ -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 @@ -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
};
}
void UpdateNode(XamlOutlineNode node, NodeWrapper dataNode)
UpdateNode(treeView.Root as XamlOutlineNode, root);
}
void UpdateNode(XamlOutlineNode node, AXmlObject dataNode)
{
if (dataNode != null && node != null) {
node.Name = dataNode.Name;
node.ElementName = dataNode.ElementName;
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 = dataNode.Children.Count;
int dataCount = dataChildren.Count;
for (int i = 0; i < Math.Max(childrenCount, dataCount); i++) {
if (i >= childrenCount) {
node.Children.Add(BuildNode(dataNode.Children[i]));
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, dataNode.Children[i]);
}
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<AXmlElement>())
node.Children.Add(BuildNode(child));
return node;
@ -96,9 +107,7 @@ namespace ICSharpCode.XamlBinding @@ -96,9 +107,7 @@ namespace ICSharpCode.XamlBinding
}
public object OutlineContent {
get {
return this;
}
get { return this; }
}
public void Dispose()

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

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

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

@ -31,9 +31,10 @@ namespace ICSharpCode.XamlBinding @@ -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 @@ -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)

Loading…
Cancel
Save