From 6adccfa490bdcd03fa6f50103a62731cb6e86866 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 19 Aug 2009 07:41:16 +0000 Subject: [PATCH] XamlBinding: ported outline content to AXml API git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4734 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../CompilationUnitCreatorVisitor.cs | 33 +++ .../XamlBinding/CompletionDataHelper.cs | 4 +- .../XamlBinding/DebugTimerObject.cs | 4 + .../XamlBinding/XamlBinding/NodeWrapper.cs | 22 ++ .../EditGridColumnsAndRowsDialog.xaml.cs | 4 +- .../XamlBinding/XamlBinding/Utils.cs | 11 +- .../XamlBinding/XamlBinding.csproj | 2 + .../XamlBinding/XamlCompilationUnit.cs | 2 + .../XamlOutlineContentHost.xaml.cs | 277 ++---------------- .../XamlBinding/XamlOutlineNode.cs | 138 +++++++++ .../XamlBinding/XamlBinding/XamlParser.cs | 30 +- 11 files changed, 249 insertions(+), 278 deletions(-) create mode 100644 src/AddIns/BackendBindings/XamlBinding/XamlBinding/NodeWrapper.cs create mode 100644 src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineNode.cs diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompilationUnitCreatorVisitor.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompilationUnitCreatorVisitor.cs index 969b04afef..3466b44b05 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompilationUnitCreatorVisitor.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompilationUnitCreatorVisitor.cs @@ -22,6 +22,7 @@ namespace ICSharpCode.XamlBinding AXmlDocument document; IClass generatedClass; IProjectContent projectContent; + Stack nodeStack; /// /// string representation of the document, used to create DOM regions. @@ -38,6 +39,8 @@ namespace ICSharpCode.XamlBinding this.fileContent = fileContent; this.lexerTags = lexerTags; this.projectContent = projectContent; + + this.nodeStack = new Stack(); } public override void VisitDocument(AXmlDocument document) @@ -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() + }; + + 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; diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs index 5f1071a9d5..b455f904fa 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs @@ -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 return context; } - } + //} } public static XamlCompletionContext ResolveCompletionContext(ITextEditor editor, char typedValue) diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/DebugTimerObject.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/DebugTimerObject.cs index c93c48d9ff..ecb8539495 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/DebugTimerObject.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/DebugTimerObject.cs @@ -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 } } } + +#pragma warning restore 169 \ No newline at end of file diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/NodeWrapper.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/NodeWrapper.cs new file mode 100644 index 0000000000..9bbe2548cc --- /dev/null +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/NodeWrapper.cs @@ -0,0 +1,22 @@ +// +// +// +// +// $Revision$ +// + +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/PowerToys/Dialogs/EditGridColumnsAndRowsDialog.xaml.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/EditGridColumnsAndRowsDialog.xaml.cs index 140ef5b3a6..ad22453c1d 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/EditGridColumnsAndRowsDialog.xaml.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/EditGridColumnsAndRowsDialog.xaml.cs @@ -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); } diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/Utils.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/Utils.cs index b34a4fd036..904b2f72c1 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/Utils.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/Utils.cs @@ -23,7 +23,7 @@ namespace ICSharpCode.XamlBinding /// Description of Utils. /// public static class Utils - { + { public static MarkupExtensionInfo GetInnermostMarkupExtensionInfo(MarkupExtensionInfo info) { var lastNamed = info.NamedArguments.LastOrDefault(); @@ -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 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 /// /// A string, if the at offset is the extension type.
/// An AttributeValue, if at the offset is a positional argument.
- /// A KeyValuePair<string, AttributeValue>, if at the offset is a named argument. + /// A KeyValuePair<string, AttributeValue>, if at the offset is a named argument. ///
public static object GetMarkupDataAtPosition(MarkupExtensionInfo info, int offset) { diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlBinding.csproj b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlBinding.csproj index 48e168bc2d..992e7f78d7 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlBinding.csproj +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlBinding.csproj @@ -79,6 +79,7 @@ + CodeCompletion.xaml Code @@ -145,6 +146,7 @@ XamlOutlineContentHost.xaml Code + diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompilationUnit.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompilationUnit.cs index b3428bccf3..d2673873dc 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompilationUnit.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompilationUnit.cs @@ -22,6 +22,8 @@ namespace ICSharpCode.XamlBinding : base(projectContent) { } + + public NodeWrapper TreeRootNode { get; set; } /// /// Creates a IReturnType looking for a class referenced in XAML. diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineContentHost.xaml.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineContentHost.xaml.cs index 4df2c68743..e2afa75de8 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineContentHost.xaml.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineContentHost.xaml.cs @@ -5,25 +5,15 @@ // $Revision$ // -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 public partial class XamlOutlineContentHost : DockPanel, IOutlineContentHost { ITextEditor editor; - Task updateTask; DispatcherTimer timer; public XamlOutlineContentHost(ITextEditor editor) @@ -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 nodes = new Stack(); - 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() - }; - 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 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 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 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 } } } - - 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 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() - .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()) { - 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); } - } - } } \ No newline at end of file diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineNode.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineNode.cs new file mode 100644 index 0000000000..d003409bc4 --- /dev/null +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineNode.cs @@ -0,0 +1,138 @@ +// +// +// +// +// $Revision$ +// + +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() + .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()) { + 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); } + } + } +} diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParser.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParser.cs index 1be098c4dc..f236cb303d 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParser.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParser.cs @@ -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 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; } + //} } ///