Browse Source

XamlBinding: ported outline content to AXml API

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4734 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 16 years ago
parent
commit
6adccfa490
  1. 33
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompilationUnitCreatorVisitor.cs
  2. 4
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs
  3. 4
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/DebugTimerObject.cs
  4. 22
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/NodeWrapper.cs
  5. 4
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/EditGridColumnsAndRowsDialog.xaml.cs
  6. 11
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/Utils.cs
  7. 2
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlBinding.csproj
  8. 2
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompilationUnit.cs
  9. 277
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineContentHost.xaml.cs
  10. 138
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineNode.cs
  11. 30
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParser.cs

33
src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompilationUnitCreatorVisitor.cs

@ -22,6 +22,7 @@ namespace ICSharpCode.XamlBinding @@ -22,6 +22,7 @@ namespace ICSharpCode.XamlBinding
AXmlDocument document;
IClass generatedClass;
IProjectContent projectContent;
Stack<NodeWrapper> nodeStack;
/// <summary>
/// string representation of the document, used to create DOM regions.
@ -38,6 +39,8 @@ namespace ICSharpCode.XamlBinding @@ -38,6 +39,8 @@ namespace ICSharpCode.XamlBinding
this.fileContent = fileContent;
this.lexerTags = lexerTags;
this.projectContent = projectContent;
this.nodeStack = new Stack<NodeWrapper>();
}
public override void VisitDocument(AXmlDocument document)
@ -93,6 +96,36 @@ namespace ICSharpCode.XamlBinding @@ -93,6 +96,36 @@ namespace ICSharpCode.XamlBinding
base.VisitTag(tag);
}
public override void VisitElement(AXmlElement element)
{
AXmlTag tag = element.Children.FirstOrDefault() as AXmlTag;
if (tag != null && tag.IsStartOrEmptyTag) {
NodeWrapper node = new NodeWrapper() {
ElementName = element.LocalName,
StartOffset = element.StartOffset,
EndOffset = element.EndOffset,
Name = element.GetAttributeValue("Name") ?? element.GetAttributeValue(CompletionDataHelper.XamlNamespace, "Name"),
Children = new List<NodeWrapper>()
};
if (CompilationUnit.TreeRootNode == null) {
CompilationUnit.TreeRootNode = node;
nodeStack.Push(CompilationUnit.TreeRootNode);
} else {
if (nodeStack.Count > 0)
nodeStack.Peek().Children.Add(node);
if (!tag.IsEmptyTag)
nodeStack.Push(node);
}
}
base.VisitElement(element);
if (tag != null && tag.IsStartTag)
nodeStack.PopOrDefault();
}
IClass AddClass(string className, AXmlElement element) {
DefaultClass c = new DefaultClass(CompilationUnit, className);
c.Modifiers = ModifierEnum.Partial;

4
src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs

@ -73,7 +73,7 @@ namespace ICSharpCode.XamlBinding @@ -73,7 +73,7 @@ namespace ICSharpCode.XamlBinding
public static XamlContext ResolveContext(ITextBuffer fileContent, string fileName, int offset)
{
using (new DebugTimerObject("ResolveContext")) {
//using (new DebugTimerObject("ResolveContext")) {
XamlParser parser = string.IsNullOrEmpty(fileName) ? new XamlParser() : ParserService.GetParser(fileName) as XamlParser;
ParseInformation info = string.IsNullOrEmpty(fileName) ? null : ParserService.GetParseInformation(fileName);
@ -188,7 +188,7 @@ namespace ICSharpCode.XamlBinding @@ -188,7 +188,7 @@ namespace ICSharpCode.XamlBinding
return context;
}
}
//}
}
public static XamlCompletionContext ResolveCompletionContext(ITextEditor editor, char typedValue)

4
src/AddIns/BackendBindings/XamlBinding/XamlBinding/DebugTimerObject.cs

