Browse Source

Remove whitespace from xml schema annotation displayed in completion tooltip.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5323 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Matt Ward 16 years ago
parent
commit
945a683791
  1. 76
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/SchemaDocumentation.cs
  2. 36
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletion.cs
  3. 1
      src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.csproj
  4. 58
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/ElementAnnotationWithWhitespaceTestFixture.cs
  5. 1
      src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj

76
src/AddIns/DisplayBindings/XmlEditor/Project/Src/SchemaDocumentation.cs

@ -0,0 +1,76 @@ @@ -0,0 +1,76 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Text;
using System.Xml;
using System.Xml.Schema;
namespace ICSharpCode.XmlEditor
{
public class SchemaDocumentation
{
XmlSchemaAnnotation annotation;
StringBuilder documentation = new StringBuilder();
StringBuilder documentationWithoutWhitespace = new StringBuilder();
public SchemaDocumentation(XmlSchemaAnnotation annotation)
{
this.annotation = annotation;
if (annotation != null) {
ReadDocumentationFromAnnotation(annotation.Items);
}
}
void ReadDocumentationFromAnnotation(XmlSchemaObjectCollection annotationItems)
{
foreach (XmlSchemaObject schemaObject in annotationItems) {
XmlSchemaDocumentation schemaDocumentation = schemaObject as XmlSchemaDocumentation;
if (schemaDocumentation != null) {
ReadSchemaDocumentationFromMarkup(schemaDocumentation.Markup);
}
}
RemoveWhitespaceFromDocumentation();
}
void ReadSchemaDocumentationFromMarkup(XmlNode[] markup)
{
foreach (XmlNode node in markup) {
XmlText textNode = node as XmlText;
AppendTextToDocumentation(textNode);
}
}
void AppendTextToDocumentation(XmlText textNode)
{
if (textNode != null) {
if (textNode.Data != null) {
documentation.Append(textNode.Data);
}
}
}
void RemoveWhitespaceFromDocumentation()
{
string[] lines = documentation.ToString().Split('\n');
RemoveWhitespaceFromLines(lines);
}
void RemoveWhitespaceFromLines(string[] lines)
{
foreach (string line in lines) {
string lineWithoutWhitespace = line.Trim();
documentationWithoutWhitespace.AppendLine(lineWithoutWhitespace);
}
}
public override string ToString()
{
return documentationWithoutWhitespace.ToString().Trim();
}
}
}

36
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletion.cs

@ -566,6 +566,11 @@ namespace ICSharpCode.XmlEditor @@ -566,6 +566,11 @@ namespace ICSharpCode.XmlEditor
}
}
static string GetDocumentation(XmlSchemaAnnotation annotation)
{
return new SchemaDocumentation(annotation).ToString();
}
/// <summary>
/// Adds an element completion data to the collection if it does not
/// already exist.
@ -588,37 +593,6 @@ namespace ICSharpCode.XmlEditor @@ -588,37 +593,6 @@ namespace ICSharpCode.XmlEditor
}
}
/// <summary>
/// Gets the documentation from the annotation element.
/// </summary>
/// <remarks>
/// All documentation elements are added. All text nodes inside
/// the documentation element are added.
/// </remarks>
static string GetDocumentation(XmlSchemaAnnotation annotation)
{
if (annotation != null) {
StringBuilder documentationBuilder = new StringBuilder();
foreach (XmlSchemaObject schemaObject in annotation.Items) {
XmlSchemaDocumentation schemaDocumentation = schemaObject as XmlSchemaDocumentation;
if (schemaDocumentation != null) {
foreach (XmlNode node in schemaDocumentation.Markup) {
XmlText textNode = node as XmlText;
if (textNode != null) {
if (textNode.Data != null) {
if (textNode.Data.Length > 0) {
documentationBuilder.Append(textNode.Data);
}
}
}
}
}
}
return documentationBuilder.ToString();
}
return String.Empty;
}
XmlCompletionItemCollection GetAttributeCompletion(XmlSchemaElement element)
{
XmlCompletionItemCollection completionItems = new XmlCompletionItemCollection();

1
src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.csproj

@ -111,6 +111,7 @@ @@ -111,6 +111,7 @@
<Compile Include="Src\RemoveAttributeCommand.cs" />
<Compile Include="Src\RemoveXPathHighlightingCommand.cs" />
<Compile Include="Src\RunXslTransformCommand.cs" />
<Compile Include="Src\SchemaDocumentation.cs" />
<Compile Include="Src\SelectXmlSchemaWindow.xaml.cs">
<DependentUpon>SelectXmlSchemaWindow.xaml</DependentUpon>
<SubType>Code</SubType>

58
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/ElementAnnotationWithWhitespaceTestFixture.cs

@ -0,0 +1,58 @@ @@ -0,0 +1,58 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop.Editor.CodeCompletion;
using ICSharpCode.XmlEditor;
using NUnit.Framework;
namespace XmlEditor.Tests.Schema
{
[TestFixture]
public class ElementAnnotationWithWhitespaceTestFixture : SchemaTestFixtureBase
{
XmlCompletionItemCollection fooChildElementCompletionItems;
XmlCompletionItemCollection rootElementCompletionItems;
public override void FixtureInit()
{
rootElementCompletionItems = SchemaCompletion.GetRootElementCompletion();
XmlElementPath path = new XmlElementPath();
path.AddElement(new QualifiedName("foo", "http://foo.com"));
fooChildElementCompletionItems = SchemaCompletion.GetChildElementCompletion(path);
}
[Test]
public void WhitespaceRemovedFromAnnotation()
{
string expectedText =
"First line\r\n" +
"Second line\r\n" +
"Third line\r\n" +
"Fourth line";
Assert.AreEqual(expectedText, rootElementCompletionItems[0].Description);
}
protected override string GetSchema()
{
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://foo.com\" xmlns=\"http://foo.com\" elementFormDefault=\"qualified\">\r\n" +
"\t<xs:element name=\"foo\">\r\n" +
"\t\t<xs:annotation>\r\n" +
"\t\t\t<xs:documentation>\r\n" +
"\t\t\tFirst line\r\n" +
"\t\t\tSecond line\r\n" +
" Third line\r\n" +
" Fourth line\r\n" +
"\t\t\t</xs:documentation>\r\n" +
"\t\t</xs:annotation>\r\n" +
"\t</xs:element>\r\n" +
"</xs:schema>";
}
}
}

1
src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj

@ -156,6 +156,7 @@ @@ -156,6 +156,7 @@
<Compile Include="Paths\TwoElementPathsByNamespaceTestFixture.cs" />
<Compile Include="Schema.Multiple\DuplicateSchemaNamespaceAddedToCollectionTestFixture.cs" />
<Compile Include="Schema.Multiple\TwoSchemaChildElementCompletionTestFixture.cs" />
<Compile Include="Schema\ElementAnnotationWithWhitespaceTestFixture.cs" />
<Compile Include="Schema\SchemaHasNamespaceTests.cs" />
<Compile Include="Schema\SingleElementSchemaTestFixture.cs" />
<Compile Include="Schema\ElementWithAttributeSchemaTestFixture.cs" />

Loading…
Cancel
Save