Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 6adccfa

Browse files
XamlBinding: ported outline content to AXml API
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4734 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
1 parent 5b19084 commit 6adccfa

11 files changed

Lines changed: 249 additions & 278 deletions

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public sealed class CompilationUnitCreatorVisitor : AbstractAXmlVisitor
2222
AXmlDocument document;
2323
IClass generatedClass;
2424
IProjectContent projectContent;
25+
Stack<NodeWrapper> nodeStack;
2526

2627
/// <summary>
2728
/// string representation of the document, used to create DOM regions.
@@ -38,6 +39,8 @@ public CompilationUnitCreatorVisitor(IProjectContent projectContent, string file
3839
this.fileContent = fileContent;
3940
this.lexerTags = lexerTags;
4041
this.projectContent = projectContent;
42+
43+
this.nodeStack = new Stack<NodeWrapper>();
4144
}
4245

4346
public override void VisitDocument(AXmlDocument document)
@@ -93,6 +96,36 @@ public override void VisitTag(AXmlTag tag)
9396
base.VisitTag(tag);
9497
}
9598

99+
public override void VisitElement(AXmlElement element)
100+
{
101+
AXmlTag tag = element.Children.FirstOrDefault() as AXmlTag;
102+
103+
if (tag != null && tag.IsStartOrEmptyTag) {
104+
NodeWrapper node = new NodeWrapper() {
105+
ElementName = element.LocalName,
106+
StartOffset = element.StartOffset,
107+
EndOffset = element.EndOffset,
108+
Name = element.GetAttributeValue("Name") ?? element.GetAttributeValue(CompletionDataHelper.XamlNamespace, "Name"),
109+
Children = new List<NodeWrapper>()
110+
};
111+
112+
if (CompilationUnit.TreeRootNode == null) {
113+
CompilationUnit.TreeRootNode = node;
114+
nodeStack.Push(CompilationUnit.TreeRootNode);
115+
} else {
116+
if (nodeStack.Count > 0)
117+
nodeStack.Peek().Children.Add(node);
118+
if (!tag.IsEmptyTag)
119+
nodeStack.Push(node);
120+
}
121+
}
122+
123+
base.VisitElement(element);
124+
125+
if (tag != null && tag.IsStartTag)
126+
nodeStack.PopOrDefault();
127+
}
128+
96129
IClass AddClass(string className, AXmlElement element) {
97130
DefaultClass c = new DefaultClass(CompilationUnit, className);
98131
c.Modifiers = ModifierEnum.Partial;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static XamlContext ResolveContext(string text, string fileName, int offse
7373

7474
public static XamlContext ResolveContext(ITextBuffer fileContent, string fileName, int offset)
7575
{
76-
using (new DebugTimerObject("ResolveContext")) {
76+
//using (new DebugTimerObject("ResolveContext")) {
7777
XamlParser parser = string.IsNullOrEmpty(fileName) ? new XamlParser() : ParserService.GetParser(fileName) as XamlParser;
7878
ParseInformation info = string.IsNullOrEmpty(fileName) ? null : ParserService.GetParseInformation(fileName);
7979

@@ -188,7 +188,7 @@ public static XamlContext ResolveContext(ITextBuffer fileContent, string fileNam
188188

189189
return context;
190190
}
191-
}
191+
//}
192192
}
193193

194194
public static XamlCompletionContext ResolveCompletionContext(ITextEditor editor, char typedValue)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
using ICSharpCode.SharpDevelop.Editor;
1818
using ICSharpCode.XmlEditor;
1919

20+
#pragma warning disable 169
21+
2022
namespace ICSharpCode.XamlBinding
2123
{
2224
class DebugTimerObject : IDisposable
@@ -43,3 +45,5 @@ public void Dispose()
4345
}
4446
}
4547
}
48+
49+
#pragma warning restore 169
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// <file>
2+
// <copyright see="prj:///doc/copyright.txt"/>
3+
// <license see="prj:///doc/license.txt"/>
4+
// <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/>
5+
// <version>$Revision$</version>
6+
// </file>
7+
8+
using System;
9+
using System.Collections.Generic;
10+
11+
namespace ICSharpCode.XamlBinding
12+
{
13+
public class NodeWrapper {
14+
public string ElementName { get; set; }
15+
public string Name { get; set; }
16+
17+
public int StartOffset { get; set; }
18+
public int EndOffset { get; set; }
19+
20+
public IList<NodeWrapper> Children { get; set; }
21+
}
22+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ static void NormalizeElementGridIndices(XElement element, int maxCols, int maxRo
9999
XAttribute b = element.Attribute(gridRowName);
100100
int value;
101101
if (a != null && int.TryParse(a.Value, out value))
102-
element.SetAttributeValue(gridColName, Math.Min(Math.Max(0, value), maxCols - 1));
102+
element.SetAttributeValue(gridColName, Utils.MinMax(value, 0, maxCols - 1));
103103
else
104104
element.SetAttributeValue(gridColName, 0);
105105
if (b != null && int.TryParse(b.Value, out value))
106-
element.SetAttributeValue(gridRowName, Math.Min(Math.Max(0, value), maxRows - 1));
106+
element.SetAttributeValue(gridRowName, Utils.MinMax(value, 0, maxRows - 1));
107107
else
108108
element.SetAttributeValue(gridRowName, 0);
109109
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace ICSharpCode.XamlBinding
2323
/// Description of Utils.
2424
/// </summary>
2525
public static class Utils
26-
{
26+
{
2727
public static MarkupExtensionInfo GetInnermostMarkupExtensionInfo(MarkupExtensionInfo info)
2828
{
2929
var lastNamed = info.NamedArguments.LastOrDefault();
@@ -46,6 +46,11 @@ public static MarkupExtensionInfo GetInnermostMarkupExtensionInfo(MarkupExtensio
4646
return info;
4747
}
4848

49+
public static int MinMax(int value, int lower, int upper)
50+
{
51+
return Math.Min(Math.Max(value, lower), upper);
52+
}
53+
4954
static char[] whitespace = new char[] {' ', '\t', '\n', '\r'};
5055

5156
public static string GetXamlNamespacePrefix(XamlContext context)
@@ -86,7 +91,7 @@ public static int GetOffsetFromFilePos(string content, int line, int col)
8691

8792
public static Location GetLocationInfoFromOffset(string text, int offset)
8893
{
89-
string[] lines = text.Substring(0, offset).Split('\n');
94+
string[] lines = text.Substring(0, MinMax(offset, 0, text.Length)).Split('\n');
9095
string line = lines.LastOrDefault() ?? string.Empty;
9196

9297
return new Location(line.Length + 1, lines.Length);
@@ -100,7 +105,7 @@ public static Location GetLocationInfoFromOffset(string text, int offset)
100105
/// <returns>
101106
/// A string, if the at offset is the extension type. <br />
102107
/// An AttributeValue, if at the offset is a positional argument. <br />
103-
/// A KeyValuePair&lt;string, AttributeValue&gt;, if at the offset is a named argument.
108+
/// A KeyValuePair&lt;string, AttributeValue>, if at the offset is a named argument.
104109
/// </returns>
105110
public static object GetMarkupDataAtPosition(MarkupExtensionInfo info, int offset)
106111
{

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
</Compile>
8080
<Compile Include="MarkupExtensionTokenKind.cs">
8181
</Compile>
82+
<Compile Include="NodeWrapper.cs" />
8283
<Compile Include="Options\CodeCompletion.xaml.cs">
8384
<DependentUpon>CodeCompletion.xaml</DependentUpon>
8485
<SubType>Code</SubType>
@@ -145,6 +146,7 @@
145146
<DependentUpon>XamlOutlineContentHost.xaml</DependentUpon>
146147
<SubType>Code</SubType>
147148
</Compile>
149+
<Compile Include="XamlOutlineNode.cs" />
148150
<Compile Include="XamlParser.cs" />
149151
<Compile Include="XamlResolver.cs" />
150152
<ProjectReference Include="..\..\..\..\Libraries\ICSharpCode.TextEditor\Project\ICSharpCode.TextEditor.csproj">

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public XamlCompilationUnit(IProjectContent projectContent)
2222
: base(projectContent)
2323
{
2424
}
25+
26+
public NodeWrapper TreeRootNode { get; set; }
2527

2628
/// <summary>
2729
/// Creates a IReturnType looking for a class referenced in XAML.

0 commit comments

Comments
 (0)