@ -17,6 +17,8 @@ using ICSharpCode.Core; @@ -17,6 +17,8 @@ using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.XmlEditor;
#pragma warning disable 169
namespace ICSharpCode.XamlBinding
{
class DebugTimerObject : IDisposable
@ -43,3 +45,5 @@ namespace ICSharpCode.XamlBinding @@ -43,3 +45,5 @@ namespace ICSharpCode.XamlBinding
}
}
}
#pragma warning restore 169

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

@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/>
// <version>$Revision$</version>
// </file>
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; }
}
}

4
src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/EditGridColumnsAndRowsDialog.xaml.cs

@ -99,11 +99,11 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs @@ -99,11 +99,11 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
XAttribute b = element.Attribute(gridRowName);
int value;
if (a != null && int.TryParse(a.Value, out value))
element.SetAttributeValue(gridColName, Math.Min(Math.Max(0, value), maxCols - 1));
element.SetAttributeValue(gridColName, Utils.MinMax(value, 0, maxCols - 1));
else
element.SetAttributeValue(gridColName, 0);
if (b != null && int.TryParse(b.Value, out value))
element.SetAttributeValue(gridRowName, Math.Min(Math.Max(0, value), maxRows - 1));
element.SetAttributeValue(gridRowName, Utils.MinMax(value, 0, maxRows - 1));
else
element.SetAttributeValue(gridRowName, 0);
}

11
src/AddIns/BackendBindings/XamlBinding/XamlBinding/Utils.cs

@ -23,7 +23,7 @@ namespace ICSharpCode.XamlBinding @@ -23,7 +23,7 @@ namespace ICSharpCode.XamlBinding
/// Description of Utils.
/// </summary>
public static class Utils
{
{
public static MarkupExtensionInfo GetInnermostMarkupExtensionInfo(MarkupExtensionInfo info)
{
var lastNamed = info.NamedArguments.LastOrDefault();
@ -46,6 +46,11 @@ namespace ICSharpCode.XamlBinding @@ -46,6 +46,11 @@ namespace ICSharpCode.XamlBinding
return info;
}
public static int MinMax(int value, int lower, int upper)
{
return Math.Min(Math.Max(value, lower), upper);
}
static char[] whitespace = new char[] {' ', '\t', '\n', '\r'};
public static string GetXamlNamespacePrefix(XamlContext context)
@ -86,7 +91,7 @@ namespace ICSharpCode.XamlBinding @@ -86,7 +91,7 @@ namespace ICSharpCode.XamlBinding
public static Location GetLocationInfoFromOffset(string text, int offset)
{
string[] lines = text.Substring(0, offset).Split('\n');
string[] lines = text.Substring(0, MinMax(offset, 0, text.Length)).Split('\n');
string line = lines.LastOrDefault() ?? string.Empty;
return new Location(line.Length + 1, lines.Length);
@ -100,7 +105,7 @@ namespace ICSharpCode.XamlBinding @@ -100,7 +105,7 @@ namespace ICSharpCode.XamlBinding
/// <returns>
/// A string, if the at offset is the extension type. <br />
/// An AttributeValue, if at the offset is a positional argument. <br />
/// A KeyValuePair&lt;string, AttributeValue&gt;, if at the offset is a named argument.
/// A KeyValuePair&lt;string, AttributeValue>, if at the offset is a named argument.
/// </returns>
public static object GetMarkupDataAtPosition(MarkupExtensionInfo info, int offset)
{

2
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlBinding.csproj

@ -79,6 +79,7 @@ @@ -79,6 +79,7 @@
</Compile>
<Compile Include="MarkupExtensionTokenKind.cs">
</Compile>
<Compile Include="NodeWrapper.cs" />
<Compile Include="Options\CodeCompletion.xaml.cs">
<DependentUpon>CodeCompletion.xaml</DependentUpon>
<SubType>Code</SubType>
@ -145,6 +146,7 @@ @@ -145,6 +146,7 @@
<DependentUpon>XamlOutlineContentHost.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="XamlOutlineNode.cs" />
<Compile Include="XamlParser.cs" />
<Compile Include="XamlResolver.cs" />
<ProjectReference Include="..\..\..\..\Libraries\ICSharpCode.TextEditor\Project\ICSharpCode.TextEditor.csproj">

2
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompilationUnit.cs

@ -22,6 +22,8 @@ namespace ICSharpCode.XamlBinding @@ -22,6 +22,8 @@ namespace ICSharpCode.XamlBinding
: base(projectContent)
{
}
public NodeWrapper TreeRootNode { get; set; }
/// <summary>
/// Creates a IReturnType looking for a class referenced in XAML.

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

@ -5,25 +5,15 @@ @@ -5,25 +5,15 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.Core;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using System.Xml;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.TreeView;
namespace ICSharpCode.XamlBinding
{
@ -33,7 +23,6 @@ namespace ICSharpCode.XamlBinding @@ -33,7 +23,6 @@ namespace ICSharpCode.XamlBinding
public partial class XamlOutlineContentHost : DockPanel, IOutlineContentHost
{
ITextEditor editor;
Task updateTask;
DispatcherTimer timer;
public XamlOutlineContentHost(ITextEditor editor)
@ -51,72 +40,26 @@ namespace ICSharpCode.XamlBinding @@ -51,72 +40,26 @@ namespace ICSharpCode.XamlBinding
void XamlOutlineContentHostTick(object sender, EventArgs e)
{
if (updateTask != null && updateTask.Status == TaskStatus.Running)
updateTask.Wait();
updateTask = new Task(UpdateTask);
updateTask.Start();
}
void UpdateTask()
{
string content = WorkbenchSingleton.SafeThreadFunction(() => editor.Document.Text);
Stack<NodeWrapper> nodes = new Stack<NodeWrapper>();
NodeWrapper root = null;
if (this.editor == null || string.IsNullOrEmpty(this.editor.FileName))
return;
using (XmlTextReader reader = new XmlTextReader(new StringReader(content))) {
try {
while (reader.Read()) {
switch (reader.NodeType) {
case XmlNodeType.Element:
NodeWrapper node = new NodeWrapper() {
ElementName = reader.LocalName,
Line = reader.LineNumber,
Column = reader.LinePosition,
EndColumn = -1,
EndLine = -1,
Children = new List<NodeWrapper>()
};
if (reader.HasAttributes) {
string name = reader.GetAttribute("Name");
if (name == null)
name = reader.GetAttribute("Name", CompletionDataHelper.XamlNamespace);
if (name != null)
node.Name = name;
}
if (root == null) {
root = node;
nodes.Push(root);
} else {
if (nodes.Count > 0)
nodes.Peek().Children.Add(node);
if (!reader.IsEmptyElement)
nodes.Push(node);
}
break;
case XmlNodeType.EndElement:
if (nodes.Count > 1) {
NodeWrapper n = nodes.Pop();
n.EndLine = reader.LineNumber;
n.EndColumn = reader.LinePosition;
}
break;
}
}
} catch (XmlException) {
return;
}
WorkbenchSingleton.SafeThreadCall(() => UpdateTree(root));
}
ParseInformation info = ParserService.GetExistingParseInformation(this.editor.FileName);
if (info == null || !(info.CompilationUnit is XamlCompilationUnit))
return;
var cu = info.CompilationUnit as XamlCompilationUnit;
if (cu.TreeRootNode != null)
UpdateTree(cu.TreeRootNode);
}
void UpdateTree(NodeWrapper root)
{
if (this.treeView.Root == null)
this.treeView.Root = BuildNode(root);
else {
else
UpdateNode(this.treeView.Root as XamlOutlineNode, root);
}
}
void UpdateNode(XamlOutlineNode node, NodeWrapper dataNode)
@ -124,15 +67,8 @@ namespace ICSharpCode.XamlBinding @@ -124,15 +67,8 @@ namespace ICSharpCode.XamlBinding
if (dataNode != null && node != null) {
node.Name = dataNode.Name;
node.ElementName = dataNode.ElementName;
node.Marker = editor.Document.CreateAnchor(editor.Document.PositionToOffset(dataNode.Line, dataNode.Column));
ITextAnchor marker = null;
if (dataNode.EndLine != -1 && dataNode.EndColumn != -1) {
marker = editor.Document.CreateAnchor(editor.Document.PositionToOffset(dataNode.EndLine, dataNode.EndColumn));
}
node.EndMarker = marker;
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;
@ -152,18 +88,12 @@ namespace ICSharpCode.XamlBinding @@ -152,18 +88,12 @@ namespace ICSharpCode.XamlBinding
XamlOutlineNode BuildNode(NodeWrapper item)
{
ITextAnchor marker = null;
if (item.EndLine != -1 && item.EndColumn != -1) {
marker = editor.Document.CreateAnchor(editor.Document.PositionToOffset(item.EndLine, item.EndColumn));
}
XamlOutlineNode node = new XamlOutlineNode() {
Name = item.Name,
ElementName = item.ElementName,
ShowIcon = false,
Marker = editor.Document.CreateAnchor(editor.Document.PositionToOffset(item.Line, item.Column)),
EndMarker = marker,
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
};
@ -176,9 +106,7 @@ namespace ICSharpCode.XamlBinding @@ -176,9 +106,7 @@ namespace ICSharpCode.XamlBinding
void TreeViewMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
XamlOutlineNode node = treeView.SelectedItem as XamlOutlineNode;
int offset = editor.Document.PositionToOffset(node.Marker.Line, node.Marker.Column);
int endOffset = node.GetEndOffset();
editor.Select(offset - 1, endOffset - offset);
editor.Select(node.Marker.Offset, node.EndMarker.Offset - node.Marker.Offset);
}
public object OutlineContent {
@ -187,169 +115,4 @@ namespace ICSharpCode.XamlBinding @@ -187,169 +115,4 @@ namespace ICSharpCode.XamlBinding
}
}
}
class NodeWrapper {
public string ElementName { get; set; }
public string Name { get; set; }
public int Line { get; set; }
public int Column { get; set; }
public int EndLine { get; set; }
public int EndColumn { get; set; }
public IList<NodeWrapper> Children { get; set; }
}
class XamlOutlineNode : SharpTreeNode {
string elementName, name;
public string ElementName {
get { return elementName; }
set {
this.elementName = value;
this.RaisePropertyChanged("Text");
}
}
public string Name {
get { return name; }
set {
this.name = value;
this.RaisePropertyChanged("Text");
}
}
public ITextAnchor Marker { get; set; }
public ITextAnchor EndMarker { get; set; }
public ITextEditor Editor { get; set; }
public XamlOutlineNode Successor {
get {
if (this.Parent == null)
return null;
int index = this.Parent.Children.IndexOf(this);
if (index + 1 < this.Parent.Children.Count)
return this.Parent.Children[index + 1] as XamlOutlineNode;
else
return null;
}
}
public override bool CanDrag(SharpTreeNode[] nodes)
{
return nodes.All(node => node.Parent != null);
}
public override DropEffect CanDrop(IDataObject data, DropEffect requestedEffect)
{
return DropEffect.Move;
}
public override bool CanCopy(SharpTreeNode[] nodes)
{
return true;
}
public int GetEndOffset()
{
if (EndMarker != null) {
return EndMarker.Offset + ElementName.Length + 2;
} else {
XamlOutlineNode successor = Successor;
if (successor != null) {
return successor.Marker.Offset;
} else {
XamlOutlineNode parent = Parent as XamlOutlineNode;
if (parent != null)
return parent.EndMarker.Offset - 1;
}
}
return Editor.Document.TextLength + 1;
}
public string GetMarkupText()
{
int offset = Editor.Document.PositionToOffset(Marker.Line, Marker.Column);
return Editor.Document.GetText(offset - 1, GetEndOffset() - offset);
}
public override IDataObject Copy(SharpTreeNode[] nodes)
{
string[] data = nodes
.OfType<XamlOutlineNode>()
.Select(item => item.GetMarkupText())
.ToArray();
var dataObject = new DataObject();
dataObject.SetData(typeof(string[]), data);
return dataObject;
}
public override bool CanDelete(SharpTreeNode[] nodes)
{
return nodes.All(node => node.Parent != null);
}
public override void Drop(IDataObject data, int index, DropEffect finalEffect)
{
try {
string insertText = (data.GetData(typeof(string[])) as string[])
.Aggregate((text, part) => text += part);
ITextAnchor marker;
int length = 0;
if (index == this.Children.Count) {
if (index == 0)
marker = null;
else
marker = (this.Children[index - 1] as XamlOutlineNode).EndMarker;
if (marker == null) {
marker = this.EndMarker;
length = -1; // move backwards
} else {
length = 2 + (this.Children[index - 1] as XamlOutlineNode).elementName.Length;
}
} else
marker = (this.Children[index] as XamlOutlineNode).Marker;
int offset = marker.Offset + length;
Editor.Document.Insert(offset - 1, insertText);
} catch (Exception ex) {
throw ex;
}
}
public override void Delete(SharpTreeNode[] nodes)
{
DeleteCore(nodes);
}
public override void DeleteCore(SharpTreeNode[] nodes)
{
foreach (XamlOutlineNode node in nodes.OfType<XamlOutlineNode>()) {
node.Editor.Document.Remove(node.Marker.Offset - 1, node.GetEndOffset() - node.Marker.Offset);
}
}
ContextMenu menu;
public override ContextMenu GetContextMenu()
{
if (menu == null) {
menu = new ContextMenu();
menu.Items.Add(new MenuItem() { Command = ApplicationCommands.Cut });
menu.Items.Add(new MenuItem() { Command = ApplicationCommands.Copy });
menu.Items.Add(new MenuItem() { Command = ApplicationCommands.Paste });
menu.Items.Add(new Separator());
menu.Items.Add(new MenuItem() { Command = ApplicationCommands.Delete });
}
return menu;
}
public override object Text {
get { return (!string.IsNullOrEmpty(Name) ? ElementName + " (" + Name + ")" : ElementName); }
}
}
}

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

@ -0,0 +1,138 @@ @@ -0,0 +1,138 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.TreeView;
namespace ICSharpCode.XamlBinding
{
class XamlOutlineNode : SharpTreeNode {
string elementName, name;
public string ElementName {
get { return elementName; }
set {
this.elementName = value;
this.RaisePropertyChanged("Text");
}
}
public string Name {
get { return name; }
set {
this.name = value;
this.RaisePropertyChanged("Text");
}
}
public ITextAnchor Marker { get; set; }
public ITextAnchor EndMarker { get; set; }
public ITextEditor Editor { get; set; }
public override bool CanDrag(SharpTreeNode[] nodes)
{
return nodes.All(node => node.Parent != null);
}
public override DropEffect CanDrop(IDataObject data, DropEffect requestedEffect)
{
return DropEffect.Move;
}
public override bool CanCopy(SharpTreeNode[] nodes)
{
return true;
}
public string GetMarkupText()
{
return Editor.Document.GetText(Marker.Offset, EndMarker.Offset - Marker.Offset);
}
public override IDataObject Copy(SharpTreeNode[] nodes)
{
string[] data = nodes
.OfType<XamlOutlineNode>()
.Select(item => item.GetMarkupText())
.ToArray();
var dataObject = new DataObject();
dataObject.SetData(typeof(string[]), data);
return dataObject;
}
public override bool CanDelete(SharpTreeNode[] nodes)
{
return nodes.All(node => node.Parent != null);
}
public override void Drop(IDataObject data, int index, DropEffect finalEffect)
{
try {
string insertText = (data.GetData(typeof(string[])) as string[])
.Aggregate((text, part) => text += part);
ITextAnchor marker;
int length = 0;
if (index == this.Children.Count) {
if (index == 0)
marker = null;
else
marker = (this.Children[index - 1] as XamlOutlineNode).EndMarker;
if (marker == null) {
marker = this.EndMarker;
length = -1; // move backwards
} else {
length = 2 + (this.Children[index - 1] as XamlOutlineNode).elementName.Length;
}
} else
marker = (this.Children[index] as XamlOutlineNode).Marker;
int offset = marker.Offset + length;
Editor.Document.Insert(offset, insertText);
} catch (Exception ex) {
throw ex;
}
}
public override void Delete(SharpTreeNode[] nodes)
{
DeleteCore(nodes);
}
public override void DeleteCore(SharpTreeNode[] nodes)
{
foreach (XamlOutlineNode node in nodes.OfType<XamlOutlineNode>()) {
node.Editor.Document.Remove(node.Marker.Offset, node.EndMarker.Offset - node.Marker.Offset);
}
}
ContextMenu menu;
public override ContextMenu GetContextMenu()
{
if (menu == null) {
menu = new ContextMenu();
menu.Items.Add(new MenuItem() { Command = ApplicationCommands.Cut });
menu.Items.Add(new MenuItem() { Command = ApplicationCommands.Copy });
menu.Items.Add(new MenuItem() { Command = ApplicationCommands.Paste });
menu.Items.Add(new Separator());
menu.Items.Add(new MenuItem() { Command = ApplicationCommands.Delete });
}
return menu;
}
public override object Text {
get { return (!string.IsNullOrEmpty(Name) ? ElementName + " (" + Name + ")" : ElementName); }
}
}
}

30
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParser.cs

@ -72,13 +72,15 @@ namespace ICSharpCode.XamlBinding @@ -72,13 +72,15 @@ namespace ICSharpCode.XamlBinding
// Double check, now that we are thread-safe
if (lastParsedVersion == null || fileContent.Version == null || !fileContent.Version.BelongsToSameDocumentAs(lastVer)) {
// First parse or versioning not supported
parser.Parse(fileContent.Text, null);
using (new DebugTimerObject("normal parse"))
parser.Parse(fileContent.Text, null);
lastParsedVersion = fileContent.Version;
} else if (fileContent.Version.CompareAge(lastParsedVersion) > 0) {
// Incremental parse
var changes = lastParsedVersion.GetChangesTo(fileContent.Version).
Select(c => new DocumentChangeEventArgs(c.Offset, c.RemovedText, c.InsertedText));
parser.Parse(fileContent.Text, changes);
using (new DebugTimerObject("incremental parse"))
parser.Parse(fileContent.Text, changes);
lastParsedVersion = fileContent.Version;
} else {
// fileContent is older - no need to parse
@ -94,19 +96,19 @@ namespace ICSharpCode.XamlBinding @@ -94,19 +96,19 @@ namespace ICSharpCode.XamlBinding
public ICompilationUnit Parse(IProjectContent projectContent, string fileName, ITextBuffer fileContent)
{
using (new DebugTimerObject("background parser")) {
Core.LoggingService.Info("file: " + fileName);
using (ParseAndLock(fileContent)) {
var document = parser.LastDocument;
CompilationUnitCreatorVisitor visitor =
new CompilationUnitCreatorVisitor(projectContent, fileContent.Text, fileName, lexerTags);
document.AcceptVisitor(visitor);
return visitor.CompilationUnit;
}
//using (new DebugTimerObject("background parser")) {
// Core.LoggingService.Info("file: " + fileName);
using (ParseAndLock(fileContent)) {
var document = parser.LastDocument;
CompilationUnitCreatorVisitor visitor =
new CompilationUnitCreatorVisitor(projectContent, fileContent.Text, fileName, lexerTags);
document.AcceptVisitor(visitor);
return visitor.CompilationUnit;
}
//}
}
/// <summary>

Loading…
Cancel
Save