Browse Source
Fixed some bugs. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@312 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
90 changed files with 16327 additions and 36 deletions
@ -0,0 +1,175 @@
@@ -0,0 +1,175 @@
|
||||
Xml Intellisense |
||||
---------------- |
||||
|
||||
In order to be able to provide intellisense for an xml document we need a schema. From the schema we can determine an element's attributes and its child elements. Without resorting to writing our own xml schema parser, can we retrieve this information from the schema? |
||||
|
||||
XmlSchema class |
||||
--------------- |
||||
|
||||
The .Net framework provides us with the XmlSchema class. It provides us with two methods that of interest to us when reading rather than creating an xml schema. |
||||
|
||||
1) Read - Reads an XML Schema definition language (XSD) schema. |
||||
|
||||
2) Compile - Compiles the XML Schema definition language (XSD) Schema Object Model (SOM) into schema information for validation. Used to check the syntactic and semantic structure of the programmatically-built SOM. Semantic validation checking is performed during compilation. |
||||
|
||||
Let us first look at the Read method and see what we can get from it. |
||||
|
||||
The read method seems to do a first parse of the schema, the XmlSchema.Elements property is not populated, about the only thing that is populated is the Items property, which seems to be pretty much a mirror image of what is in the xsd file. |
||||
|
||||
Quickstart sample from Microsoft |
||||
-------------------------------- |
||||
|
||||
XmlSchemaObjectModel sample |
||||
|
||||
http://go.microsoft.com/fwlink/?linkid=3268&url=/quickstart/howto/doc/XML/XmlSchemaObjectModel.aspx |
||||
|
||||
A sample provided by Microsoft adds two schemas to an XmlSchemaCollection, outputs the schema xsd based on what was read in, then generates an xml documentrepresentative of the read in schema. |
||||
|
||||
XmlNameTable myXmlNameTable = new NameTable(); |
||||
XmlSchemaCollection myXmlSchemaCollection = new XmlSchemaCollection(myXmlNameTable); |
||||
myXmlSchemaCollection.Add(null, "books.xsd"); |
||||
myXmlSchemaCollection.Add(null, "poschema.xsd"); |
||||
|
||||
foreach(XmlSchema myTempXmlSchema in myXmlSchemaCollection) |
||||
{ |
||||
myXmlSchema = myTempXmlSchema; |
||||
|
||||
// Write out the various schema parts |
||||
WriteXSDSchema(); |
||||
|
||||
// Write out an example of the XML for the schema |
||||
WriteExample(); |
||||
|
||||
} |
||||
|
||||
|
||||
void WriteXSDSchema() |
||||
{ |
||||
myXmlTextWriter.WriteStartElement("schema", XmlSchema.Namespace); |
||||
myXmlTextWriter.WriteAttributeString("targetNamespace", myXmlSchema.TargetNamespace); |
||||
foreach(XmlSchemaInclude include in myXmlSchema.Includes) |
||||
{ |
||||
myXmlTextWriter.WriteStartElement("include", XmlSchema.Namespace); |
||||
myXmlTextWriter.WriteAttributeString("schemaLocation", include.SchemaLocation); |
||||
myXmlTextWriter.WriteEndElement(); |
||||
} |
||||
|
||||
foreach(object item in myXmlSchema.Items) |
||||
{ |
||||
if (item is XmlSchemaAttribute) |
||||
WriteXmlSchemaAttribute((XmlSchemaAttribute)item); //attribute |
||||
else if (item is XmlSchemaComplexType) |
||||
WriteXmlSchemaComplexType((XmlSchemaComplexType)item); //complexType |
||||
else if (item is XmlSchemaSimpleType) |
||||
WriteXmlSchemaSimpleType((XmlSchemaSimpleType)item); //simpleType |
||||
else if (item is XmlSchemaElement) |
||||
WriteXmlSchemaElement((XmlSchemaElement)item); //element |
||||
else if (item is XmlSchemaAnnotation) |
||||
WriteXmlSchemaAnnotation((XmlSchemaAnnotation)item); //annotation |
||||
else if (item is XmlSchemaAttributeGroup) |
||||
WriteXmlSchemaAttributeGroup((XmlSchemaAttributeGroup)item); //attributeGroup |
||||
else if (item is XmlSchemaNotation) |
||||
WriteXmlSchemaNotation((XmlSchemaNotation)item); //notation |
||||
else if (item is XmlSchemaGroup) |
||||
WriteXmlSchemaGroup((XmlSchemaGroup)item); //group |
||||
else |
||||
Console.WriteLine("Not Implemented."); |
||||
} |
||||
myXmlTextWriter.WriteEndElement(); |
||||
} |
||||
|
||||
// Write out the example of the XSD usage |
||||
void WriteExample() |
||||
{ |
||||
foreach(XmlSchemaElement element in myXmlSchema.Elements.Values) |
||||
WriteExampleElement(element); |
||||
} |
||||
|
||||
// Write some example elements |
||||
void WriteExampleElement(XmlSchemaElement element) |
||||
{ |
||||
myXmlTextWriter.WriteStartElement(element.QualifiedName.Name, element.QualifiedName.Namespace); |
||||
if (element.ElementType is XmlSchemaComplexType) |
||||
{ |
||||
XmlSchemaComplexType type = (XmlSchemaComplexType)element.ElementType; |
||||
if (type.ContentModel != null) |
||||
Console.WriteLine("Not Implemented for this ContentModel"); |
||||
WriteExampleAttributes(type.Attributes); |
||||
WriteExampleParticle(type.Particle); |
||||
} |
||||
else |
||||
WriteExampleValue(element.ElementType); |
||||
|
||||
myXmlTextWriter.WriteEndElement(); |
||||
} |
||||
|
||||
Now how does this work? The WriteExample code iterates through the XmlSchema.Elements.Values collection and outputs some data for each XmlSchemaElement. The Elements property is not generated when you only do an XmlSchema.Read. What is actually happening is that the schema is being compiled aswell. I stumbled across this not using Reflector, but when changing the sample code to read in NAnt's 0.84 schema. Reading in NAnt-0.84.xsd the code threw an exception since one of the types (formatter) was defined twice, even though the schema is valid as far as I can tell. The exception was thrown at the line |
||||
|
||||
myXmlSchemaCollection.Add(null, "nant-0.84.xsd"); |
||||
|
||||
The exception call stack showed that XmlSchemaCollection.Add method calls XmlSchema.Compile. |
||||
|
||||
So it looks like we need to compile the XmlSchema object to get it to do a second parse. |
||||
|
||||
Xhtml1-Strict |
||||
------------- |
||||
|
||||
Fun and games getting this to load in the XmlSchema object. |
||||
|
||||
First, set the XmlResolver to null on the XmlTextReader. If this is not done the reader tries to look for referenced DTDs in the assembly folder. When the resolver is set to null it looks for the DTDs in the same folder as the .xsd itself which seems more reasonable. |
||||
|
||||
XmlSchema throws an exception because the xhtml1-strict.xsd redefines the xml namespace via the string xmlns:xml="http://www.w3.org/XML/1998/namespace" at the top of the file. According to the w3 spec this is valid, but the XmlSchema class does not like it. |
||||
|
||||
|
||||
Xml Editor handling property changes |
||||
------------------------------------ |
||||
|
||||
The properties are changed from inside SharpDevelop. Options are: |
||||
|
||||
1) Directly access the SharpDevelop properties each time the control is about to do something. |
||||
2) Control exposes properties which need to be changed via another object, not the editor, |
||||
when they have changed. |
||||
3) Control exposes a property object with a defined interface which the user of the control |
||||
can set. This object is checked whenever the control attempts to do something. This |
||||
object can access the SharpDevelop properties. |
||||
|
||||
I want to keep the Xml Editor control only dependent on the SharpDevelop Text Editor. This rules out option 1. |
||||
|
||||
|
||||
Schemas |
||||
------- |
||||
|
||||
System schemas |
||||
-------------- |
||||
|
||||
System schemas will live in the C:\Program Files\SharpDevelop\data\schemas folder. |
||||
|
||||
The PropertyService gives us a DataDirectory property which usually points to C:\Program Files\SharpDevelop\data so we can use this. |
||||
|
||||
If the folder does not exist it is not created since access to C:\Program Files can be restricted. |
||||
|
||||
User schemas |
||||
------------ |
||||
|
||||
User schemas will live in C:\Documents and Settings\web\Application Data\.ICSharpCode\SharpDevelop\schemas folder. |
||||
|
||||
The PropertyService gives us a ConfigDirectory which points to the parent of the above folder (i.e. SharpDevelop above the schemas folder). |
||||
|
||||
|
||||
XmlEditor addin |
||||
--------------- |
||||
|
||||
The binary and its addin file will exist in AddIns/AddIns/DisplayBindings/XmlEditor |
||||
|
||||
Folding |
||||
------- |
||||
|
||||
The standard way in SharpDevelop that folds are added is via the parser. The SharpDevelop has a parser thread which checks if the current view's text has changed, then looks for a parser that can handle that particular filename. This parser then parses the contents and the IParseInformation is sent to the view's IParseInformationListener.ParseInformationUpdated method. This method then usually uses the parse info to update the foldings. |
||||
|
||||
Now, the SharpDevelop parsers are programming language orientated, so a lot of the properties and objects are not relevant to parsed xml, so do we create a parser just to update the folds? The fold updating still needs to be done on a background thread, because folds aren't massively important, so creating our own extra thread is out of the question. We could trigger a fold update on every key press, but again this is overkill and will be probably be slow. |
||||
|
||||
Enabling searching in the xml editor |
||||
------------------------------------ |
||||
|
||||
The view class needs to implement the ITextEditorControlProvider otherwise the search menu options are disabled. |
||||
|
@ -0,0 +1,50 @@
@@ -0,0 +1,50 @@
|
||||
INSTALLATION: |
||||
------------- |
||||
|
||||
Using Binaries |
||||
-------------- |
||||
|
||||
Assuming SharpDevelop is installed in the folder "C:/Program Files/SharpDevelop" |
||||
|
||||
Copy the contents of the "bin" folder to "C:/Program Files/SharpDevelop/AddIns/AddIns/DisplayBindings/XmlEditor". |
||||
|
||||
The binaries should work with SharpDevelop v1.0.3.1768. |
||||
|
||||
|
||||
Building source |
||||
--------------- |
||||
|
||||
Copy the contents of the XmlEditor folder to "src/AddIns/DisplayBindings/XmlEditor". |
||||
|
||||
Load the "XmlEditor.cmbx" combine and build the project OR run the "XmlEditor.build" file with NAnt 0.84. |
||||
|
||||
|
||||
Configuring Schema Auto-completion |
||||
---------------------------------- |
||||
|
||||
Go to Tools->Options->Text Editor->Xml Schemas. Use the Add button to add your .xsds to SharpDevelop. |
||||
|
||||
|
||||
|
||||
Done: |
||||
----- |
||||
|
||||
Properties taken from SharpDevelop. |
||||
Handle property changes whilst editor is open. |
||||
Validate xml menu only available for the xml editor. |
||||
Validation against schema. Right click and menu option. |
||||
User added xsds. |
||||
System xsds. |
||||
Check that we can still "jump to" NAnt errors in .build files. |
||||
Test getting element completion data for the root element of a document. |
||||
Code completion window size. Long namespace URIs do not fit in the window. Duplicated |
||||
the CodeCompletionWindow class. The item width calculation should really be in |
||||
the CodeCompletionListView. |
||||
Custom code completion window. Only autocomplete when the tab or return key |
||||
is pressed. |
||||
Validation of the xml against the schema - send output to build window and add |
||||
task list entry. |
||||
Comment folding. |
||||
Recognise special file extensions (e.g. build). Allow user to specify schema |
||||
for a file extension. This would act as a default, but could be overriden |
||||
by specifying an xmlns in the xml. |
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
using System.Reflection; |
||||
using System.Runtime.CompilerServices; |
||||
|
||||
// Information about this assembly is defined by the following
|
||||
// attributes.
|
||||
//
|
||||
// change them to the information which is associated with the assembly
|
||||
// you compile.
|
||||
|
||||
[assembly: AssemblyTitle("")] |
||||
[assembly: AssemblyDescription("")] |
||||
[assembly: AssemblyConfiguration("")] |
||||
[assembly: AssemblyCompany("")] |
||||
[assembly: AssemblyProduct("")] |
||||
[assembly: AssemblyCopyright("")] |
||||
[assembly: AssemblyTrademark("")] |
||||
[assembly: AssemblyCulture("")] |
||||
|
||||
// The assembly version has following format :
|
||||
//
|
||||
// Major.Minor.Build.Revision
|
||||
//
|
||||
// You can specify all values by your own or you can build default build and revision
|
||||
// numbers with the '*' character (the default):
|
||||
|
||||
[assembly: AssemblyVersion("1.1.0.1964")] |
||||
|
||||
// The following attributes specify the key for the sign of your assembly. See the
|
||||
// .NET Framework documentation for more information about signing.
|
||||
// This is not required, if you don't want signing let these attributes like they're.
|
||||
[assembly: AssemblyDelaySign(false)] |
||||
[assembly: AssemblyKeyFile("")] |
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor; |
||||
using ICSharpCode.TextEditor.Actions; |
||||
using System; |
||||
using System.Windows.Forms; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Command executed when the user hits Ctrl+Space
|
||||
/// </summary>
|
||||
public class CodeCompletionPopupCommand : AbstractEditAction |
||||
{ |
||||
public override void Execute(TextArea services) |
||||
{ |
||||
XmlEditorControl editor = services.MotherTextEditorControl as XmlEditorControl; |
||||
if (editor != null) { |
||||
editor.ShowCompletionWindow(); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,305 @@
@@ -0,0 +1,305 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Mike Krueger" email="mike@icsharpcode.net"/>
|
||||
// <version value="$version"/>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Drawing; |
||||
using System.Windows.Forms; |
||||
using System.Reflection; |
||||
using System.Collections; |
||||
using System.Diagnostics; |
||||
|
||||
using ICSharpCode.TextEditor; |
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
public class CodeCompletionWindow : AbstractCompletionWindow |
||||
{ |
||||
static ICompletionData[] completionData; |
||||
CodeCompletionListView codeCompletionListView; |
||||
VScrollBar vScrollBar = new VScrollBar(); |
||||
|
||||
int startOffset; |
||||
int endOffset; |
||||
DeclarationViewWindow declarationViewWindow = null; |
||||
Rectangle workingScreen; |
||||
|
||||
const int ScrollbarWidth = 16; |
||||
bool showDeclarationWindow = true; |
||||
|
||||
public static CodeCompletionWindow ShowCompletionWindow(Form parent, TextEditorControl control, string fileName, ICompletionDataProvider completionDataProvider, char firstChar) |
||||
{ |
||||
return ShowCompletionWindow(parent, control, fileName, completionDataProvider, firstChar, true); |
||||
} |
||||
|
||||
public static CodeCompletionWindow ShowCompletionWindow(Form parent, TextEditorControl control, string fileName, ICompletionDataProvider completionDataProvider, char firstChar, bool showDeclarationWindow) |
||||
{ |
||||
completionData = completionDataProvider.GenerateCompletionData(fileName, control.ActiveTextAreaControl.TextArea, firstChar); |
||||
if (completionData == null || completionData.Length == 0) { |
||||
return null; |
||||
} |
||||
CodeCompletionWindow codeCompletionWindow = new CodeCompletionWindow(completionDataProvider, parent, control, fileName, showDeclarationWindow); |
||||
codeCompletionWindow.ShowCompletionWindow(); |
||||
return codeCompletionWindow; |
||||
} |
||||
|
||||
CodeCompletionWindow(ICompletionDataProvider completionDataProvider, Form parentForm, TextEditorControl control, string fileName, bool showDeclarationWindow) : base(parentForm, control, fileName) |
||||
{ |
||||
this.showDeclarationWindow = showDeclarationWindow; |
||||
|
||||
workingScreen = Screen.GetWorkingArea(Location); |
||||
startOffset = control.ActiveTextAreaControl.Caret.Offset + 1; |
||||
endOffset = startOffset; |
||||
if (completionDataProvider.PreSelection != null) { |
||||
startOffset -= completionDataProvider.PreSelection.Length + 1; |
||||
endOffset--; |
||||
} |
||||
|
||||
codeCompletionListView = new CodeCompletionListView(completionData); |
||||
codeCompletionListView.ImageList = completionDataProvider.ImageList; |
||||
codeCompletionListView.Dock = DockStyle.Fill; |
||||
codeCompletionListView.SelectedItemChanged += new EventHandler(CodeCompletionListViewSelectedItemChanged); |
||||
codeCompletionListView.DoubleClick += new EventHandler(CodeCompletionListViewDoubleClick); |
||||
codeCompletionListView.Click += new EventHandler(CodeCompletionListViewClick); |
||||
Controls.Add(codeCompletionListView); |
||||
|
||||
if (completionData.Length > 10) { |
||||
vScrollBar.Dock = DockStyle.Right; |
||||
vScrollBar.Minimum = 0; |
||||
vScrollBar.Maximum = completionData.Length - 8; |
||||
vScrollBar.SmallChange = 1; |
||||
vScrollBar.LargeChange = 3; |
||||
codeCompletionListView.FirstItemChanged += new EventHandler(CodeCompletionListViewFirstItemChanged); |
||||
Controls.Add(vScrollBar); |
||||
} |
||||
|
||||
this.drawingSize = GetListViewSize(); |
||||
SetLocation(); |
||||
|
||||
declarationViewWindow = new DeclarationViewWindow(parentForm); |
||||
SetDeclarationViewLocation(); |
||||
declarationViewWindow.ShowDeclarationViewWindow(); |
||||
control.Focus(); |
||||
CodeCompletionListViewSelectedItemChanged(this, EventArgs.Empty); |
||||
if (completionDataProvider.PreSelection != null) { |
||||
CaretOffsetChanged(this, EventArgs.Empty); |
||||
} |
||||
|
||||
vScrollBar.Scroll += new ScrollEventHandler(DoScroll); |
||||
} |
||||
|
||||
public void HandleMouseWheel(MouseEventArgs e) |
||||
{ |
||||
int MAX_DELTA = 120; // basically it's constant now, but could be changed later by MS
|
||||
int multiplier = Math.Abs(e.Delta) / MAX_DELTA; |
||||
|
||||
int newValue; |
||||
if (System.Windows.Forms.SystemInformation.MouseWheelScrollLines > 0) { |
||||
newValue = this.vScrollBar.Value - (control.TextEditorProperties.MouseWheelScrollDown ? 1 : -1) * Math.Sign(e.Delta) * System.Windows.Forms.SystemInformation.MouseWheelScrollLines * vScrollBar.SmallChange * multiplier; |
||||
} else { |
||||
newValue = this.vScrollBar.Value - (control.TextEditorProperties.MouseWheelScrollDown ? 1 : -1) * Math.Sign(e.Delta) * vScrollBar.LargeChange; |
||||
} |
||||
vScrollBar.Value = Math.Max(vScrollBar.Minimum, Math.Min(vScrollBar.Maximum, newValue)); |
||||
DoScroll(this, null); |
||||
} |
||||
|
||||
void CodeCompletionListViewFirstItemChanged(object sender, EventArgs e) |
||||
{ |
||||
vScrollBar.Value = Math.Min(vScrollBar.Maximum, codeCompletionListView.FirstItem); |
||||
} |
||||
|
||||
void SetDeclarationViewLocation() |
||||
{ |
||||
Console.WriteLine("SET DECLARATION VIEW LOCATION."); |
||||
// This method uses the side with more free space
|
||||
int leftSpace = Bounds.Left - workingScreen.Left; |
||||
int rightSpace = workingScreen.Right - Bounds.Right; |
||||
Point pos; |
||||
// The declaration view window has better line break when used on
|
||||
// the right side, so prefer the right side to the left.
|
||||
if (rightSpace * 2 > leftSpace) |
||||
pos = new Point(Bounds.Right, Bounds.Top); |
||||
else |
||||
pos = new Point(Bounds.Left - declarationViewWindow.Width, Bounds.Top); |
||||
if (declarationViewWindow.Location != pos) { |
||||
declarationViewWindow.Location = pos; |
||||
} |
||||
} |
||||
|
||||
protected override void SetLocation() |
||||
{ |
||||
base.SetLocation(); |
||||
if (declarationViewWindow != null) { |
||||
SetDeclarationViewLocation(); |
||||
} |
||||
} |
||||
|
||||
void CodeCompletionListViewSelectedItemChanged(object sender, EventArgs e) |
||||
{ |
||||
ICompletionData data = codeCompletionListView.SelectedCompletionData; |
||||
if (data != null && data.Description != null && showDeclarationWindow) { |
||||
declarationViewWindow.Description = data.Description; |
||||
SetDeclarationViewLocation(); |
||||
} else { |
||||
declarationViewWindow.Size = new Size(0, 0); |
||||
} |
||||
} |
||||
|
||||
public override bool ProcessKeyEvent(char ch) |
||||
{ |
||||
if (XmlParser.IsXmlNameChar(ch) || XmlParser.IsAttributeValueChar(ch)){ |
||||
++endOffset; |
||||
return base.ProcessKeyEvent(ch); |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
protected override void CaretOffsetChanged(object sender, EventArgs e) |
||||
{ |
||||
int offset = control.ActiveTextAreaControl.Caret.Offset; |
||||
//Console.WriteLine("StartOffset {0} endOffset {1} - Offset {2}", startOffset, endOffset, offset);
|
||||
if (offset < startOffset || offset > endOffset) { |
||||
Close(); |
||||
} else { |
||||
codeCompletionListView.SelectItemWithStart(control.Document.GetText(startOffset, offset - startOffset)); |
||||
} |
||||
} |
||||
|
||||
protected void DoScroll(object sender, ScrollEventArgs sea) |
||||
{ |
||||
codeCompletionListView.FirstItem = vScrollBar.Value; |
||||
codeCompletionListView.Refresh(); |
||||
control.ActiveTextAreaControl.TextArea.Focus(); |
||||
} |
||||
|
||||
protected override bool ProcessTextAreaKey(Keys keyData) |
||||
{ |
||||
if (!Visible) { |
||||
return false; |
||||
} |
||||
|
||||
switch (keyData) { |
||||
case Keys.Back: |
||||
--endOffset; |
||||
if (endOffset < startOffset) { |
||||
Close(); |
||||
} |
||||
return false; |
||||
case Keys.Delete: |
||||
if (control.ActiveTextAreaControl.Caret.Offset <= endOffset) { |
||||
--endOffset; |
||||
} |
||||
if (endOffset < startOffset) { |
||||
Close(); |
||||
} |
||||
return false; |
||||
case Keys.Home: |
||||
codeCompletionListView.SelectIndex(0); |
||||
return true; |
||||
case Keys.End: |
||||
codeCompletionListView.SelectIndex(completionData.Length-1); |
||||
return true; |
||||
case Keys.PageDown: |
||||
codeCompletionListView.PageDown(); |
||||
return true; |
||||
case Keys.PageUp: |
||||
codeCompletionListView.PageUp(); |
||||
return true; |
||||
case Keys.Down: |
||||
case Keys.Right: |
||||
codeCompletionListView.SelectNextItem(); |
||||
return true; |
||||
case Keys.Up: |
||||
case Keys.Left: |
||||
codeCompletionListView.SelectPrevItem(); |
||||
return true; |
||||
case Keys.Tab: |
||||
case Keys.Return: |
||||
InsertSelectedItem(); |
||||
return true; |
||||
} |
||||
return base.ProcessTextAreaKey(keyData); |
||||
} |
||||
|
||||
void CodeCompletionListViewDoubleClick(object sender, EventArgs e) |
||||
{ |
||||
InsertSelectedItem(); |
||||
} |
||||
|
||||
void CodeCompletionListViewClick(object sender, EventArgs e) |
||||
{ |
||||
control.ActiveTextAreaControl.TextArea.Focus(); |
||||
} |
||||
|
||||
protected override void OnClosed(EventArgs e) |
||||
{ |
||||
base.OnClosed(e); |
||||
Dispose(); |
||||
codeCompletionListView.Dispose(); |
||||
codeCompletionListView = null; |
||||
declarationViewWindow.Dispose(); |
||||
declarationViewWindow = null; |
||||
} |
||||
|
||||
void InsertSelectedItem() |
||||
{ |
||||
ICompletionData data = codeCompletionListView.SelectedCompletionData; |
||||
if (data != null) { |
||||
control.BeginUpdate(); |
||||
|
||||
if (endOffset - startOffset > 0) { |
||||
//Console.WriteLine("start {0} length {1}", startOffset, endOffset - startOffset);
|
||||
control.Document.Remove(startOffset, endOffset - startOffset); |
||||
control.ActiveTextAreaControl.Caret.Position = control.Document.OffsetToPosition(startOffset); |
||||
} |
||||
data.InsertAction(control.ActiveTextAreaControl.TextArea, '\0'); |
||||
control.EndUpdate(); |
||||
} |
||||
Close(); |
||||
} |
||||
|
||||
Size GetListViewSize() |
||||
{ |
||||
int height = codeCompletionListView.ItemHeight * Math.Min(10, completionData.Length); |
||||
int width = GetListViewWidth(codeCompletionListView.ItemHeight * 10, height); |
||||
return new Size(width, height); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the list view width large enough to handle the longest completion data
|
||||
/// text string.
|
||||
/// </summary>
|
||||
/// <param name="defaultWidth">The default width of the list view.</param>
|
||||
/// <param name="height">The height of the list view. This is
|
||||
/// used to determine if the scrollbar is visible.</param>
|
||||
/// <returns>The list view width to accommodate the longest completion
|
||||
/// data text string; otherwise the default width.</returns>
|
||||
int GetListViewWidth(int defaultWidth, int height) |
||||
{ |
||||
Graphics graphics = codeCompletionListView.CreateGraphics(); |
||||
float width = defaultWidth; |
||||
|
||||
for(int i = 0; i < completionData.Length; ++i) |
||||
{ |
||||
float itemWidth = graphics.MeasureString(completionData[i].Text[0].ToString(), codeCompletionListView.Font).Width; |
||||
if(itemWidth > width) { |
||||
width = itemWidth; |
||||
} |
||||
} |
||||
graphics.Dispose(); |
||||
|
||||
float totalItemsHeight = codeCompletionListView.ItemHeight * completionData.Length; |
||||
|
||||
if (totalItemsHeight > height) { |
||||
width += ScrollbarWidth; // Compensate for scroll bar.
|
||||
} |
||||
|
||||
return (int)width; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,122 @@
@@ -0,0 +1,122 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop; |
||||
using System; |
||||
using System.Data; |
||||
using System.IO; |
||||
using System.Text; |
||||
using System.Windows.Forms; |
||||
using System.Xml; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Creates a schema based on the xml in the currently active view.
|
||||
/// </summary>
|
||||
public class CreateSchemaCommand : AbstractMenuCommand |
||||
{ |
||||
public CreateSchemaCommand() |
||||
{ |
||||
} |
||||
|
||||
public override void Run() |
||||
{ |
||||
// Find active XmlView.
|
||||
XmlView xmlView = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ActiveViewContent as XmlView; |
||||
if (xmlView != null) { |
||||
|
||||
// Create a schema based on the xml.
|
||||
SharpDevelopTextEditorProperties properties = xmlView.TextEditorControl.TextEditorProperties as SharpDevelopTextEditorProperties; |
||||
string schema = CreateSchema(xmlView.TextEditorControl.Document.TextContent, xmlView.TextEditorControl.Encoding, properties.ConvertTabsToSpaces, properties.TabIndent); |
||||
|
||||
// Create a new file and display the generated schema.
|
||||
string fileName = GenerateSchemaFileName(xmlView.TitleName); |
||||
OpenNewXmlFile(fileName, schema); |
||||
|
||||
if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null) { |
||||
WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.SelectWindow(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates a schema based on the xml content.
|
||||
/// </summary>
|
||||
/// <returns>A generated schema.</returns>
|
||||
string CreateSchema(string xml, Encoding encoding, bool convertTabsToSpaces, int tabIndent) |
||||
{ |
||||
string schema = String.Empty; |
||||
|
||||
using (DataSet dataSet = new DataSet()) { |
||||
dataSet.ReadXml(new StringReader(xml), XmlReadMode.InferSchema); |
||||
EncodedStringWriter writer = new EncodedStringWriter(encoding); |
||||
XmlTextWriter xmlWriter = new XmlTextWriter(writer); |
||||
|
||||
xmlWriter.Formatting = Formatting.Indented; |
||||
if (convertTabsToSpaces) { |
||||
xmlWriter.Indentation = tabIndent; |
||||
xmlWriter.IndentChar = ' '; |
||||
} else { |
||||
xmlWriter.Indentation = 1; |
||||
xmlWriter.IndentChar = '\t'; |
||||
} |
||||
|
||||
dataSet.WriteXmlSchema(xmlWriter); |
||||
schema = writer.ToString(); |
||||
writer.Close(); |
||||
xmlWriter.Close(); |
||||
} |
||||
|
||||
return schema; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Opens a new unsaved xml file in SharpDevelop.
|
||||
/// </summary>
|
||||
void OpenNewXmlFile(string fileName, string xml) |
||||
{ |
||||
FileService.NewFile(fileName, XmlView.Language, xml); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Generates an xsd filename based on the name of the original xml
|
||||
/// file. If a file with the same name is already open in SharpDevelop
|
||||
/// then a new name is generated (e.g. MyXml1.xsd).
|
||||
/// </summary>
|
||||
string GenerateSchemaFileName(string xmlFileName) |
||||
{ |
||||
string baseFileName = Path.GetFileNameWithoutExtension(xmlFileName); |
||||
string schemaFileName = String.Concat(baseFileName, ".xsd"); |
||||
|
||||
int count = 1; |
||||
while (FileService.IsOpen(schemaFileName)) { |
||||
schemaFileName = String.Concat(baseFileName, count.ToString(), ".xsd"); |
||||
++count; |
||||
} |
||||
|
||||
return schemaFileName; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,62 @@
@@ -0,0 +1,62 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// A string writer that allows you to specify the text encoding to
|
||||
/// be used when generating the string.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This class is used when generating xml strings using a writer and
|
||||
/// the encoding in the xml processing instruction needs to be changed.
|
||||
/// The xml encoding string will be the encoding specified in the constructor
|
||||
/// of this class (i.e. UTF-8, UTF-16)</remarks>
|
||||
public class EncodedStringWriter : StringWriter |
||||
{ |
||||
Encoding encoding = Encoding.UTF8; |
||||
|
||||
/// <summary>
|
||||
/// Creates a new string writer that will generate a string with the
|
||||
/// specified encoding.
|
||||
/// </summary>
|
||||
/// <remarks>The encoding will be used when generating the
|
||||
/// xml encoding header (i.e. UTF-8, UTF-16).</remarks>
|
||||
public EncodedStringWriter(Encoding encoding) |
||||
{ |
||||
this.encoding = encoding; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the text encoding that will be used when generating
|
||||
/// the string.
|
||||
/// </summary>
|
||||
public override Encoding Encoding { |
||||
get { |
||||
return encoding; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,81 @@
@@ -0,0 +1,81 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using System; |
||||
using System.Collections; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Parser that does nothing except return empty compilation unit
|
||||
/// classes so the XmlFoldingStrategy is executed.
|
||||
/// </summary>
|
||||
public class Parser : IParser |
||||
{ |
||||
public Parser() |
||||
{ |
||||
} |
||||
|
||||
#region IParser interface
|
||||
public string[] LexerTags { |
||||
get { |
||||
return null; |
||||
} |
||||
set { |
||||
} |
||||
} |
||||
|
||||
public IExpressionFinder CreateExpressionFinder(string fileName) |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public IResolver CreateResolver() |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public ICompilationUnit Parse(IProjectContent projectContent, string fileName) |
||||
{ |
||||
return new DefaultCompilationUnit(projectContent); |
||||
} |
||||
|
||||
public ICompilationUnit Parse(IProjectContent projectContent, string fileName, string fileContent) |
||||
{ |
||||
return new DefaultCompilationUnit(projectContent); |
||||
} |
||||
|
||||
public bool CanParse(IProject project) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
public bool CanParse(string fileName) |
||||
{ |
||||
return XmlView.IsFileNameHandled(fileName); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
@ -0,0 +1,136 @@
@@ -0,0 +1,136 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using System; |
||||
using System.Xml; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// An <see cref="XmlQualifiedName"/> with the namespace prefix.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The namespace prefix active for a namespace is
|
||||
/// needed when an element is inserted via autocompletion. This
|
||||
/// class just adds this extra information alongside the
|
||||
/// <see cref="XmlQualifiedName"/>.
|
||||
/// </remarks>
|
||||
public class QualifiedName |
||||
{ |
||||
XmlQualifiedName xmlQualifiedName = XmlQualifiedName.Empty; |
||||
string prefix = String.Empty; |
||||
|
||||
public QualifiedName() |
||||
{ |
||||
} |
||||
|
||||
public QualifiedName(string name, string namespaceUri) |
||||
: this(name, namespaceUri, String.Empty) |
||||
{ |
||||
} |
||||
|
||||
public QualifiedName(string name, string namespaceUri, string prefix) |
||||
{ |
||||
xmlQualifiedName = new XmlQualifiedName(name, namespaceUri); |
||||
this.prefix = prefix; |
||||
} |
||||
|
||||
public static bool operator ==(QualifiedName lhs, QualifiedName rhs) |
||||
{ |
||||
bool equals = false; |
||||
|
||||
if (((object)lhs != null) && ((object)rhs != null)) { |
||||
equals = lhs.Equals(rhs); |
||||
} else if (((object)lhs == null) && ((object)rhs == null)) { |
||||
equals = true; |
||||
} |
||||
|
||||
return equals; |
||||
} |
||||
|
||||
public static bool operator !=(QualifiedName lhs, QualifiedName rhs) |
||||
{ |
||||
return !(lhs == rhs); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// A qualified name is considered equal if the namespace and
|
||||
/// name are the same. The prefix is ignored.
|
||||
/// </summary>
|
||||
public override bool Equals(object obj) |
||||
{ |
||||
bool equals = false; |
||||
|
||||
QualifiedName qualifiedName = obj as QualifiedName; |
||||
if (qualifiedName != null) { |
||||
equals = xmlQualifiedName.Equals(qualifiedName.xmlQualifiedName); |
||||
} else { |
||||
XmlQualifiedName name = obj as XmlQualifiedName; |
||||
if (name != null) { |
||||
equals = xmlQualifiedName.Equals(name); |
||||
} |
||||
} |
||||
|
||||
return equals; |
||||
} |
||||
|
||||
public override int GetHashCode() |
||||
{ |
||||
return xmlQualifiedName.GetHashCode(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the namespace of the qualified name.
|
||||
/// </summary>
|
||||
public string Namespace { |
||||
get { |
||||
return xmlQualifiedName.Namespace; |
||||
} |
||||
set { |
||||
xmlQualifiedName = new XmlQualifiedName(xmlQualifiedName.Name, value); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the element.
|
||||
/// </summary>
|
||||
public string Name { |
||||
get { |
||||
return xmlQualifiedName.Name; |
||||
} |
||||
set { |
||||
xmlQualifiedName = new XmlQualifiedName(value, xmlQualifiedName.Namespace); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the namespace prefix used.
|
||||
/// </summary>
|
||||
public string Prefix { |
||||
get { |
||||
return prefix; |
||||
} |
||||
set { |
||||
prefix = value; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,288 @@
@@ -0,0 +1,288 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// A collection that stores <see cref='QualifiedName'/> objects.
|
||||
/// </summary>
|
||||
[Serializable()] |
||||
public class QualifiedNameCollection : CollectionBase { |
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref='QualifiedNameCollection'/>.
|
||||
/// </summary>
|
||||
public QualifiedNameCollection() |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref='QualifiedNameCollection'/> based on another <see cref='QualifiedNameCollection'/>.
|
||||
/// </summary>
|
||||
/// <param name='val'>
|
||||
/// A <see cref='QualifiedNameCollection'/> from which the contents are copied
|
||||
/// </param>
|
||||
public QualifiedNameCollection(QualifiedNameCollection val) |
||||
{ |
||||
this.AddRange(val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref='QualifiedNameCollection'/> containing any array of <see cref='QualifiedName'/> objects.
|
||||
/// </summary>
|
||||
/// <param name='val'>
|
||||
/// A array of <see cref='QualifiedName'/> objects with which to intialize the collection
|
||||
/// </param>
|
||||
public QualifiedNameCollection(QualifiedName[] val) |
||||
{ |
||||
this.AddRange(val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Represents the entry at the specified index of the <see cref='QualifiedName'/>.
|
||||
/// </summary>
|
||||
/// <param name='index'>The zero-based index of the entry to locate in the collection.</param>
|
||||
/// <value>The entry at the specified index of the collection.</value>
|
||||
/// <exception cref='ArgumentOutOfRangeException'><paramref name='index'/> is outside the valid range of indexes for the collection.</exception>
|
||||
public QualifiedName this[int index] { |
||||
get { |
||||
return ((QualifiedName)(List[index])); |
||||
} |
||||
set { |
||||
List[index] = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds a <see cref='QualifiedName'/> with the specified value to the
|
||||
/// <see cref='QualifiedNameCollection'/>.
|
||||
/// </summary>
|
||||
/// <param name='val'>The <see cref='QualifiedName'/> to add.</param>
|
||||
/// <returns>The index at which the new element was inserted.</returns>
|
||||
/// <seealso cref='QualifiedNameCollection.AddRange'/>
|
||||
public int Add(QualifiedName val) |
||||
{ |
||||
return List.Add(val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Copies the elements of an array to the end of the <see cref='QualifiedNameCollection'/>.
|
||||
/// </summary>
|
||||
/// <param name='val'>
|
||||
/// An array of type <see cref='QualifiedName'/> containing the objects to add to the collection.
|
||||
/// </param>
|
||||
/// <seealso cref='QualifiedNameCollection.Add'/>
|
||||
public void AddRange(QualifiedName[] val) |
||||
{ |
||||
for (int i = 0; i < val.Length; i++) { |
||||
this.Add(val[i]); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds the contents of another <see cref='QualifiedNameCollection'/> to the end of the collection.
|
||||
/// </summary>
|
||||
/// <param name='val'>
|
||||
/// A <see cref='QualifiedNameCollection'/> containing the objects to add to the collection.
|
||||
/// </param>
|
||||
/// <seealso cref='QualifiedNameCollection.Add'/>
|
||||
public void AddRange(QualifiedNameCollection val) |
||||
{ |
||||
for (int i = 0; i < val.Count; i++) |
||||
{ |
||||
this.Add(val[i]); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the
|
||||
/// <see cref='QualifiedNameCollection'/> contains the specified <see cref='QualifiedName'/>.
|
||||
/// </summary>
|
||||
/// <param name='val'>The <see cref='QualifiedName'/> to locate.</param>
|
||||
/// <returns>
|
||||
/// <see langword='true'/> if the <see cref='QualifiedName'/> is contained in the collection;
|
||||
/// otherwise, <see langword='false'/>.
|
||||
/// </returns>
|
||||
/// <seealso cref='QualifiedNameCollection.IndexOf'/>
|
||||
public bool Contains(QualifiedName val) |
||||
{ |
||||
return List.Contains(val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Copies the <see cref='QualifiedNameCollection'/> values to a one-dimensional <see cref='Array'/> instance at the
|
||||
/// specified index.
|
||||
/// </summary>
|
||||
/// <param name='array'>The one-dimensional <see cref='Array'/> that is the destination of the values copied from <see cref='QualifiedNameCollection'/>.</param>
|
||||
/// <param name='index'>The index in <paramref name='array'/> where copying begins.</param>
|
||||
/// <exception cref='ArgumentException'>
|
||||
/// <para><paramref name='array'/> is multidimensional.</para>
|
||||
/// <para>-or-</para>
|
||||
/// <para>The number of elements in the <see cref='QualifiedNameCollection'/> is greater than
|
||||
/// the available space between <paramref name='arrayIndex'/> and the end of
|
||||
/// <paramref name='array'/>.</para>
|
||||
/// </exception>
|
||||
/// <exception cref='ArgumentNullException'><paramref name='array'/> is <see langword='null'/>. </exception>
|
||||
/// <exception cref='ArgumentOutOfRangeException'><paramref name='arrayIndex'/> is less than <paramref name='array'/>'s lowbound. </exception>
|
||||
/// <seealso cref='Array'/>
|
||||
public void CopyTo(QualifiedName[] array, int index) |
||||
{ |
||||
List.CopyTo(array, index); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the index of a <see cref='QualifiedName'/> in
|
||||
/// the <see cref='QualifiedNameCollection'/>.
|
||||
/// </summary>
|
||||
/// <param name='val'>The <see cref='QualifiedName'/> to locate.</param>
|
||||
/// <returns>
|
||||
/// The index of the <see cref='QualifiedName'/> of <paramref name='val'/> in the
|
||||
/// <see cref='QualifiedNameCollection'/>, if found; otherwise, -1.
|
||||
/// </returns>
|
||||
/// <seealso cref='QualifiedNameCollection.Contains'/>
|
||||
public int IndexOf(QualifiedName val) |
||||
{ |
||||
return List.IndexOf(val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Inserts a <see cref='QualifiedName'/> into the <see cref='QualifiedNameCollection'/> at the specified index.
|
||||
/// </summary>
|
||||
/// <param name='index'>The zero-based index where <paramref name='val'/> should be inserted.</param>
|
||||
/// <param name='val'>The <see cref='QualifiedName'/> to insert.</param>
|
||||
/// <seealso cref='QualifiedNameCollection.Add'/>
|
||||
public void Insert(int index, QualifiedName val) |
||||
{ |
||||
List.Insert(index, val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator that can iterate through the <see cref='QualifiedNameCollection'/>.
|
||||
/// </summary>
|
||||
/// <seealso cref='IEnumerator'/>
|
||||
public new QualifiedNameEnumerator GetEnumerator() |
||||
{ |
||||
return new QualifiedNameEnumerator(this); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes a specific <see cref='QualifiedName'/> from the <see cref='QualifiedNameCollection'/>.
|
||||
/// </summary>
|
||||
/// <param name='val'>The <see cref='QualifiedName'/> to remove from the <see cref='QualifiedNameCollection'/>.</param>
|
||||
/// <exception cref='ArgumentException'><paramref name='val'/> is not found in the Collection.</exception>
|
||||
public void Remove(QualifiedName val) |
||||
{ |
||||
List.Remove(val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes the last item in this collection.
|
||||
/// </summary>
|
||||
public void RemoveLast() |
||||
{ |
||||
if (Count > 0) { |
||||
RemoveAt(Count - 1); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes the first item in the collection.
|
||||
/// </summary>
|
||||
public void RemoveFirst() |
||||
{ |
||||
if (Count > 0) { |
||||
RemoveAt(0); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the namespace prefix of the last item.
|
||||
/// </summary>
|
||||
public string LastPrefix { |
||||
get { |
||||
string prefix = String.Empty; |
||||
|
||||
if (Count > 0) { |
||||
QualifiedName name = this[Count - 1]; |
||||
prefix = name.Prefix; |
||||
} |
||||
|
||||
return prefix; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Enumerator that can iterate through a QualifiedNameCollection.
|
||||
/// </summary>
|
||||
/// <seealso cref='IEnumerator'/>
|
||||
/// <seealso cref='QualifiedNameCollection'/>
|
||||
/// <seealso cref='QualifiedName'/>
|
||||
public class QualifiedNameEnumerator : IEnumerator |
||||
{ |
||||
IEnumerator baseEnumerator; |
||||
IEnumerable temp; |
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref='QualifiedNameEnumerator'/>.
|
||||
/// </summary>
|
||||
public QualifiedNameEnumerator(QualifiedNameCollection mappings) |
||||
{ |
||||
this.temp = ((IEnumerable)(mappings)); |
||||
this.baseEnumerator = temp.GetEnumerator(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the current <see cref='QualifiedName'/> in the <seealso cref='QualifiedNameCollection'/>.
|
||||
/// </summary>
|
||||
public QualifiedName Current { |
||||
get { |
||||
return ((QualifiedName)(baseEnumerator.Current)); |
||||
} |
||||
} |
||||
|
||||
object IEnumerator.Current { |
||||
get { |
||||
return baseEnumerator.Current; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Advances the enumerator to the next <see cref='QualifiedName'/> of the <see cref='QualifiedNameCollection'/>.
|
||||
/// </summary>
|
||||
public bool MoveNext() |
||||
{ |
||||
return baseEnumerator.MoveNext(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Sets the enumerator to its initial position, which is before the first element in the <see cref='QualifiedNameCollection'/>.
|
||||
/// </summary>
|
||||
public void Reset() |
||||
{ |
||||
baseEnumerator.Reset(); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
<Components version="1.0"> |
||||
<System.Windows.Forms.Form> |
||||
<Name value="SelectXmlSchemaForm" /> |
||||
<ShowInTaskbar value="False" /> |
||||
<ClientSize value="{Width=376, Height=286}" /> |
||||
<DockPadding value="" /> |
||||
<Text value="${res:ICSharpCode.XmlEditor.SelectXmlSchema.DialogTitle}" /> |
||||
<AcceptButton value="okButton [System.Windows.Forms.Button], Text: ${res:Global.OKButtonText}" /> |
||||
<CancelButton value="cancelButton [System.Windows.Forms.Button], Text: ${res:Global.CancelButtonText}" /> |
||||
<Controls> |
||||
<System.Windows.Forms.Button> |
||||
<Name value="okButton" /> |
||||
<Location value="{X=248,Y=256}" /> |
||||
<Size value="{Width=56, Height=24}" /> |
||||
<Text value="${res:Global.OKButtonText}" /> |
||||
<Anchor value="Bottom, Right" /> |
||||
<TabIndex value="2" /> |
||||
<DialogResult value="Cancel" /> |
||||
</System.Windows.Forms.Button> |
||||
<System.Windows.Forms.Button> |
||||
<Name value="cancelButton" /> |
||||
<Location value="{X=312,Y=256}" /> |
||||
<Size value="{Width=56, Height=24}" /> |
||||
<Text value="${res:Global.CancelButtonText}" /> |
||||
<Anchor value="Bottom, Right" /> |
||||
<TabIndex value="1" /> |
||||
<DialogResult value="Cancel" /> |
||||
</System.Windows.Forms.Button> |
||||
<System.Windows.Forms.ListBox> |
||||
<Name value="schemaListBox" /> |
||||
<Size value="{Width=360, Height=238}" /> |
||||
<Anchor value="Top, Bottom, Left, Right" /> |
||||
<TabIndex value="0" /> |
||||
<Location value="{X=8,Y=8}" /> |
||||
</System.Windows.Forms.ListBox> |
||||
</Controls> |
||||
</System.Windows.Forms.Form> |
||||
</Components> |
@ -0,0 +1,105 @@
@@ -0,0 +1,105 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Gui.XmlForms; |
||||
using System; |
||||
using System.Windows.Forms; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Allows the use to choose a schema from the schemas that SharpDevelop
|
||||
/// knows about.
|
||||
/// </summary>
|
||||
public class SelectXmlSchemaForm : XmlForm |
||||
{ |
||||
ListBox schemaListBox; |
||||
string NoSchemaSelectedText = String.Empty; |
||||
|
||||
public SelectXmlSchemaForm(string[] namespaces) |
||||
{ |
||||
Initialize(); |
||||
PopulateListBox(namespaces); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the selected schema namesace.
|
||||
/// </summary>
|
||||
public string SelectedNamespaceUri { |
||||
get { |
||||
string namespaceUri = schemaListBox.Text; |
||||
if (namespaceUri == NoSchemaSelectedText) { |
||||
namespaceUri = String.Empty; |
||||
} |
||||
return namespaceUri; |
||||
} |
||||
|
||||
set { |
||||
int index = 0; |
||||
if (value.Length > 0) { |
||||
index = schemaListBox.Items.IndexOf(value); |
||||
} |
||||
|
||||
// Select the option representing "no schema" if
|
||||
// the value does not exist in the list box.
|
||||
if (index == -1) { |
||||
index = 0; |
||||
} |
||||
|
||||
schemaListBox.SelectedIndex = index; |
||||
} |
||||
} |
||||
|
||||
protected override void SetupXmlLoader() |
||||
{ |
||||
xmlLoader.StringValueFilter = new SharpDevelopStringValueFilter(); |
||||
xmlLoader.PropertyValueCreator = new SharpDevelopPropertyValueCreator(); |
||||
xmlLoader.ObjectCreator = new SharpDevelopObjectCreator(); |
||||
} |
||||
|
||||
void Initialize() |
||||
{ |
||||
SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("ICSharpCode.XmlEditor.SelectXmlSchema.xfrm")); |
||||
|
||||
NoSchemaSelectedText = StringParser.Parse("${res:Dialog.Options.IDEOptions.TextEditor.Behaviour.IndentStyle.None}"); |
||||
|
||||
schemaListBox = (ListBox)ControlDictionary["schemaListBox"]; |
||||
|
||||
AcceptButton = (Button)ControlDictionary["okButton"]; |
||||
CancelButton = (Button)ControlDictionary["cancelButton"]; |
||||
AcceptButton.DialogResult = DialogResult.OK; |
||||
} |
||||
|
||||
void PopulateListBox(string[] namespaces) |
||||
{ |
||||
foreach (string schemaNamespace in namespaces) { |
||||
schemaListBox.Items.Add(schemaNamespace); |
||||
} |
||||
|
||||
// Add the "None" string at the top of the list.
|
||||
schemaListBox.Sorted = true; |
||||
schemaListBox.Sorted = false; |
||||
|
||||
schemaListBox.Items.Insert(0, NoSchemaSelectedText); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,48 @@
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using System; |
||||
using System.Windows.Forms; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Validates the xml in the xml editor against the known schemas.
|
||||
/// </summary>
|
||||
public class ValidateXmlCommand : AbstractMenuCommand |
||||
{ |
||||
/// <summary>
|
||||
/// Validate the xml.
|
||||
/// </summary>
|
||||
public override void Run() |
||||
{ |
||||
// Find active XmlView.
|
||||
XmlView xmlView = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ActiveViewContent as XmlView; |
||||
if (xmlView != null) { |
||||
// Validate the xml.
|
||||
xmlView.ValidateXml(); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,127 @@
@@ -0,0 +1,127 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor; |
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using System; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Holds the text for namespace, child element or attribute
|
||||
/// autocomplete (intellisense).
|
||||
/// </summary>
|
||||
public class XmlCompletionData : ICompletionData |
||||
{ |
||||
string text; |
||||
DataType dataType = DataType.XmlElement; |
||||
string description = String.Empty; |
||||
|
||||
/// <summary>
|
||||
/// The type of text held in this object.
|
||||
/// </summary>
|
||||
public enum DataType { |
||||
XmlElement = 1, |
||||
XmlAttribute = 2, |
||||
NamespaceUri = 3, |
||||
XmlAttributeValue = 4 |
||||
} |
||||
|
||||
public XmlCompletionData(string text) |
||||
: this(text, String.Empty, DataType.XmlElement) |
||||
{ |
||||
} |
||||
|
||||
public XmlCompletionData(string text, string description) |
||||
: this(text, description, DataType.XmlElement) |
||||
{ |
||||
} |
||||
|
||||
public XmlCompletionData(string text, DataType dataType) |
||||
: this(text, String.Empty, dataType) |
||||
{ |
||||
} |
||||
|
||||
public XmlCompletionData(string text, string description, DataType dataType) |
||||
{ |
||||
this.text = text; |
||||
this.description = description; |
||||
this.dataType = dataType; |
||||
} |
||||
|
||||
public int ImageIndex { |
||||
get { |
||||
return 0; |
||||
} |
||||
} |
||||
|
||||
public string Text { |
||||
get { |
||||
return text; |
||||
} |
||||
set { |
||||
text = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the xml item's documentation as retrieved from
|
||||
/// the xs:annotation/xs:documentation element.
|
||||
/// </summary>
|
||||
public string Description { |
||||
get { |
||||
return description; |
||||
} |
||||
} |
||||
|
||||
public double Priority { |
||||
get { |
||||
return 0; |
||||
} |
||||
} |
||||
|
||||
public bool InsertAction(TextArea textArea, char ch) |
||||
{ |
||||
if ((dataType == DataType.XmlElement) || (dataType == DataType.XmlAttributeValue)) { |
||||
textArea.InsertString(text); |
||||
} |
||||
else if (dataType == DataType.NamespaceUri) { |
||||
textArea.InsertString(String.Concat("\"", text, "\"")); |
||||
} else { |
||||
// Insert an attribute.
|
||||
Caret caret = textArea.Caret; |
||||
textArea.InsertString(String.Concat(text, "=\"\"")); |
||||
|
||||
// Move caret into the middle of the attribute quotes.
|
||||
caret.Position = textArea.Document.OffsetToPosition(caret.Offset - 1); |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
public int CompareTo(object obj) |
||||
{ |
||||
if ((obj == null) || !(obj is XmlCompletionData)) { |
||||
return -1; |
||||
} |
||||
return text.CompareTo(((XmlCompletionData)obj).text); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,302 @@
@@ -0,0 +1,302 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using System; |
||||
using System.Collections; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// A collection that stores <see cref='XmlCompletionData'/> objects.
|
||||
/// </summary>
|
||||
[Serializable()] |
||||
public class XmlCompletionDataCollection : CollectionBase { |
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref='XmlCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
public XmlCompletionDataCollection() |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref='XmlCompletionDataCollection'/> based on another <see cref='XmlCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
/// <param name='val'>
|
||||
/// A <see cref='XmlCompletionDataCollection'/> from which the contents are copied
|
||||
/// </param>
|
||||
public XmlCompletionDataCollection(XmlCompletionDataCollection val) |
||||
{ |
||||
this.AddRange(val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref='XmlCompletionDataCollection'/> containing any array of <see cref='XmlCompletionData'/> objects.
|
||||
/// </summary>
|
||||
/// <param name='val'>
|
||||
/// A array of <see cref='XmlCompletionData'/> objects with which to intialize the collection
|
||||
/// </param>
|
||||
public XmlCompletionDataCollection(XmlCompletionData[] val) |
||||
{ |
||||
this.AddRange(val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Represents the entry at the specified index of the <see cref='XmlCompletionData'/>.
|
||||
/// </summary>
|
||||
/// <param name='index'>The zero-based index of the entry to locate in the collection.</param>
|
||||
/// <value>The entry at the specified index of the collection.</value>
|
||||
/// <exception cref='ArgumentOutOfRangeException'><paramref name='index'/> is outside the valid range of indexes for the collection.</exception>
|
||||
public XmlCompletionData this[int index] { |
||||
get { |
||||
return ((XmlCompletionData)(List[index])); |
||||
} |
||||
set { |
||||
List[index] = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds a <see cref='XmlCompletionData'/> with the specified value to the
|
||||
/// <see cref='XmlCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If the completion data already exists in the collection it is not added.
|
||||
/// </remarks>
|
||||
/// <param name='val'>The <see cref='XmlCompletionData'/> to add.</param>
|
||||
/// <returns>The index at which the new element was inserted.</returns>
|
||||
/// <seealso cref='XmlCompletionDataCollection.AddRange'/>
|
||||
public int Add(XmlCompletionData val) |
||||
{ |
||||
int index = -1; |
||||
if (!Contains(val)) { |
||||
index = List.Add(val); |
||||
} |
||||
return index; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Copies the elements of an array to the end of the <see cref='XmlCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
/// <param name='val'>
|
||||
/// An array of type <see cref='XmlCompletionData'/> containing the objects to add to the collection.
|
||||
/// </param>
|
||||
/// <seealso cref='XmlCompletionDataCollection.Add'/>
|
||||
public void AddRange(XmlCompletionData[] val) |
||||
{ |
||||
for (int i = 0; i < val.Length; i++) { |
||||
this.Add(val[i]); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds the contents of another <see cref='XmlCompletionDataCollection'/> to the end of the collection.
|
||||
/// </summary>
|
||||
/// <param name='val'>
|
||||
/// A <see cref='XmlCompletionDataCollection'/> containing the objects to add to the collection.
|
||||
/// </param>
|
||||
/// <seealso cref='XmlCompletionDataCollection.Add'/>
|
||||
public void AddRange(XmlCompletionDataCollection val) |
||||
{ |
||||
for (int i = 0; i < val.Count; i++) |
||||
{ |
||||
this.Add(val[i]); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the
|
||||
/// <see cref='XmlCompletionDataCollection'/> contains the specified <see cref='XmlCompletionData'/>.
|
||||
/// </summary>
|
||||
/// <param name='val'>The <see cref='XmlCompletionData'/> to locate.</param>
|
||||
/// <returns>
|
||||
/// <see langword='true'/> if the <see cref='XmlCompletionData'/> is contained in the collection;
|
||||
/// otherwise, <see langword='false'/>.
|
||||
/// </returns>
|
||||
/// <seealso cref='XmlCompletionDataCollection.IndexOf'/>
|
||||
public bool Contains(XmlCompletionData val) |
||||
{ |
||||
if (val.Text != null) { |
||||
if (val.Text.Length > 0) { |
||||
return Contains(val.Text); |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
public bool Contains(string name) |
||||
{ |
||||
bool contains = false; |
||||
|
||||
foreach (XmlCompletionData data in this) { |
||||
if (data.Text != null) { |
||||
if (data.Text.Length > 0) { |
||||
if (data.Text == name) { |
||||
contains = true; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
return contains; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Copies the <see cref='XmlCompletionDataCollection'/> values to a one-dimensional <see cref='Array'/> instance at the
|
||||
/// specified index.
|
||||
/// </summary>
|
||||
/// <param name='array'>The one-dimensional <see cref='Array'/> that is the destination of the values copied from <see cref='XmlCompletionDataCollection'/>.</param>
|
||||
/// <param name='index'>The index in <paramref name='array'/> where copying begins.</param>
|
||||
/// <exception cref='ArgumentException'>
|
||||
/// <para><paramref name='array'/> is multidimensional.</para>
|
||||
/// <para>-or-</para>
|
||||
/// <para>The number of elements in the <see cref='XmlCompletionDataCollection'/> is greater than
|
||||
/// the available space between <paramref name='arrayIndex'/> and the end of
|
||||
/// <paramref name='array'/>.</para>
|
||||
/// </exception>
|
||||
/// <exception cref='ArgumentNullException'><paramref name='array'/> is <see langword='null'/>. </exception>
|
||||
/// <exception cref='ArgumentOutOfRangeException'><paramref name='arrayIndex'/> is less than <paramref name='array'/>'s lowbound. </exception>
|
||||
/// <seealso cref='Array'/>
|
||||
public void CopyTo(XmlCompletionData[] array, int index) |
||||
{ |
||||
List.CopyTo(array, index); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Copies the <see cref='XmlCompletionDataCollection'/> values to a one-dimensional <see cref='Array'/> instance at the
|
||||
/// specified index.
|
||||
/// </summary>
|
||||
public void CopyTo(ICompletionData[] array, int index) |
||||
{ |
||||
List.CopyTo(array, index); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the index of a <see cref='XmlCompletionData'/> in
|
||||
/// the <see cref='XmlCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
/// <param name='val'>The <see cref='XmlCompletionData'/> to locate.</param>
|
||||
/// <returns>
|
||||
/// The index of the <see cref='XmlCompletionData'/> of <paramref name='val'/> in the
|
||||
/// <see cref='XmlCompletionDataCollection'/>, if found; otherwise, -1.
|
||||
/// </returns>
|
||||
/// <seealso cref='XmlCompletionDataCollection.Contains'/>
|
||||
public int IndexOf(XmlCompletionData val) |
||||
{ |
||||
return List.IndexOf(val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Inserts a <see cref='XmlCompletionData'/> into the <see cref='XmlCompletionDataCollection'/> at the specified index.
|
||||
/// </summary>
|
||||
/// <param name='index'>The zero-based index where <paramref name='val'/> should be inserted.</param>
|
||||
/// <param name='val'>The <see cref='XmlCompletionData'/> to insert.</param>
|
||||
/// <seealso cref='XmlCompletionDataCollection.Add'/>
|
||||
public void Insert(int index, XmlCompletionData val) |
||||
{ |
||||
List.Insert(index, val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns an array of <see cref="ICompletionData"/> items.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ICompletionData[] ToArray() |
||||
{ |
||||
ICompletionData[] data = new ICompletionData[Count]; |
||||
CopyTo(data, 0); |
||||
return data; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator that can iterate through the <see cref='XmlCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
/// <seealso cref='IEnumerator'/>
|
||||
public new XmlCompletionDataEnumerator GetEnumerator() |
||||
{ |
||||
return new XmlCompletionDataEnumerator(this); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes a specific <see cref='XmlCompletionData'/> from the <see cref='XmlCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
/// <param name='val'>The <see cref='XmlCompletionData'/> to remove from the <see cref='XmlCompletionDataCollection'/>.</param>
|
||||
/// <exception cref='ArgumentException'><paramref name='val'/> is not found in the Collection.</exception>
|
||||
public void Remove(XmlCompletionData val) |
||||
{ |
||||
List.Remove(val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Enumerator that can iterate through a XmlCompletionDataCollection.
|
||||
/// </summary>
|
||||
/// <seealso cref='IEnumerator'/>
|
||||
/// <seealso cref='XmlCompletionDataCollection'/>
|
||||
/// <seealso cref='XmlCompletionData'/>
|
||||
public class XmlCompletionDataEnumerator : IEnumerator |
||||
{ |
||||
IEnumerator baseEnumerator; |
||||
IEnumerable temp; |
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref='XmlCompletionDataEnumerator'/>.
|
||||
/// </summary>
|
||||
public XmlCompletionDataEnumerator(XmlCompletionDataCollection mappings) |
||||
{ |
||||
this.temp = ((IEnumerable)(mappings)); |
||||
this.baseEnumerator = temp.GetEnumerator(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the current <see cref='XmlCompletionData'/> in the <seealso cref='XmlCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
public XmlCompletionData Current { |
||||
get { |
||||
return ((XmlCompletionData)(baseEnumerator.Current)); |
||||
} |
||||
} |
||||
|
||||
object IEnumerator.Current { |
||||
get { |
||||
return baseEnumerator.Current; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Advances the enumerator to the next <see cref='XmlCompletionData'/> of the <see cref='XmlCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
public bool MoveNext() |
||||
{ |
||||
return baseEnumerator.MoveNext(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Sets the enumerator to its initial position, which is before the first element in the <see cref='XmlCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
public void Reset() |
||||
{ |
||||
baseEnumerator.Reset(); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using System; |
||||
using System.Windows.Forms; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
public class XmlCompletionDataImageList |
||||
{ |
||||
XmlCompletionDataImageList() |
||||
{ |
||||
} |
||||
|
||||
public static ImageList GetImageList() |
||||
{ |
||||
ImageList imageList = new ImageList(); |
||||
|
||||
return imageList; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,193 @@
@@ -0,0 +1,193 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor; |
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using System; |
||||
using System.Collections; |
||||
using System.Windows.Forms; |
||||
using System.Xml; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Provides the autocomplete (intellisense) data for an
|
||||
/// xml document that specifies a known schema.
|
||||
/// </summary>
|
||||
public class XmlCompletionDataProvider : ICompletionDataProvider |
||||
{ |
||||
XmlSchemaCompletionDataCollection schemaCompletionDataItems; |
||||
XmlSchemaCompletionData defaultSchemaCompletionData; |
||||
string defaultNamespacePrefix = String.Empty; |
||||
string preSelection = null; |
||||
|
||||
public XmlCompletionDataProvider(XmlSchemaCompletionDataCollection schemaCompletionDataItems, XmlSchemaCompletionData defaultSchemaCompletionData, string defaultNamespacePrefix) |
||||
{ |
||||
this.schemaCompletionDataItems = schemaCompletionDataItems; |
||||
this.defaultSchemaCompletionData = defaultSchemaCompletionData; |
||||
this.defaultNamespacePrefix = defaultNamespacePrefix; |
||||
} |
||||
|
||||
public ImageList ImageList { |
||||
get |
||||
{ |
||||
return XmlCompletionDataImageList.GetImageList(); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the preselected text.
|
||||
/// </summary>
|
||||
public string PreSelection { |
||||
get |
||||
{ |
||||
return preSelection; |
||||
} |
||||
} |
||||
|
||||
public int DefaultIndex { |
||||
get { |
||||
return -1; |
||||
} |
||||
} |
||||
|
||||
public ICompletionData[] GenerateCompletionData(string fileName, TextArea textArea, char charTyped) |
||||
{ |
||||
preSelection = null; |
||||
string text = String.Concat(textArea.Document.GetText(0, textArea.Caret.Offset), charTyped); |
||||
|
||||
switch (charTyped) { |
||||
case '=': |
||||
// Namespace intellisense.
|
||||
if (XmlParser.IsNamespaceDeclaration(text, text.Length)) { |
||||
return schemaCompletionDataItems.GetNamespaceCompletionData();; |
||||
} |
||||
break; |
||||
case '<': |
||||
// Child element intellisense.
|
||||
XmlElementPath parentPath = XmlParser.GetParentElementPath(text, text.Length); |
||||
if (parentPath.Elements.Count > 0) { |
||||
return GetChildElementCompletionData(parentPath); |
||||
} else if (defaultSchemaCompletionData != null) { |
||||
return defaultSchemaCompletionData.GetElementCompletionData(defaultNamespacePrefix); |
||||
} |
||||
break; |
||||
|
||||
case ' ': |
||||
// Attribute intellisense.
|
||||
XmlElementPath path = XmlParser.GetActiveElementStartPath(text, text.Length); |
||||
if (path.Elements.Count > 0) { |
||||
return GetAttributeCompletionData(path); |
||||
} |
||||
break; |
||||
|
||||
default: |
||||
|
||||
// Attribute value intellisense.
|
||||
if (XmlParser.IsAttributeValueChar(charTyped)) { |
||||
string attributeName = XmlParser.GetAttributeName(text, text.Length); |
||||
if (attributeName.Length > 0) { |
||||
XmlElementPath elementPath = XmlParser.GetActiveElementStartPath(text, text.Length); |
||||
if (elementPath.Elements.Count > 0) { |
||||
preSelection = charTyped.ToString(); |
||||
return GetAttributeValueCompletionData(elementPath, attributeName); |
||||
} |
||||
} |
||||
} |
||||
break; |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
ICompletionData[] GetChildElementCompletionData(XmlElementPath path) |
||||
{ |
||||
ICompletionData[] completionData = null; |
||||
|
||||
XmlSchemaCompletionData schema = FindSchema(path); |
||||
if (schema != null) { |
||||
completionData = schema.GetChildElementCompletionData(path); |
||||
} |
||||
|
||||
return completionData; |
||||
} |
||||
|
||||
ICompletionData[] GetAttributeCompletionData(XmlElementPath path) |
||||
{ |
||||
ICompletionData[] completionData = null; |
||||
|
||||
XmlSchemaCompletionData schema = FindSchema(path); |
||||
if (schema != null) { |
||||
completionData = schema.GetAttributeCompletionData(path); |
||||
} |
||||
|
||||
return completionData; |
||||
} |
||||
|
||||
ICompletionData[] GetAttributeValueCompletionData(XmlElementPath path, string name) |
||||
{ |
||||
ICompletionData[] completionData = null; |
||||
|
||||
XmlSchemaCompletionData schema = FindSchema(path); |
||||
if (schema != null) { |
||||
completionData = schema.GetAttributeValueCompletionData(path, name); |
||||
} |
||||
|
||||
return completionData; |
||||
} |
||||
|
||||
XmlSchemaCompletionData FindSchema(XmlElementPath path) |
||||
{ |
||||
XmlSchemaCompletionData schemaData = null; |
||||
|
||||
if (path.Elements.Count > 0) { |
||||
string namespaceUri = path.Elements[0].Namespace; |
||||
if (namespaceUri.Length > 0) { |
||||
schemaData = schemaCompletionDataItems[namespaceUri]; |
||||
} else if (defaultSchemaCompletionData != null) { |
||||
|
||||
// Use the default schema namespace if none
|
||||
// specified in a xml element path, otherwise
|
||||
// we will not find any attribute or element matches
|
||||
// later.
|
||||
foreach (QualifiedName name in path.Elements) { |
||||
if (name.Namespace.Length == 0) { |
||||
name.Namespace = defaultSchemaCompletionData.NamespaceUri; |
||||
} |
||||
} |
||||
schemaData = defaultSchemaCompletionData; |
||||
} |
||||
} |
||||
|
||||
return schemaData; |
||||
} |
||||
|
||||
// string GetTextFromStartToEndOfCurrentLine(TextArea textArea)
|
||||
// {
|
||||
// LineSegment line = textArea.Document.GetLineSegment(textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset));
|
||||
// if (line != null) {
|
||||
// return textArea.Document.GetText(0, line.Offset + line.Length);
|
||||
// }
|
||||
//
|
||||
// return String.Empty;//textArea.Document.GetText(0, textArea.Caret.Offset);
|
||||
// }
|
||||
} |
||||
} |
@ -0,0 +1,72 @@
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using System; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Display binding for the xml editor.
|
||||
/// </summary>
|
||||
public class XmlDisplayBinding : IDisplayBinding |
||||
{ |
||||
public XmlDisplayBinding() |
||||
{ |
||||
} |
||||
|
||||
#region IDisplayBinding
|
||||
|
||||
public IViewContent CreateContentForLanguage(string languageName, string content) |
||||
{ |
||||
XmlView view = new XmlView(); |
||||
view.LoadContent(content); |
||||
return view; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Can create content for the 'XML' language.
|
||||
/// </summary>
|
||||
public bool CanCreateContentForLanguage(string languageName) |
||||
{ |
||||
return XmlView.IsLanguageHandled(languageName); |
||||
} |
||||
|
||||
public IViewContent CreateContentForFile(string fileName) |
||||
{ |
||||
XmlView view = new XmlView(); |
||||
view.Load(fileName); |
||||
return view; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Can only create content for file with extensions that are
|
||||
/// known to be xml files as specified in the SyntaxModes.xml file.
|
||||
/// </summary>
|
||||
public bool CanCreateContentForFile(string fileName) |
||||
{ |
||||
return XmlView.IsFileNameHandled(fileName); |
||||
} |
||||
|
||||
#endregion
|
||||
} |
||||
} |
@ -0,0 +1,113 @@
@@ -0,0 +1,113 @@
|
||||
<AddIn name = "Xml Editor" |
||||
author = "Matt Ward" |
||||
copyright = "GPL" |
||||
url = "http://www.icsharpcode.net" |
||||
description = "Xml Editor" |
||||
version = "1.0.0"> |
||||
|
||||
<Runtime> |
||||
<Import assembly="XmlEditor.dll"/> |
||||
<Import assembly="../../../../bin/SharpDevelop.DefaultTexteditor.dll"/> |
||||
</Runtime> |
||||
|
||||
<!-- Xml Editor View --> |
||||
<Extension path = "/SharpDevelop/Workbench/DisplayBindings"> |
||||
<DisplayBinding id = "XmlEditor" |
||||
insertbefore = "Text" |
||||
supportedformats = "Text Files,Source Files" |
||||
class = "ICSharpCode.XmlEditor.XmlDisplayBinding"/> |
||||
</Extension> |
||||
|
||||
<!-- Xml parser used to initiate the folding update --> |
||||
<Extension path = "/Workspace/Parser"> |
||||
<Class id = "XmlFoldingParser" |
||||
class = "ICSharpCode.XmlEditor.Parser"/> |
||||
</Extension> |
||||
|
||||
<!-- Right click menu --> |
||||
<Extension path = "/SharpDevelop/ViewContent/XmlEditor/ContextMenu"> |
||||
<MenuItem id = "Cut" |
||||
label = "${res:XML.TextAreaContextMenu.Cut}" |
||||
icon = "Icons.16x16.CutIcon" |
||||
shortcut = "Control|X" |
||||
class = "ICSharpCode.SharpDevelop.Commands.Cut"/> |
||||
<MenuItem id = "Copy" |
||||
label = "${res:XML.TextAreaContextMenu.Copy}" |
||||
icon = "Icons.16x16.CopyIcon" |
||||
shortcut = "Control|C" |
||||
class = "ICSharpCode.SharpDevelop.Commands.Copy"/> |
||||
<MenuItem id = "Paste" |
||||
label = "${res:XML.TextAreaContextMenu.Paste}" |
||||
icon = "Icons.16x16.PasteIcon" |
||||
shortcut = "Control|V" |
||||
class = "ICSharpCode.SharpDevelop.Commands.Paste"/> |
||||
<MenuItem id = "Delete" |
||||
label = "${res:XML.MainMenu.EditMenu.Delete}" |
||||
icon = "Icons.16x16.DeleteIcon" |
||||
class = "ICSharpCode.SharpDevelop.Commands.Delete"/> |
||||
<MenuItem id = "Separator1" label = "-" /> |
||||
<MenuItem id = "Save" |
||||
label = "${res:XML.MainMenu.FileMenu.Save}" |
||||
icon = "Icons.16x16.SaveIcon" |
||||
shortcut = "Control|S" |
||||
class = "ICSharpCode.SharpDevelop.Commands.SaveFile"/> |
||||
<MenuItem id = "SaveAs" |
||||
label = "${res:XML.MainMenu.FileMenu.SaveAs}" |
||||
class = "ICSharpCode.SharpDevelop.Commands.SaveFileAs"/> |
||||
<MenuItem id = "File" |
||||
label = "${res:XML.MainMenu.FileMenu.Close}" |
||||
class = "ICSharpCode.SharpDevelop.Commands.CloseFile"/> |
||||
<MenuItem id = "Separator2" label = "-" /> |
||||
<MenuItem id = "CreateSchema" |
||||
label = "${res:ICSharpCode.XmlEditor.CreateSchemaMenuLabel}" |
||||
class = "ICSharpCode.XmlEditor.CreateSchemaCommand" /> |
||||
<MenuItem id = "ValidateXml" |
||||
label = "${res:ICSharpCode.XmlEditor.ValidateXmlMenuLabel}" |
||||
class = "ICSharpCode.XmlEditor.ValidateXmlCommand" |
||||
shortcut = "Control|Shift|V" /> |
||||
<MenuItem id = "Indent" |
||||
label = "${res:XML.TextAreaContextMenu.Indent}" |
||||
shortcut = "Control|I" |
||||
class = "ICSharpCode.SharpDevelop.DefaultEditor.Commands.IndentSelection" /> |
||||
<MenuItem id = "FileMode" label = "${res:XML.TextAreaContextMenu.FileMode}"> |
||||
<MenuItem id = "HighlightBuilder" label = "boguslabel" class = "ICSharpCode.SharpDevelop.DefaultEditor.Commands.HighlightingTypeBuilder" /> |
||||
</MenuItem> |
||||
<MenuItem id = "Separator3" label = "-" /> |
||||
<MenuItem id = "Options" |
||||
label = "${res:XML.TextAreaContextMenu.BufferOptions}" |
||||
icon = "Icons.16x16.PropertiesIcon" |
||||
class ="ICSharpCode.SharpDevelop.DefaultEditor.Commands.ShowBufferOptions"/> |
||||
</Extension> |
||||
|
||||
<!-- Tools menu option --> |
||||
<Extension path = "/SharpDevelop/Workbench/MainMenu/Tools"> |
||||
<Conditional activewindow = "ICSharpCode.XmlEditor.XmlView"> |
||||
<MenuItem id = "ValidateXml" |
||||
insertbefore = "Separator4" |
||||
label = "${res:ICSharpCode.XmlEditor.ValidateXmlMenuLabel}" |
||||
description = "Validates the xml against the known schemas." |
||||
class = "ICSharpCode.XmlEditor.ValidateXmlCommand" |
||||
shortcut = "Control|Shift|V" |
||||
/> |
||||
</Conditional> |
||||
</Extension> |
||||
|
||||
<!-- Options panel --> |
||||
<Extension path = "/SharpDevelop/Dialogs/OptionsDialog/TextEditorOptions"> |
||||
|
||||
<DialogPanel id = "XmlSchemasPanel" |
||||
insertafter = "VBSpecificOptions" |
||||
label = "${res:ICSharpCode.XmlEditor.XmlSchemasPanel.Title}" |
||||
class = "ICSharpCode.XmlEditor.XmlSchemasPanel" /> |
||||
<DialogPanel id = "XmlEditorOptionsPanel" |
||||
insertafter = "VBSpecificOptions" |
||||
insertbefore = "XmlSchemasPanel" |
||||
label = "${res:ICSharpCode.XmlEditor.XmlEditorOptionsPanel.Title}" |
||||
class = "ICSharpCode.XmlEditor.XmlEditorOptionsPanel" /> |
||||
</Extension> |
||||
|
||||
<Extension path = "/AddIns/XmlEditor/EditActions"> |
||||
<EditAction id = "XmlCompletionPopup" class = "ICSharpCode.XmlEditor.CodeCompletionPopupCommand" keys = "Control|Space"/> |
||||
</Extension> |
||||
|
||||
</AddIn> |
@ -0,0 +1,90 @@
@@ -0,0 +1,90 @@
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<PropertyGroup> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||
<SchemaVersion>2.0</SchemaVersion> |
||||
<ProjectGuid>{6B717BD1-CD5E-498C-A42E-9E6A4584DC48}</ProjectGuid> |
||||
<RootNamespace>ICSharpCode.XmlEditor</RootNamespace> |
||||
<AssemblyName>XmlEditor</AssemblyName> |
||||
<OutputType>Library</OutputType> |
||||
<WarningLevel>4</WarningLevel> |
||||
<NoStdLib>False</NoStdLib> |
||||
<NoConfig>False</NoConfig> |
||||
<RunPostBuildEvent>OnSuccessfulBuild</RunPostBuildEvent> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
||||
<DebugSymbols>True</DebugSymbols> |
||||
<Optimize>False</Optimize> |
||||
<AllowUnsafeBlocks>False</AllowUnsafeBlocks> |
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> |
||||
<OutputPath>..\..\..\..\..\AddIns\AddIns\DisplayBindings\XmlEditor\</OutputPath> |
||||
<TreatWarningsAsErrors>False</TreatWarningsAsErrors> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
||||
<DebugSymbols>False</DebugSymbols> |
||||
<Optimize>True</Optimize> |
||||
<AllowUnsafeBlocks>False</AllowUnsafeBlocks> |
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> |
||||
<OutputPath>..\..\..\..\..\AddIns\AddIns\DisplayBindings\XmlEditor\</OutputPath> |
||||
<TreatWarningsAsErrors>False</TreatWarningsAsErrors> |
||||
</PropertyGroup> |
||||
<ItemGroup> |
||||
<Reference Include="System" /> |
||||
<Reference Include="System.Data" /> |
||||
<Reference Include="System.Drawing" /> |
||||
<Reference Include="System.Windows.Forms" /> |
||||
<Reference Include="System.Xml" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="AssemblyInfo.cs" /> |
||||
<Compile Include="XmlEditorControl.cs" /> |
||||
<Compile Include="XmlCompletionDataProvider.cs" /> |
||||
<Compile Include="XmlCompletionData.cs" /> |
||||
<Compile Include="XmlCompletionDataImageList.cs" /> |
||||
<Compile Include="XmlParser.cs" /> |
||||
<Compile Include="XmlSchemaCompletionData.cs" /> |
||||
<Compile Include="XmlSchemaCompletionDataCollection.cs" /> |
||||
<Compile Include="XmlFoldingStrategy.cs" /> |
||||
<Compile Include="QualifiedName.cs" /> |
||||
<Compile Include="XmlElementPath.cs" /> |
||||
<Compile Include="QualifiedNameCollection.cs" /> |
||||
<Compile Include="XmlCompletionDataCollection.cs" /> |
||||
<Compile Include="XmlDisplayBinding.cs" /> |
||||
<Compile Include="XmlView.cs" /> |
||||
<Compile Include="XmlSchemaManager.cs" /> |
||||
<Compile Include="Parser.cs" /> |
||||
<Compile Include="ValidateXmlCommand.cs" /> |
||||
<Compile Include="XmlSchemasPanel.cs" /> |
||||
<Compile Include="XmlSchemaListBoxItem.cs" /> |
||||
<Compile Include="CodeCompletionWindow.cs" /> |
||||
<Compile Include="XmlEditorAddInOptions.cs" /> |
||||
<Compile Include="SelectXmlSchemaForm.cs" /> |
||||
<Compile Include="CodeCompletionPopupCommand.cs" /> |
||||
<Compile Include="XmlSchemaAssociation.cs" /> |
||||
<Compile Include="XmlSchemaAssociationListBoxItem.cs" /> |
||||
<Compile Include="XmlEditorOptionsPanel.cs" /> |
||||
<Compile Include="CreateSchemaCommand.cs" /> |
||||
<Compile Include="EncodedStringWriter.cs" /> |
||||
<EmbeddedResource Include="XmlSchemasPanel.xfrm" /> |
||||
<EmbeddedResource Include="SelectXmlSchema.xfrm" /> |
||||
<EmbeddedResource Include="XmlEditorOptionsPanel.xfrm" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<ProjectReference Include="..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj"> |
||||
<Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project> |
||||
<Name>ICSharpCode.SharpDevelop</Name> |
||||
<Private>False</Private> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\..\..\..\Main\Core\Project\ICSharpCode.Core.csproj"> |
||||
<Project>{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}</Project> |
||||
<Name>ICSharpCode.Core</Name> |
||||
<Private>False</Private> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\..\..\..\Libraries\ICSharpCode.TextEditor\Project\ICSharpCode.TextEditor.csproj"> |
||||
<Project>{2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}</Project> |
||||
<Name>ICSharpCode.TextEditor</Name> |
||||
<Private>False</Private> |
||||
</ProjectReference> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> |
||||
</Project> |
@ -0,0 +1,4 @@
@@ -0,0 +1,4 @@
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' " /> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " /> |
||||
</Project> |
@ -0,0 +1,137 @@
@@ -0,0 +1,137 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor.
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.Core; |
||||
using System; |
||||
using System.Diagnostics; |
||||
using System.IO; |
||||
using System.Reflection; |
||||
using System.Xml; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// The Xml Editor add-in options.
|
||||
/// </summary>
|
||||
public static class XmlEditorAddInOptions |
||||
{ |
||||
public static readonly string OptionsProperty = "XmlEditor.AddIn.Options"; |
||||
public static readonly string ShowAttributesWhenFoldedPropertyName = "ShowAttributesWhenFolded"; |
||||
public static readonly string ShowSchemaAnnotationPropertyName = "ShowSchemaAnnotation"; |
||||
|
||||
static Properties properties; |
||||
|
||||
static XmlEditorAddInOptions() |
||||
{ |
||||
properties = PropertyService.Get(OptionsProperty, new Properties()); |
||||
} |
||||
|
||||
static Properties Properties { |
||||
get { |
||||
Debug.Assert(properties != null); |
||||
return properties; |
||||
} |
||||
} |
||||
|
||||
public static event PropertyChangedEventHandler PropertyChanged { |
||||
add { Properties.PropertyChanged += value; } |
||||
remove { Properties.PropertyChanged += value; } |
||||
} |
||||
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// Gets an association between a schema and a file extension.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>The property will be an xml element when the SharpDevelopProperties.xml
|
||||
/// is read on startup. The property will be a schema association
|
||||
/// if the user changes the schema associated with the file
|
||||
/// extension in tools->options.</para>
|
||||
/// <para>The normal way of doing things is to
|
||||
/// pass the GetProperty method a default value which auto-magically
|
||||
/// turns the xml element into a schema association so we would not
|
||||
/// have to check for both. In this case, however, I do not want
|
||||
/// a default saved to the SharpDevelopProperties.xml file unless the user
|
||||
/// makes a change using Tools->Options.</para>
|
||||
/// <para>If we have a file extension that is currently missing a default
|
||||
/// schema then if we ship the schema at a later date the association will
|
||||
/// be updated by the code if the user has not changed the settings themselves.
|
||||
/// </para>
|
||||
/// <para>For example, the initial release of the xml editor add-in had
|
||||
/// no default schema for .xsl files, by default it was associated with
|
||||
/// no schema and this setting is saved if the user ever viewed the settings
|
||||
/// in the tools->options dialog. Now, after the initial release the
|
||||
/// .xsl schema was created and shipped with SharpDevelop, there is
|
||||
/// no way to associate this schema to .xsl files by default since
|
||||
/// the property exists in the SharpDevelopProperties.xml file.</para>
|
||||
/// <para>An alternative way of doing this might be to have the
|
||||
/// config info in the schema itself, which a special SharpDevelop
|
||||
/// namespace. I believe this is what Visual Studio does. This
|
||||
/// way is not as flexible since it requires the user to locate
|
||||
/// the schema and change the association manually.</para>
|
||||
/// </remarks>
|
||||
public static XmlSchemaAssociation GetSchemaAssociation(string extension) |
||||
{ |
||||
object property = Properties.Get(extension); |
||||
|
||||
XmlSchemaAssociation association = property as XmlSchemaAssociation; |
||||
XmlElement element = property as XmlElement; |
||||
|
||||
if (element != null) { |
||||
association = XmlSchemaAssociation.ConvertFromXmlElement(element) as XmlSchemaAssociation; |
||||
} |
||||
|
||||
// Use default?
|
||||
if (association == null) { |
||||
association = XmlSchemaAssociation.GetDefaultAssociation(extension); |
||||
} |
||||
|
||||
return association; |
||||
} |
||||
|
||||
public static void SetSchemaAssociation(XmlSchemaAssociation association) |
||||
{ |
||||
Properties.Set(association.Extension, association); |
||||
} |
||||
|
||||
public static bool ShowAttributesWhenFolded { |
||||
get { |
||||
return Properties.Get(ShowAttributesWhenFoldedPropertyName, false); |
||||
} |
||||
|
||||
set { |
||||
Properties.Set(ShowAttributesWhenFoldedPropertyName, value); |
||||
} |
||||
} |
||||
|
||||
public static bool ShowSchemaAnnotation { |
||||
get { |
||||
return Properties.Get(ShowSchemaAnnotationPropertyName, true); |
||||
} |
||||
|
||||
set { |
||||
Properties.Set(ShowSchemaAnnotationPropertyName, value); |
||||
} |
||||
} |
||||
|
||||
#endregion
|
||||
} |
||||
} |
@ -0,0 +1,342 @@
@@ -0,0 +1,342 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.DefaultEditor; |
||||
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.TextEditor; |
||||
using ICSharpCode.TextEditor.Actions; |
||||
using ICSharpCode.TextEditor.Document; |
||||
using System; |
||||
using System.ComponentModel; |
||||
using System.Drawing; |
||||
using System.Windows.Forms; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Xml editor derived from the SharpDevelop TextEditor control.
|
||||
/// </summary>
|
||||
public class XmlEditorControl : ICSharpCode.TextEditor.TextEditorControl |
||||
{ |
||||
static readonly string editActionsPath = "/AddIns/XmlEditor/EditActions"; |
||||
static readonly string contextMenuPath = "/SharpDevelop/ViewContent/XmlEditor/ContextMenu"; |
||||
CodeCompletionWindow codeCompletionWindow; |
||||
XmlSchemaCompletionDataCollection schemaCompletionDataItems = new XmlSchemaCompletionDataCollection(); |
||||
XmlSchemaCompletionData defaultSchemaCompletionData = null; |
||||
string defaultNamespacePrefix = String.Empty; |
||||
|
||||
public XmlEditorControl() |
||||
{ |
||||
XmlFormattingStrategy strategy = new XmlFormattingStrategy(); |
||||
Document.FormattingStrategy = (IFormattingStrategy)strategy; |
||||
|
||||
Document.HighlightingStrategy = HighlightingManager.Manager.FindHighlighter("XML"); |
||||
Document.FoldingManager.FoldingStrategy = new XmlFoldingStrategy(); |
||||
TextEditorProperties = new SharpDevelopTextEditorProperties(); |
||||
|
||||
GenerateEditActions(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the schemas that the xml editor will use.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Probably should have NOT a 'set' property, but allowing one
|
||||
/// allows us to share the completion data amongst multiple
|
||||
/// xml editor controls.
|
||||
/// </remarks>
|
||||
public XmlSchemaCompletionDataCollection SchemaCompletionDataItems { |
||||
get { |
||||
return schemaCompletionDataItems; |
||||
} |
||||
set { |
||||
schemaCompletionDataItems = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default namespace prefix.
|
||||
/// </summary>
|
||||
public string DefaultNamespacePrefix { |
||||
get { |
||||
return defaultNamespacePrefix; |
||||
} |
||||
set { |
||||
defaultNamespacePrefix = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default schema completion data associated with this
|
||||
/// view.
|
||||
/// </summary>
|
||||
public XmlSchemaCompletionData DefaultSchemaCompletionData { |
||||
get { |
||||
return defaultSchemaCompletionData; |
||||
} |
||||
|
||||
set { |
||||
defaultSchemaCompletionData = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Called when the user hits Ctrl+Space.
|
||||
/// </summary>
|
||||
public void ShowCompletionWindow() |
||||
{ |
||||
if (!IsCaretAtDocumentStart) { |
||||
// Find character before cursor.
|
||||
|
||||
char ch = GetCharacterBeforeCaret(); |
||||
|
||||
HandleKeyPress(ch); |
||||
} |
||||
} |
||||
|
||||
protected override void InitializeTextAreaControl(TextAreaControl newControl) |
||||
{ |
||||
base.InitializeTextAreaControl(newControl); |
||||
newControl.TextArea.KeyEventHandler += new ICSharpCode.TextEditor.KeyEventHandler(HandleKeyPress); |
||||
|
||||
newControl.ContextMenuStrip = MenuService.CreateContextMenu(this, contextMenuPath); |
||||
newControl.SelectionManager.SelectionChanged += new EventHandler(SelectionChanged); |
||||
newControl.Document.DocumentChanged += new DocumentEventHandler(DocumentChanged); |
||||
newControl.Caret.PositionChanged += new EventHandler(CaretPositionChanged); |
||||
newControl.TextArea.ClipboardHandler.CopyText += new CopyTextEventHandler(ClipboardHandlerCopyText); |
||||
|
||||
newControl.MouseWheel += new MouseEventHandler(TextAreaMouseWheel); |
||||
newControl.DoHandleMousewheel = false; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Captures the user's key presses.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>The code completion window ProcessKeyEvent is not perfect
|
||||
/// when typing xml. If enter a space or ':' the text is
|
||||
/// autocompleted when it should not be.</para>
|
||||
/// <para>The code completion window has one predefined width,
|
||||
/// which cuts off any long namespaces that we show.</para>
|
||||
/// <para>The above issues have been resolved by duplicating
|
||||
/// the code completion window and fixing the problems in the
|
||||
/// duplicated class.</para>
|
||||
/// </remarks>
|
||||
protected bool HandleKeyPress(char ch) |
||||
{ |
||||
if (IsCodeCompletionWindowOpen) { |
||||
if (codeCompletionWindow.ProcessKeyEvent(ch)) { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
try { |
||||
switch (ch) { |
||||
case '<': |
||||
case ' ': |
||||
case '=': |
||||
ShowCompletionWindow(ch); |
||||
return false; |
||||
default: |
||||
if (XmlParser.IsAttributeValueChar(ch)) { |
||||
if (IsInsideQuotes(ActiveTextAreaControl.TextArea)) { |
||||
// Have to insert the character ourselves since
|
||||
// it is not actually inserted yet. If it is not
|
||||
// inserted now the code completion will not work
|
||||
// since the completion data provider attempts to
|
||||
// include the key typed as the pre-selected text.
|
||||
InsertCharacter(ch); |
||||
ShowCompletionWindow(ch); |
||||
return true; |
||||
} |
||||
} |
||||
break; |
||||
} |
||||
} catch (Exception e) { |
||||
MessageService.ShowError(e); |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
bool IsCodeCompletionEnabled { |
||||
get { |
||||
return ICSharpCode.SharpDevelop.Dom.CodeCompletionOptions.EnableCodeCompletion; |
||||
} |
||||
} |
||||
|
||||
void CodeCompletionWindowClosed(object sender, EventArgs e) |
||||
{ |
||||
codeCompletionWindow.Closed -= new EventHandler(CodeCompletionWindowClosed); |
||||
codeCompletionWindow.Dispose(); |
||||
codeCompletionWindow = null; |
||||
} |
||||
|
||||
bool IsCodeCompletionWindowOpen { |
||||
get { |
||||
return ((codeCompletionWindow != null) && (!codeCompletionWindow.IsDisposed)); |
||||
} |
||||
} |
||||
|
||||
void ShowCompletionWindow(char ch) |
||||
{ |
||||
if (IsCodeCompletionWindowOpen) { |
||||
codeCompletionWindow.Close(); |
||||
} |
||||
|
||||
if (IsCodeCompletionEnabled) { |
||||
XmlCompletionDataProvider completionDataProvider = new XmlCompletionDataProvider(schemaCompletionDataItems, defaultSchemaCompletionData, defaultNamespacePrefix); |
||||
codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(ParentForm, this, FileName, completionDataProvider, ch, XmlEditorAddInOptions.ShowSchemaAnnotation); |
||||
|
||||
if (codeCompletionWindow != null) { |
||||
codeCompletionWindow.Closed += new EventHandler(CodeCompletionWindowClosed); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void GenerateEditActions() |
||||
{ |
||||
IEditAction[] actions = (IEditAction[])(AddInTree.BuildItems(editActionsPath, this, false).ToArray(typeof(IEditAction))); |
||||
|
||||
foreach (IEditAction action in actions) { |
||||
foreach (Keys key in action.Keys) { |
||||
editactions[key] = action; |
||||
} |
||||
} |
||||
} |
||||
|
||||
void DocumentChanged(object sender, DocumentEventArgs e) |
||||
{ |
||||
} |
||||
|
||||
void SelectionChanged(object sender, EventArgs e) |
||||
{ |
||||
} |
||||
|
||||
void ClipboardHandlerCopyText(object sender, CopyTextEventArgs e) |
||||
{ |
||||
SideBarView.PutInClipboardRing(e.Text); |
||||
} |
||||
|
||||
void CaretPositionChanged(object sender, EventArgs e) |
||||
{ |
||||
StatusBarService.SetCaretPosition(ActiveTextAreaControl.TextArea.TextView.GetVisualColumn(ActiveTextAreaControl.Caret.Line, ActiveTextAreaControl.Caret.Column), ActiveTextAreaControl.Caret.Line, ActiveTextAreaControl.Caret.Column); |
||||
} |
||||
|
||||
void TextAreaMouseWheel(object sender, MouseEventArgs e) |
||||
{ |
||||
TextAreaControl textAreaControl = (TextAreaControl)sender; |
||||
|
||||
if (IsCodeCompletionWindowOpen && codeCompletionWindow.Visible) { |
||||
codeCompletionWindow.HandleMouseWheel(e); |
||||
} else { |
||||
textAreaControl.HandleMouseWheel(e); |
||||
} |
||||
} |
||||
|
||||
char GetCharacterBeforeCaret() |
||||
{ |
||||
string text = Document.GetText(ActiveTextAreaControl.TextArea.Caret.Offset - 1, 1); |
||||
if (text.Length > 0) { |
||||
return text[0]; |
||||
} |
||||
|
||||
return '\0'; |
||||
} |
||||
|
||||
bool IsCaretAtDocumentStart { |
||||
get { |
||||
return ActiveTextAreaControl.TextArea.Caret.Offset == 0; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Checks whether the caret is inside a set of quotes (" or ').
|
||||
/// </summary>
|
||||
bool IsInsideQuotes(TextArea textArea) |
||||
{ |
||||
bool inside = false; |
||||
|
||||
LineSegment line = textArea.Document.GetLineSegment(textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset)); |
||||
if (line != null) { |
||||
if ((line.Offset + line.Length > textArea.Caret.Offset) && |
||||
(line.Offset < textArea.Caret.Offset)){ |
||||
|
||||
char charAfter = textArea.Document.GetCharAt(textArea.Caret.Offset); |
||||
char charBefore = textArea.Document.GetCharAt(textArea.Caret.Offset - 1); |
||||
|
||||
if (((charBefore == '\'') && (charAfter == '\'')) || |
||||
((charBefore == '\"') && (charAfter == '\"'))) { |
||||
inside = true; |
||||
} |
||||
} |
||||
} |
||||
|
||||
return inside; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Inserts a character into the text editor at the current offset.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This code is copied from the TextArea.SimulateKeyPress method. This
|
||||
/// code is needed to handle an issue with code completion. What if
|
||||
/// we want to include the character just typed as the pre-selected text
|
||||
/// for autocompletion? If we do not insert the character before
|
||||
/// displaying the autocompletion list we cannot set the pre-selected text
|
||||
/// because it is not actually inserted yet. The autocompletion window
|
||||
/// checks the offset of the pre-selected text and closes the window
|
||||
/// if the range is wrong. The offset check is always wrong since the text
|
||||
/// does not actually exist yet. The check occurs in
|
||||
/// CodeCompletionWindow.CaretOffsetChanged:
|
||||
/// <code>[[!CDATA[ int offset = control.ActiveTextAreaControl.Caret.Offset;
|
||||
///
|
||||
/// if (offset < startOffset || offset > endOffset) {
|
||||
/// Close();
|
||||
/// } else {
|
||||
/// codeCompletionListView.SelectItemWithStart(control.Document.GetText(startOffset, offset - startOffset));
|
||||
/// }]]
|
||||
/// </code>
|
||||
/// The Close method is called because the offset is out of the range.
|
||||
/// </remarks>
|
||||
void InsertCharacter(char ch) |
||||
{ |
||||
ActiveTextAreaControl.TextArea.MotherTextEditorControl.BeginUpdate(); |
||||
|
||||
switch (ActiveTextAreaControl.TextArea.Caret.CaretMode) |
||||
{ |
||||
case CaretMode.InsertMode: |
||||
ActiveTextAreaControl.TextArea.InsertChar(ch); |
||||
break; |
||||
case CaretMode.OverwriteMode: |
||||
ActiveTextAreaControl.TextArea.ReplaceChar(ch); |
||||
break; |
||||
} |
||||
int currentLineNr = ActiveTextAreaControl.TextArea.Caret.Line; |
||||
int delta = Document.FormattingStrategy.FormatLine(ActiveTextAreaControl.TextArea, currentLineNr, Document.PositionToOffset(ActiveTextAreaControl.TextArea.Caret.Position), ch); |
||||
|
||||
ActiveTextAreaControl.TextArea.MotherTextEditorControl.EndUpdate(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,62 @@
@@ -0,0 +1,62 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using System; |
||||
using System.Windows.Forms; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Configuration settings for the xml editor.
|
||||
/// </summary>
|
||||
public class XmlEditorOptionsPanel : AbstractOptionPanel |
||||
{ |
||||
static readonly string showAttributesWhenFoldedCheckBoxName = "showAttributesWhenFoldedCheckBox"; |
||||
static readonly string showSchemaAnnotationCheckBoxName = "showSchemaAnnotationCheckBox"; |
||||
|
||||
public XmlEditorOptionsPanel() |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Initialises the panel.
|
||||
/// </summary>
|
||||
public override void LoadPanelContents() |
||||
{ |
||||
SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("ICSharpCode.XmlEditor.XmlEditorOptionsPanel.xfrm")); |
||||
|
||||
((CheckBox)ControlDictionary[showAttributesWhenFoldedCheckBoxName]).Checked = XmlEditorAddInOptions.ShowAttributesWhenFolded; |
||||
((CheckBox)ControlDictionary[showSchemaAnnotationCheckBoxName]).Checked = XmlEditorAddInOptions.ShowSchemaAnnotation; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Saves any changes.
|
||||
/// </summary>
|
||||
public override bool StorePanelContents() |
||||
{ |
||||
XmlEditorAddInOptions.ShowAttributesWhenFolded = ((CheckBox)ControlDictionary[showAttributesWhenFoldedCheckBoxName]).Checked; |
||||
XmlEditorAddInOptions.ShowSchemaAnnotation = ((CheckBox)ControlDictionary[showSchemaAnnotationCheckBoxName]).Checked; |
||||
|
||||
return true; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
<Components version="1.0"> |
||||
<System.Windows.Forms.UserControl> |
||||
<Name value="XmlEditorOptionsPanel" /> |
||||
<DockPadding value="" /> |
||||
<ClientSize value="{Width=352, Height=336}" /> |
||||
<Controls> |
||||
<System.Windows.Forms.GroupBox> |
||||
<Name value="foldingGroupBox" /> |
||||
<TabIndex value="0" /> |
||||
<Location value="{X=8,Y=8}" /> |
||||
<Anchor value="Top, Left, Right" /> |
||||
<Size value="{Width=336, Height=56}" /> |
||||
<Text value="${res:ICSharpCode.XmlEditor.XmlEditorOptionsPanel.FoldingGroupLabel}" /> |
||||
<Controls> |
||||
<System.Windows.Forms.CheckBox> |
||||
<Name value="showAttributesWhenFoldedCheckBox" /> |
||||
<Location value="{X=16,Y=26}" /> |
||||
<Size value="{Width=304, Height=16}" /> |
||||
<Text value="${res:ICSharpCode.XmlEditor.XmlEditorOptionsPanel.ShowAttributesWhenFoldedLabel}" /> |
||||
<Anchor value="Top, Left, Right" /> |
||||
<TabIndex value="0" /> |
||||
</System.Windows.Forms.CheckBox> |
||||
</Controls> |
||||
</System.Windows.Forms.GroupBox> |
||||
<System.Windows.Forms.GroupBox> |
||||
<Name value="xmlCompletionGroupBox" /> |
||||
<TabIndex value="1" /> |
||||
<Location value="{X=8,Y=72}" /> |
||||
<Anchor value="Top, Left, Right" /> |
||||
<Size value="{Width=336, Height=56}" /> |
||||
<Text value="${res:ICSharpCode.XmlEditor.XmlEditorOptionsPanel.XmlCompletionGroupLabel}" /> |
||||
<Controls> |
||||
<System.Windows.Forms.CheckBox> |
||||
<Name value="showSchemaAnnotationCheckBox" /> |
||||
<Location value="{X=16,Y=27}" /> |
||||
<Size value="{Width=304, Height=16}" /> |
||||
<Text value="${res:ICSharpCode.XmlEditor.XmlEditorOptionsPanel.ShowSchemaAnnotationLabel}" /> |
||||
<Anchor value="Top, Left, Right" /> |
||||
<TabIndex value="0" /> |
||||
</System.Windows.Forms.CheckBox> |
||||
</Controls> |
||||
</System.Windows.Forms.GroupBox> |
||||
</Controls> |
||||
</System.Windows.Forms.UserControl> |
||||
</Components> |
@ -0,0 +1,128 @@
@@ -0,0 +1,128 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Represents the path to an xml element starting from the root of the
|
||||
/// document.
|
||||
/// </summary>
|
||||
public class XmlElementPath |
||||
{ |
||||
QualifiedNameCollection elements = new QualifiedNameCollection(); |
||||
|
||||
public XmlElementPath() |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the elements specifying the path.
|
||||
/// </summary>
|
||||
/// <remarks>The order of the elements determines the path.</remarks>
|
||||
public QualifiedNameCollection Elements { |
||||
get { |
||||
return elements; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Compacts the path so it only contains the elements that are from
|
||||
/// the namespace of the last element in the path.
|
||||
/// </summary>
|
||||
/// <remarks>This method is used when we need to know the path for a
|
||||
/// particular namespace and do not care about the complete path.
|
||||
/// </remarks>
|
||||
public void Compact() |
||||
{ |
||||
if (elements.Count > 0) { |
||||
QualifiedName lastName = Elements[Elements.Count - 1]; |
||||
if (lastName != null) { |
||||
int index = FindNonMatchingParentElement(lastName.Namespace); |
||||
if (index != -1) { |
||||
RemoveParentElements(index); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// An xml element path is considered to be equal if
|
||||
/// each path item has the same name and namespace.
|
||||
/// </summary>
|
||||
public override bool Equals(object obj) { |
||||
|
||||
if (!(obj is XmlElementPath)) return false; |
||||
if (this == obj) return true; |
||||
|
||||
XmlElementPath rhs = (XmlElementPath)obj; |
||||
if (elements.Count == rhs.elements.Count) { |
||||
|
||||
for (int i = 0; i < elements.Count; ++i) { |
||||
if (!elements[i].Equals(rhs.elements[i])) { |
||||
return false; |
||||
} |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
public override int GetHashCode() { |
||||
return elements.GetHashCode(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes elements up to and including the specified index.
|
||||
/// </summary>
|
||||
void RemoveParentElements(int index) |
||||
{ |
||||
while (index >= 0) { |
||||
--index; |
||||
elements.RemoveFirst(); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Finds the first parent that does belong in the specified
|
||||
/// namespace.
|
||||
/// </summary>
|
||||
int FindNonMatchingParentElement(string namespaceUri) |
||||
{ |
||||
int index = -1; |
||||
|
||||
if (elements.Count > 1) { |
||||
// Start the check from the the last but one item.
|
||||
for (int i = elements.Count - 2; i >= 0; --i) { |
||||
QualifiedName name = elements[i]; |
||||
if (name.Namespace != namespaceUri) { |
||||
index = i; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
return index; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,277 @@
@@ -0,0 +1,277 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Document; |
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.IO; |
||||
using System.Text; |
||||
using System.Xml; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Holds information about the start of a fold in an xml string.
|
||||
/// </summary>
|
||||
public class XmlFoldStart |
||||
{ |
||||
int line = 0; |
||||
int col = 0; |
||||
string prefix = String.Empty; |
||||
string name = String.Empty; |
||||
string foldText = String.Empty; |
||||
|
||||
public XmlFoldStart(string prefix, string name, int line, int col) |
||||
{ |
||||
this.line = line; |
||||
this.col = col; |
||||
this.prefix = prefix; |
||||
this.name = name; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The line where the fold should start. Lines start from 0.
|
||||
/// </summary>
|
||||
public int Line { |
||||
get { |
||||
return line; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The column where the fold should start. Columns start from 0.
|
||||
/// </summary>
|
||||
public int Column { |
||||
get { |
||||
return col; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The name of the xml item with its prefix if it has one.
|
||||
/// </summary>
|
||||
public string Name { |
||||
get { |
||||
if (prefix.Length > 0) { |
||||
return String.Concat(prefix, ":", name); |
||||
} else { |
||||
return name; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The text to be displayed when the item is folded.
|
||||
/// </summary>
|
||||
public string FoldText { |
||||
get { |
||||
return foldText; |
||||
} |
||||
|
||||
set { |
||||
foldText = value; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Determines folds for an xml string in the editor.
|
||||
/// </summary>
|
||||
public class XmlFoldingStrategy : IFoldingStrategy |
||||
{ |
||||
/// <summary>
|
||||
/// Flag indicating whether attributes should be displayed on folded
|
||||
/// elements.
|
||||
/// </summary>
|
||||
bool showAttributesWhenFolded = false; |
||||
|
||||
public XmlFoldingStrategy() |
||||
{ |
||||
} |
||||
|
||||
#region IFoldingStrategy
|
||||
|
||||
/// <summary>
|
||||
/// Adds folds to the text editor around each start-end element pair.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>If the xml is not well formed then no folds are created.</para>
|
||||
/// <para>Note that the xml text reader lines and positions start
|
||||
/// from 1 and the SharpDevelop text editor line information starts
|
||||
/// from 0.</para>
|
||||
/// </remarks>
|
||||
public List<FoldMarker> GenerateFoldMarkers(IDocument document, string fileName, object parseInformation) |
||||
{ |
||||
showAttributesWhenFolded = XmlEditorAddInOptions.ShowAttributesWhenFolded; |
||||
|
||||
List<FoldMarker> foldMarkers = new List<FoldMarker>(); |
||||
Stack stack = new Stack(); |
||||
|
||||
try { |
||||
string xml = document.TextContent; |
||||
XmlTextReader reader = new XmlTextReader(new StringReader(xml)); |
||||
while (reader.Read()) { |
||||
switch (reader.NodeType) { |
||||
case XmlNodeType.Element: |
||||
if (!reader.IsEmptyElement) { |
||||
XmlFoldStart newFoldStart = CreateElementFoldStart(reader); |
||||
stack.Push(newFoldStart); |
||||
} |
||||
break; |
||||
|
||||
case XmlNodeType.EndElement: |
||||
XmlFoldStart foldStart = (XmlFoldStart)stack.Pop(); |
||||
CreateElementFold(document, foldMarkers, reader, foldStart); |
||||
break; |
||||
|
||||
case XmlNodeType.Comment: |
||||
CreateCommentFold(document, foldMarkers, reader); |
||||
break; |
||||
} |
||||
} |
||||
} catch (Exception) { |
||||
// If the xml is not well formed keep the foldings
|
||||
// we found.
|
||||
} |
||||
|
||||
return foldMarkers; |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Creates a comment fold if the comment spans more than one line.
|
||||
/// </summary>
|
||||
/// <remarks>The text displayed when the comment is folded is the first
|
||||
/// line of the comment.</remarks>
|
||||
void CreateCommentFold(IDocument document, List<FoldMarker> foldMarkers, XmlTextReader reader) |
||||
{ |
||||
if (reader.Value != null) { |
||||
string comment = reader.Value.Replace("\r\n", "\n"); |
||||
string[] lines = comment.Split('\n'); |
||||
if (lines.Length > 1) { |
||||
|
||||
// Take off 5 chars to get the actual comment start (takes
|
||||
// into account the <!-- chars.
|
||||
|
||||
int startCol = reader.LinePosition - 5; |
||||
int startLine = reader.LineNumber - 1; |
||||
|
||||
// Add 3 to the end col value to take into account the '-->'
|
||||
int endCol = lines[lines.Length - 1].Length + startCol + 3; |
||||
int endLine = startLine + lines.Length - 1; |
||||
string foldText = String.Concat("<!--", lines[0], "-->"); |
||||
FoldMarker foldMarker = new FoldMarker(document, startLine, startCol, endLine, endCol, FoldType.TypeBody, foldText); |
||||
foldMarkers.Add(foldMarker); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates an XmlFoldStart for the start tag of an element.
|
||||
/// </summary>
|
||||
XmlFoldStart CreateElementFoldStart(XmlTextReader reader) |
||||
{ |
||||
// Take off 2 from the line position returned
|
||||
// from the xml since it points to the start
|
||||
// of the element name and not the beginning
|
||||
// tag.
|
||||
XmlFoldStart newFoldStart = new XmlFoldStart(reader.Prefix, reader.LocalName, reader.LineNumber - 1, reader.LinePosition - 2); |
||||
|
||||
if (showAttributesWhenFolded && reader.HasAttributes) { |
||||
newFoldStart.FoldText = String.Concat("<", newFoldStart.Name, " ", GetAttributeFoldText(reader), ">"); |
||||
} else { |
||||
newFoldStart.FoldText = String.Concat("<", newFoldStart.Name, ">"); |
||||
} |
||||
|
||||
return newFoldStart; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Create an element fold if the start and end tag are on
|
||||
/// different lines.
|
||||
/// </summary>
|
||||
void CreateElementFold(IDocument document, List<FoldMarker> foldMarkers, XmlTextReader reader, XmlFoldStart foldStart) |
||||
{ |
||||
int endLine = reader.LineNumber - 1; |
||||
if (endLine > foldStart.Line) { |
||||
int endCol = reader.LinePosition + foldStart.Name.Length; |
||||
FoldMarker foldMarker = new FoldMarker(document, foldStart.Line, foldStart.Column, endLine, endCol, FoldType.TypeBody, foldStart.FoldText); |
||||
foldMarkers.Add(foldMarker); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the element's attributes as a string on one line that will
|
||||
/// be displayed when the element is folded.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Currently this puts all attributes from an element on the same
|
||||
/// line of the start tag. It does not cater for elements where attributes
|
||||
/// are not on the same line as the start tag.
|
||||
/// </remarks>
|
||||
string GetAttributeFoldText(XmlTextReader reader) |
||||
{ |
||||
StringBuilder text = new StringBuilder(); |
||||
|
||||
for (int i = 0; i < reader.AttributeCount; ++i) { |
||||
reader.MoveToAttribute(i); |
||||
|
||||
text.Append(reader.Name); |
||||
text.Append("="); |
||||
text.Append(reader.QuoteChar.ToString()); |
||||
text.Append(XmlEncodeAttributeValue(reader.Value, reader.QuoteChar)); |
||||
text.Append(reader.QuoteChar.ToString()); |
||||
|
||||
// Append a space if this is not the
|
||||
// last attribute.
|
||||
if (i < reader.AttributeCount - 1) { |
||||
text.Append(" "); |
||||
} |
||||
} |
||||
|
||||
return text.ToString(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Xml encode the attribute string since the string returned from
|
||||
/// the XmlTextReader is the plain unencoded string and .NET
|
||||
/// does not provide us with an xml encode method.
|
||||
/// </summary>
|
||||
static string XmlEncodeAttributeValue(string attributeValue, char quoteChar) |
||||
{ |
||||
StringBuilder encodedValue = new StringBuilder(attributeValue); |
||||
|
||||
encodedValue.Replace("&", "&"); |
||||
encodedValue.Replace("<", "<"); |
||||
encodedValue.Replace(">", ">"); |
||||
|
||||
if (quoteChar == '"') { |
||||
encodedValue.Replace("\"", """); |
||||
} else { |
||||
encodedValue.Replace("'", "'"); |
||||
} |
||||
|
||||
return encodedValue.ToString(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,462 @@
@@ -0,0 +1,462 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.IO; |
||||
using System.Text; |
||||
using System.Text.RegularExpressions; |
||||
using System.Xml; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Utility class that contains xml parsing routines used to determine
|
||||
/// the currently selected element so we can provide intellisense.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// All of the routines return <see cref="XmlElementPath"/> objects
|
||||
/// since we are interested in the complete path or tree to the
|
||||
/// currently active element.
|
||||
/// </remarks>
|
||||
public class XmlParser |
||||
{ |
||||
/// <summary>
|
||||
/// Helper class. Holds the namespace URI and the prefix currently
|
||||
/// in use for this namespace.
|
||||
/// </summary>
|
||||
class NamespaceURI |
||||
{ |
||||
string namespaceURI = String.Empty; |
||||
string prefix = String.Empty; |
||||
|
||||
public NamespaceURI() |
||||
{ |
||||
} |
||||
|
||||
public NamespaceURI(string namespaceURI, string prefix) |
||||
{ |
||||
this.namespaceURI = namespaceURI; |
||||
this.prefix = prefix; |
||||
} |
||||
|
||||
public string Namespace { |
||||
get { |
||||
return namespaceURI; |
||||
} |
||||
set { |
||||
namespaceURI = value; |
||||
} |
||||
} |
||||
|
||||
public string Prefix { |
||||
get { |
||||
return prefix; |
||||
} |
||||
set { |
||||
prefix = value; |
||||
if (prefix == null) { |
||||
prefix = String.Empty; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
XmlParser() |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets path of the xml element start tag that the specified
|
||||
/// <paramref name="index"/> is currently inside.
|
||||
/// </summary>
|
||||
/// <remarks>If the index outside the start tag then an empty path
|
||||
/// is returned.</remarks>
|
||||
public static XmlElementPath GetActiveElementStartPath(string xml, int index) |
||||
{ |
||||
XmlElementPath path = new XmlElementPath(); |
||||
|
||||
string elementText = GetActiveElementStartText(xml, index); |
||||
|
||||
if (elementText != null) { |
||||
QualifiedName elementName = GetElementName(elementText); |
||||
NamespaceURI elementNamespace = GetElementNamespace(elementText); |
||||
|
||||
path = GetParentElementPath(xml, index); |
||||
if (elementNamespace.Namespace.Length == 0) { |
||||
if (path.Elements.Count > 0) { |
||||
QualifiedName parentName = path.Elements[path.Elements.Count - 1]; |
||||
elementNamespace.Namespace = parentName.Namespace; |
||||
elementNamespace.Prefix = parentName.Prefix; |
||||
} |
||||
} |
||||
|
||||
path.Elements.Add(new QualifiedName(elementName.Name, elementNamespace.Namespace, elementNamespace.Prefix)); |
||||
} |
||||
|
||||
path.Compact(); |
||||
|
||||
return path; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the parent element path based on the index position.
|
||||
/// </summary>
|
||||
public static XmlElementPath GetParentElementPath(string xml, int index) |
||||
{ |
||||
XmlElementPath path = new XmlElementPath(); |
||||
|
||||
try { |
||||
StringReader reader = new StringReader(xml); |
||||
XmlTextReader xmlReader = new XmlTextReader(reader); |
||||
while (xmlReader.Read()) { |
||||
switch (xmlReader.NodeType) { |
||||
case XmlNodeType.Element: |
||||
if (!xmlReader.IsEmptyElement) { |
||||
QualifiedName elementName = new QualifiedName(xmlReader.LocalName, xmlReader.NamespaceURI, xmlReader.Prefix); |
||||
path.Elements.Add(elementName); |
||||
} |
||||
break; |
||||
case XmlNodeType.EndElement: |
||||
path.Elements.RemoveLast(); |
||||
break; |
||||
} |
||||
} |
||||
} catch (XmlException) { |
||||
// Do nothing.
|
||||
} |
||||
|
||||
path.Compact(); |
||||
|
||||
return path; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Checks whether the attribute at the end of the string is a
|
||||
/// namespace declaration.
|
||||
/// </summary>
|
||||
public static bool IsNamespaceDeclaration(string xml, int index) |
||||
{ |
||||
if (xml.Length == 0) { |
||||
return false; |
||||
} |
||||
|
||||
if (index >= xml.Length) { |
||||
index = xml.Length - 1; |
||||
} |
||||
|
||||
// Move back one character if the last character is an '='
|
||||
if (xml[index] == '=') { |
||||
xml = xml.Substring(0, xml.Length - 1); |
||||
--index; |
||||
} |
||||
|
||||
// From the end of the string work backwards until we have
|
||||
// picked out the last attribute and reached some whitespace.
|
||||
StringBuilder reversedAttributeName = new StringBuilder(); |
||||
|
||||
bool ignoreWhitespace = true; |
||||
int currentIndex = index; |
||||
for (int i = 0; i < index; ++i) { |
||||
|
||||
char currentChar = xml[currentIndex]; |
||||
|
||||
if (Char.IsWhiteSpace(currentChar)) { |
||||
if (ignoreWhitespace == false) { |
||||
// Reached the start of the attribute name.
|
||||
break; |
||||
} |
||||
} else if (Char.IsLetterOrDigit(currentChar) || (currentChar == ':')) { |
||||
ignoreWhitespace = false; |
||||
reversedAttributeName.Append(currentChar); |
||||
} else { |
||||
// Invalid string.
|
||||
break; |
||||
} |
||||
|
||||
--currentIndex; |
||||
} |
||||
|
||||
// Did we get a namespace?
|
||||
|
||||
bool isNamespace = false; |
||||
|
||||
if ((reversedAttributeName.ToString() == "snlmx") || (reversedAttributeName.ToString().EndsWith(":snlmx"))) { |
||||
isNamespace = true; |
||||
} |
||||
|
||||
return isNamespace; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the attribute inside but before the specified
|
||||
/// index.
|
||||
/// </summary>
|
||||
public static string GetAttributeName(string xml, int index) |
||||
{ |
||||
if (xml.Length == 0) { |
||||
return String.Empty; |
||||
} |
||||
|
||||
if (index >= xml.Length) { |
||||
index = xml.Length - 1; |
||||
} |
||||
|
||||
string name = String.Empty; |
||||
|
||||
// From the end of the string work backwards until we have
|
||||
// picked out the attribute name.
|
||||
StringBuilder reversedAttributeName = new StringBuilder(); |
||||
|
||||
bool ignoreWhitespace = true; |
||||
bool ignoreQuote = true; |
||||
bool ignoreEqualsSign = true; |
||||
int currentIndex = index; |
||||
bool invalidString = true; |
||||
|
||||
for (int i = 0; i <= index; ++i) { |
||||
|
||||
char currentChar = xml[currentIndex]; |
||||
|
||||
if (Char.IsLetterOrDigit(currentChar)) { |
||||
if (!ignoreEqualsSign) { |
||||
ignoreWhitespace = false; |
||||
reversedAttributeName.Append(currentChar); |
||||
} |
||||
} else if (Char.IsWhiteSpace(currentChar)) { |
||||
if (ignoreWhitespace == false) { |
||||
// Reached the start of the attribute name.
|
||||
invalidString = false; |
||||
break; |
||||
} |
||||
} else if ((currentChar == '\'') || (currentChar == '\"')) { |
||||
if (ignoreQuote) { |
||||
ignoreQuote = false; |
||||
} else { |
||||
break; |
||||
} |
||||
} else if (currentChar == '='){ |
||||
if (ignoreEqualsSign) { |
||||
ignoreEqualsSign = false; |
||||
} else { |
||||
break; |
||||
} |
||||
} else if (IsAttributeValueChar(currentChar)) { |
||||
if (!ignoreQuote) { |
||||
break; |
||||
} |
||||
} else { |
||||
break; |
||||
} |
||||
|
||||
--currentIndex; |
||||
} |
||||
|
||||
if (!invalidString) { |
||||
name = ReverseString(reversedAttributeName.ToString()); |
||||
} |
||||
|
||||
return name; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Checks for valid xml attribute value character
|
||||
/// </summary>
|
||||
public static bool IsAttributeValueChar(char ch) |
||||
{ |
||||
if (Char.IsLetterOrDigit(ch) || |
||||
(ch == ':') || |
||||
(ch == '/') || |
||||
(ch == '_') || |
||||
(ch == '.') || |
||||
(ch == '-') || |
||||
(ch == '#')) |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Checks for valid xml element or attribute name character.
|
||||
/// </summary>
|
||||
public static bool IsXmlNameChar(char ch) |
||||
{ |
||||
if (Char.IsLetterOrDigit(ch) || |
||||
(ch == ':') || |
||||
(ch == '/') || |
||||
(ch == '_') || |
||||
(ch == '.') || |
||||
(ch == '-')) |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
/// <summary>
|
||||
/// Gets the text of the xml element start tag that the index is
|
||||
/// currently inside.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// Returns the text up to and including the start tag < character.
|
||||
/// </returns>
|
||||
static string GetActiveElementStartText(string xml, int index) |
||||
{ |
||||
int elementStartIndex = GetActiveElementStartIndex(xml, index); |
||||
|
||||
if (elementStartIndex >= 0) { |
||||
if (elementStartIndex < index) { |
||||
int elementEndIndex = GetActiveElementEndIndex(xml, index); |
||||
|
||||
if (elementEndIndex >= index) { |
||||
return xml.Substring(elementStartIndex, elementEndIndex - elementStartIndex); |
||||
} |
||||
} |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Locates the index of the start tag < character.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// Returns the index of the start tag character; otherwise
|
||||
/// -1 if no start tag character is found or a end tag
|
||||
/// > character is found first.
|
||||
/// </returns>
|
||||
static int GetActiveElementStartIndex(string xml, int index) |
||||
{ |
||||
int elementStartIndex = -1; |
||||
|
||||
int currentIndex = index - 1; |
||||
for (int i = 0; i < index; ++i) { |
||||
|
||||
char currentChar = xml[currentIndex]; |
||||
if (currentChar == '<') { |
||||
elementStartIndex = currentIndex; |
||||
break; |
||||
} else if (currentChar == '>') { |
||||
break; |
||||
} |
||||
|
||||
--currentIndex; |
||||
} |
||||
|
||||
return elementStartIndex; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Locates the index of the end tag character.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// Returns the index of the end tag character; otherwise
|
||||
/// -1 if no end tag character is found or a start tag
|
||||
/// character is found first.
|
||||
/// </returns>
|
||||
static int GetActiveElementEndIndex(string xml, int index) |
||||
{ |
||||
int elementEndIndex = index; |
||||
|
||||
for (int i = index; i < xml.Length; ++i) { |
||||
|
||||
char currentChar = xml[i]; |
||||
if (currentChar == '>') { |
||||
elementEndIndex = i; |
||||
break; |
||||
} else if (currentChar == '<'){ |
||||
elementEndIndex = -1; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
return elementEndIndex; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the element name from the element start tag string.
|
||||
/// </summary>
|
||||
/// <param name="xml">This string must start at the
|
||||
/// element we are interested in.</param>
|
||||
static QualifiedName GetElementName(string xml) |
||||
{ |
||||
string name = String.Empty; |
||||
|
||||
// Find the end of the element name.
|
||||
xml = xml.Replace("\r\n", " "); |
||||
int index = xml.IndexOf(' '); |
||||
if (index > 0) { |
||||
name = xml.Substring(1, index - 1); |
||||
} |
||||
|
||||
QualifiedName qualifiedName = new QualifiedName(); |
||||
|
||||
int prefixIndex = name.IndexOf(':'); |
||||
if (prefixIndex > 0) { |
||||
qualifiedName.Prefix = name.Substring(0, prefixIndex); |
||||
qualifiedName.Name = name.Substring(prefixIndex + 1); |
||||
} else { |
||||
qualifiedName.Name = name; |
||||
} |
||||
|
||||
return qualifiedName; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the element namespace from the element start tag
|
||||
/// string.
|
||||
/// </summary>
|
||||
/// <param name="xml">This string must start at the
|
||||
/// element we are interested in.</param>
|
||||
static NamespaceURI GetElementNamespace(string xml) |
||||
{ |
||||
NamespaceURI namespaceURI = new NamespaceURI(); |
||||
|
||||
Match match = Regex.Match(xml, ".*?(xmlns\\s*?|xmlns:.*?)=\\s*?['\\\"](.*?)['\\\"]"); |
||||
if (match.Success) { |
||||
namespaceURI.Namespace = match.Groups[2].Value; |
||||
|
||||
string xmlns = match.Groups[1].Value.Trim(); |
||||
int prefixIndex = xmlns.IndexOf(':'); |
||||
if (prefixIndex > 0) { |
||||
namespaceURI.Prefix = xmlns.Substring(prefixIndex + 1); |
||||
} |
||||
} |
||||
|
||||
return namespaceURI; |
||||
} |
||||
|
||||
static string ReverseString(string text) |
||||
{ |
||||
StringBuilder reversedString = new StringBuilder(text); |
||||
|
||||
int index = text.Length; |
||||
foreach (char ch in text) { |
||||
--index; |
||||
reversedString[index] = ch; |
||||
} |
||||
|
||||
return reversedString.ToString(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,203 @@
@@ -0,0 +1,203 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.Core; |
||||
using System; |
||||
using System.Xml; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Represents an association between an xml schema and a file extension.
|
||||
/// </summary>
|
||||
public class XmlSchemaAssociation //: IXmlConvertable
|
||||
{ |
||||
string namespaceUri = String.Empty; |
||||
string extension = String.Empty; |
||||
string namespacePrefix = String.Empty; |
||||
|
||||
static readonly string schemaAssociationElementName = "SchemaAssociation"; |
||||
static readonly string extensionAttributeName = "extension"; |
||||
static readonly string namespaceAttributeName = "namespace"; |
||||
static readonly string prefixAttributeName = "prefix"; |
||||
|
||||
public XmlSchemaAssociation(string extension) |
||||
: this(extension, String.Empty, String.Empty) |
||||
{ |
||||
} |
||||
|
||||
public XmlSchemaAssociation(string extension, string namespaceUri) |
||||
: this(extension, namespaceUri, String.Empty) |
||||
{ |
||||
} |
||||
|
||||
public XmlSchemaAssociation(string extension, string namespaceUri, string namespacePrefix) |
||||
{ |
||||
this.extension = extension; |
||||
this.namespaceUri = namespaceUri; |
||||
this.namespacePrefix = namespacePrefix; |
||||
} |
||||
|
||||
public string NamespaceUri { |
||||
get { |
||||
return namespaceUri; |
||||
} |
||||
|
||||
set { |
||||
namespaceUri = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the file extension (e.g. '.xml').
|
||||
/// </summary>
|
||||
public string Extension { |
||||
get { |
||||
return extension; |
||||
} |
||||
|
||||
set { |
||||
extension = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default namespace prefix that will be added
|
||||
/// to the xml elements.
|
||||
/// </summary>
|
||||
public string NamespacePrefix { |
||||
get { |
||||
return namespacePrefix; |
||||
} |
||||
|
||||
set { |
||||
namespacePrefix = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the default schema association for the file extension.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// These defaults are hard coded.
|
||||
/// </remarks>
|
||||
public static XmlSchemaAssociation GetDefaultAssociation(string extension) |
||||
{ |
||||
XmlSchemaAssociation association = null; |
||||
|
||||
switch (extension.ToLower()) { |
||||
case ".wxs": |
||||
association = new XmlSchemaAssociation(extension, @"http://schemas.microsoft.com/wix/2003/01/wi"); |
||||
break; |
||||
case ".config": |
||||
association = new XmlSchemaAssociation(extension, @"urn:app-config"); |
||||
break; |
||||
case ".build": |
||||
association = new XmlSchemaAssociation(extension, @"http://nant.sf.net/schemas/nant-0.84.win32.net-1.0.xsd"); |
||||
break; |
||||
case ".addin": |
||||
association = new XmlSchemaAssociation(extension, @"http://www.icsharpcode.net/2004/addin"); |
||||
break; |
||||
case ".xsl": |
||||
case ".xslt": |
||||
association = new XmlSchemaAssociation(extension, @"http://www.w3.org/1999/XSL/Transform", "xsl"); |
||||
break; |
||||
case ".xsd": |
||||
association = new XmlSchemaAssociation(extension, @"http://www.w3.org/2001/XMLSchema", "xs"); |
||||
break; |
||||
case ".manifest": |
||||
association = new XmlSchemaAssociation(extension, @"urn:schemas-microsoft-com:asm.v1"); |
||||
break; |
||||
default: |
||||
association = new XmlSchemaAssociation(extension); |
||||
break; |
||||
} |
||||
return association; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Two schema associations are considered equal if their file extension,
|
||||
/// prefix and namespaceUri are the same.
|
||||
/// </summary>
|
||||
public override bool Equals(object obj) |
||||
{ |
||||
bool equals = false; |
||||
|
||||
XmlSchemaAssociation rhs = obj as XmlSchemaAssociation; |
||||
if (rhs != null) { |
||||
if ((this.namespacePrefix == rhs.namespacePrefix) && |
||||
(this.extension == rhs.extension) && |
||||
(this.namespaceUri == rhs.namespaceUri)) { |
||||
equals = true; |
||||
} |
||||
} |
||||
|
||||
return equals; |
||||
} |
||||
|
||||
public override int GetHashCode() |
||||
{ |
||||
return (namespaceUri != null ? namespaceUri.GetHashCode() : 0) ^ (extension != null ? extension.GetHashCode() : 0) ^ (namespacePrefix != null ? namespacePrefix.GetHashCode() : 0); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates an XmlSchemaAssociation from the saved xml.
|
||||
/// </summary>
|
||||
public object FromXmlElement(XmlElement element) |
||||
{ |
||||
return XmlSchemaAssociation.ConvertFromXmlElement(element); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates an XmlSchemaAssociation from the saved xml.
|
||||
/// </summary>
|
||||
public static object ConvertFromXmlElement(XmlElement element) |
||||
{ |
||||
XmlSchemaAssociation association = null; |
||||
|
||||
if (element.ChildNodes.Count == 1) { |
||||
XmlElement childElement = element.ChildNodes[0] as XmlElement; |
||||
if (childElement != null) { |
||||
if (childElement.Name == schemaAssociationElementName) { |
||||
association = new XmlSchemaAssociation(childElement.GetAttribute(extensionAttributeName), childElement.GetAttribute(namespaceAttributeName), childElement.GetAttribute(prefixAttributeName)); |
||||
} else { |
||||
throw new ApplicationException(childElement.Name); |
||||
} |
||||
} |
||||
} |
||||
return association; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates an xml element from an XmlSchemaAssociation.
|
||||
/// </summary>
|
||||
public XmlElement ToXmlElement(XmlDocument doc) |
||||
{ |
||||
XmlElement element = doc.CreateElement(schemaAssociationElementName); |
||||
|
||||
element.SetAttribute(extensionAttributeName, extension); |
||||
element.SetAttribute(namespaceAttributeName, namespaceUri); |
||||
element.SetAttribute(prefixAttributeName, namespacePrefix); |
||||
|
||||
return element; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,105 @@
@@ -0,0 +1,105 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.Core; |
||||
using System; |
||||
using System.Xml; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Represents list box item showing the association between an xml schema
|
||||
/// and a file extension.
|
||||
/// </summary>
|
||||
public class XmlSchemaAssociationListBoxItem |
||||
{ |
||||
bool isDirty = false; |
||||
string namespaceUri = String.Empty; |
||||
string extension = String.Empty; |
||||
string namespacePrefix = String.Empty; |
||||
|
||||
public XmlSchemaAssociationListBoxItem(string extension, string namespaceUri, string namespacePrefix) |
||||
{ |
||||
this.extension = extension; |
||||
this.namespaceUri = namespaceUri; |
||||
this.namespacePrefix = namespacePrefix; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether this association has been changed by the user.
|
||||
/// </summary>
|
||||
public bool IsDirty { |
||||
get { |
||||
return isDirty; |
||||
} |
||||
|
||||
set { |
||||
isDirty = value; |
||||
} |
||||
} |
||||
|
||||
public string NamespaceUri { |
||||
get { |
||||
return namespaceUri; |
||||
} |
||||
|
||||
set { |
||||
namespaceUri = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the file extension (e.g. '.xml').
|
||||
/// </summary>
|
||||
public string Extension { |
||||
get { |
||||
return extension; |
||||
} |
||||
|
||||
set { |
||||
extension = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default namespace prefix that will be added
|
||||
/// to the xml elements.
|
||||
/// </summary>
|
||||
public string NamespacePrefix { |
||||
get { |
||||
return namespacePrefix; |
||||
} |
||||
|
||||
set { |
||||
namespacePrefix = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the file extension so this can be sorted in a list box.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override string ToString() |
||||
{ |
||||
return extension; |
||||
} |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,290 @@
@@ -0,0 +1,290 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using System; |
||||
using System.Collections; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// A collection that stores <see cref='XmlSchemaCompletionData'/> objects.
|
||||
/// </summary>
|
||||
[Serializable()] |
||||
public class XmlSchemaCompletionDataCollection : CollectionBase { |
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref='XmlSchemaCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
public XmlSchemaCompletionDataCollection() |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref='XmlSchemaCompletionDataCollection'/> based on another <see cref='XmlSchemaCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
/// <param name='val'>
|
||||
/// A <see cref='XmlSchemaCompletionDataCollection'/> from which the contents are copied
|
||||
/// </param>
|
||||
public XmlSchemaCompletionDataCollection(XmlSchemaCompletionDataCollection val) |
||||
{ |
||||
this.AddRange(val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref='XmlSchemaCompletionDataCollection'/> containing any array of <see cref='XmlSchemaCompletionData'/> objects.
|
||||
/// </summary>
|
||||
/// <param name='val'>
|
||||
/// A array of <see cref='XmlSchemaCompletionData'/> objects with which to intialize the collection
|
||||
/// </param>
|
||||
public XmlSchemaCompletionDataCollection(XmlSchemaCompletionData[] val) |
||||
{ |
||||
this.AddRange(val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Represents the entry at the specified index of the <see cref='XmlSchemaCompletionData'/>.
|
||||
/// </summary>
|
||||
/// <param name='index'>The zero-based index of the entry to locate in the collection.</param>
|
||||
/// <value>The entry at the specified index of the collection.</value>
|
||||
/// <exception cref='ArgumentOutOfRangeException'><paramref name='index'/> is outside the valid range of indexes for the collection.</exception>
|
||||
public XmlSchemaCompletionData this[int index] { |
||||
get { |
||||
return ((XmlSchemaCompletionData)(List[index])); |
||||
} |
||||
set { |
||||
List[index] = value; |
||||
} |
||||
} |
||||
|
||||
public ICompletionData[] GetNamespaceCompletionData() |
||||
{ |
||||
ArrayList completionItems = new ArrayList(); |
||||
|
||||
foreach (XmlSchemaCompletionData schema in this) { |
||||
XmlCompletionData completionData = new XmlCompletionData(schema.NamespaceUri, XmlCompletionData.DataType.NamespaceUri); |
||||
completionItems.Add(completionData); |
||||
} |
||||
|
||||
return (ICompletionData[])completionItems.ToArray(typeof(ICompletionData)); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Represents the <see cref='XmlSchemaCompletionData'/> entry with the specified namespace URI.
|
||||
/// </summary>
|
||||
/// <param name='namespaceUri'>The schema's namespace URI.</param>
|
||||
/// <value>The entry with the specified namespace URI.</value>
|
||||
public XmlSchemaCompletionData this[string namespaceUri] { |
||||
get { |
||||
return GetItem(namespaceUri); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds a <see cref='XmlSchemaCompletionData'/> with the specified value to the
|
||||
/// <see cref='XmlSchemaCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
/// <param name='val'>The <see cref='XmlSchemaCompletionData'/> to add.</param>
|
||||
/// <returns>The index at which the new element was inserted.</returns>
|
||||
/// <seealso cref='XmlSchemaCompletionDataCollection.AddRange'/>
|
||||
public int Add(XmlSchemaCompletionData val) |
||||
{ |
||||
return List.Add(val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Copies the elements of an array to the end of the <see cref='XmlSchemaCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
/// <param name='val'>
|
||||
/// An array of type <see cref='XmlSchemaCompletionData'/> containing the objects to add to the collection.
|
||||
/// </param>
|
||||
/// <seealso cref='XmlSchemaCompletionDataCollection.Add'/>
|
||||
public void AddRange(XmlSchemaCompletionData[] val) |
||||
{ |
||||
for (int i = 0; i < val.Length; i++) { |
||||
this.Add(val[i]); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds the contents of another <see cref='XmlSchemaCompletionDataCollection'/> to the end of the collection.
|
||||
/// </summary>
|
||||
/// <param name='val'>
|
||||
/// A <see cref='XmlSchemaCompletionDataCollection'/> containing the objects to add to the collection.
|
||||
/// </param>
|
||||
/// <seealso cref='XmlSchemaCompletionDataCollection.Add'/>
|
||||
public void AddRange(XmlSchemaCompletionDataCollection val) |
||||
{ |
||||
for (int i = 0; i < val.Count; i++) |
||||
{ |
||||
this.Add(val[i]); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the
|
||||
/// <see cref='XmlSchemaCompletionDataCollection'/> contains the specified <see cref='XmlSchemaCompletionData'/>.
|
||||
/// </summary>
|
||||
/// <param name='val'>The <see cref='XmlSchemaCompletionData'/> to locate.</param>
|
||||
/// <returns>
|
||||
/// <see langword='true'/> if the <see cref='XmlSchemaCompletionData'/> is contained in the collection;
|
||||
/// otherwise, <see langword='false'/>.
|
||||
/// </returns>
|
||||
/// <seealso cref='XmlSchemaCompletionDataCollection.IndexOf'/>
|
||||
public bool Contains(XmlSchemaCompletionData val) |
||||
{ |
||||
return List.Contains(val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Copies the <see cref='XmlSchemaCompletionDataCollection'/> values to a one-dimensional <see cref='Array'/> instance at the
|
||||
/// specified index.
|
||||
/// </summary>
|
||||
/// <param name='array'>The one-dimensional <see cref='Array'/> that is the destination of the values copied from <see cref='XmlSchemaCompletionDataCollection'/>.</param>
|
||||
/// <param name='index'>The index in <paramref name='array'/> where copying begins.</param>
|
||||
/// <exception cref='ArgumentException'>
|
||||
/// <para><paramref name='array'/> is multidimensional.</para>
|
||||
/// <para>-or-</para>
|
||||
/// <para>The number of elements in the <see cref='XmlSchemaCompletionDataCollection'/> is greater than
|
||||
/// the available space between <paramref name='arrayIndex'/> and the end of
|
||||
/// <paramref name='array'/>.</para>
|
||||
/// </exception>
|
||||
/// <exception cref='ArgumentNullException'><paramref name='array'/> is <see langword='null'/>. </exception>
|
||||
/// <exception cref='ArgumentOutOfRangeException'><paramref name='arrayIndex'/> is less than <paramref name='array'/>'s lowbound. </exception>
|
||||
/// <seealso cref='Array'/>
|
||||
public void CopyTo(XmlSchemaCompletionData[] array, int index) |
||||
{ |
||||
List.CopyTo(array, index); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the index of a <see cref='XmlSchemaCompletionData'/> in
|
||||
/// the <see cref='XmlSchemaCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
/// <param name='val'>The <see cref='XmlSchemaCompletionData'/> to locate.</param>
|
||||
/// <returns>
|
||||
/// The index of the <see cref='XmlSchemaCompletionData'/> of <paramref name='val'/> in the
|
||||
/// <see cref='XmlSchemaCompletionDataCollection'/>, if found; otherwise, -1.
|
||||
/// </returns>
|
||||
/// <seealso cref='XmlSchemaCompletionDataCollection.Contains'/>
|
||||
public int IndexOf(XmlSchemaCompletionData val) |
||||
{ |
||||
return List.IndexOf(val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Inserts a <see cref='XmlSchemaCompletionData'/> into the <see cref='XmlSchemaCompletionDataCollection'/> at the specified index.
|
||||
/// </summary>
|
||||
/// <param name='index'>The zero-based index where <paramref name='val'/> should be inserted.</param>
|
||||
/// <param name='val'>The <see cref='XmlSchemaCompletionData'/> to insert.</param>
|
||||
/// <seealso cref='XmlSchemaCompletionDataCollection.Add'/>
|
||||
public void Insert(int index, XmlSchemaCompletionData val) |
||||
{ |
||||
List.Insert(index, val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator that can iterate through the <see cref='XmlSchemaCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
/// <seealso cref='IEnumerator'/>
|
||||
public new XmlSchemaCompletionDataEnumerator GetEnumerator() |
||||
{ |
||||
return new XmlSchemaCompletionDataEnumerator(this); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes a specific <see cref='XmlSchemaCompletionData'/> from the <see cref='XmlSchemaCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
/// <param name='val'>The <see cref='XmlSchemaCompletionData'/> to remove from the <see cref='XmlSchemaCompletionDataCollection'/>.</param>
|
||||
/// <exception cref='ArgumentException'><paramref name='val'/> is not found in the Collection.</exception>
|
||||
public void Remove(XmlSchemaCompletionData val) |
||||
{ |
||||
List.Remove(val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Enumerator that can iterate through a XmlSchemaCompletionDataCollection.
|
||||
/// </summary>
|
||||
/// <seealso cref='IEnumerator'/>
|
||||
/// <seealso cref='XmlSchemaCompletionDataCollection'/>
|
||||
/// <seealso cref='XmlSchemaCompletionData'/>
|
||||
public class XmlSchemaCompletionDataEnumerator : IEnumerator |
||||
{ |
||||
IEnumerator baseEnumerator; |
||||
IEnumerable temp; |
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref='XmlSchemaCompletionDataEnumerator'/>.
|
||||
/// </summary>
|
||||
public XmlSchemaCompletionDataEnumerator(XmlSchemaCompletionDataCollection mappings) |
||||
{ |
||||
this.temp = ((IEnumerable)(mappings)); |
||||
this.baseEnumerator = temp.GetEnumerator(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the current <see cref='XmlSchemaCompletionData'/> in the <seealso cref='XmlSchemaCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
public XmlSchemaCompletionData Current { |
||||
get { |
||||
return ((XmlSchemaCompletionData)(baseEnumerator.Current)); |
||||
} |
||||
} |
||||
|
||||
object IEnumerator.Current { |
||||
get { |
||||
return baseEnumerator.Current; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Advances the enumerator to the next <see cref='XmlSchemaCompletionData'/> of the <see cref='XmlSchemaCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
public bool MoveNext() |
||||
{ |
||||
return baseEnumerator.MoveNext(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Sets the enumerator to its initial position, which is before the first element in the <see cref='XmlSchemaCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
public void Reset() |
||||
{ |
||||
baseEnumerator.Reset(); |
||||
} |
||||
} |
||||
|
||||
XmlSchemaCompletionData GetItem(string namespaceUri) |
||||
{ |
||||
XmlSchemaCompletionData matchedItem = null; |
||||
|
||||
foreach(XmlSchemaCompletionData item in this) |
||||
{ |
||||
if (item.NamespaceUri == namespaceUri) { |
||||
matchedItem = item; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
return matchedItem; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,74 @@
@@ -0,0 +1,74 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// A schema item shown in the tools options dialog.
|
||||
/// </summary>
|
||||
public class XmlSchemaListBoxItem |
||||
{ |
||||
string namespaceUri = String.Empty; |
||||
bool readOnly = false; |
||||
|
||||
/// <summary>
|
||||
/// Creates a new list box item.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A readonly list box item is used for system schemas, those that
|
||||
/// are installed with SharpDevelop.
|
||||
/// </remarks>
|
||||
public XmlSchemaListBoxItem(string namespaceUri, bool readOnly) |
||||
{ |
||||
this.namespaceUri = namespaceUri; |
||||
this.readOnly = readOnly; |
||||
} |
||||
|
||||
public XmlSchemaListBoxItem(string namespaceUri) |
||||
: this(namespaceUri, false) |
||||
{ |
||||
} |
||||
|
||||
public string NamespaceUri { |
||||
get { |
||||
return namespaceUri; |
||||
} |
||||
} |
||||
|
||||
public bool ReadOnly { |
||||
get { |
||||
return readOnly; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the namespace Uri so the list box item is sorted correctly.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override string ToString() |
||||
{ |
||||
return namespaceUri; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,220 @@
@@ -0,0 +1,220 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.Core; |
||||
using System; |
||||
using System.IO; |
||||
using System.Xml; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Keeps track of all the schemas that the Xml Editor is aware
|
||||
/// of.
|
||||
/// </summary>
|
||||
public class XmlSchemaManager |
||||
{ |
||||
static XmlSchemaCompletionDataCollection schemas = null; |
||||
static XmlSchemaManager manager = null; |
||||
|
||||
public static event EventHandler UserSchemaAdded; |
||||
|
||||
public static event EventHandler UserSchemaRemoved; |
||||
|
||||
XmlSchemaManager() |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the schemas that SharpDevelop knows about.
|
||||
/// </summary>
|
||||
public static XmlSchemaCompletionDataCollection SchemaCompletionDataItems { |
||||
get { |
||||
if (schemas == null) { |
||||
schemas = new XmlSchemaCompletionDataCollection(); |
||||
manager = new XmlSchemaManager(); |
||||
manager.ReadSchemas(); |
||||
} |
||||
|
||||
return schemas; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the schema completion data that is associated with the
|
||||
/// specified file extension.
|
||||
/// </summary>
|
||||
public static XmlSchemaCompletionData GetSchemaCompletionData(string extension) |
||||
{ |
||||
XmlSchemaCompletionData data = null; |
||||
|
||||
XmlSchemaAssociation association = XmlEditorAddInOptions.GetSchemaAssociation(extension); |
||||
if (association != null) { |
||||
if (association.NamespaceUri.Length > 0) { |
||||
data = SchemaCompletionDataItems[association.NamespaceUri]; |
||||
} |
||||
} |
||||
return data; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the namespace prefix that is associated with the
|
||||
/// specified file extension.
|
||||
/// </summary>
|
||||
public static string GetNamespacePrefix(string extension) |
||||
{ |
||||
string prefix = String.Empty; |
||||
|
||||
XmlSchemaAssociation association = XmlEditorAddInOptions.GetSchemaAssociation(extension); |
||||
if (association != null) { |
||||
prefix = association.NamespacePrefix; |
||||
} |
||||
|
||||
return prefix; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes the schema with the specified namespace from the
|
||||
/// user schemas folder and removes the completion data.
|
||||
/// </summary>
|
||||
public static void RemoveUserSchema(string namespaceUri) |
||||
{ |
||||
XmlSchemaCompletionData schemaData = SchemaCompletionDataItems[namespaceUri]; |
||||
if (schemaData != null) { |
||||
if (File.Exists(schemaData.FileName)) { |
||||
File.Delete(schemaData.FileName); |
||||
} |
||||
SchemaCompletionDataItems.Remove(schemaData); |
||||
OnUserSchemaRemoved(); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds the schema to the user schemas folder and makes the
|
||||
/// schema available to the xml editor.
|
||||
/// </summary>
|
||||
public static void AddUserSchema(XmlSchemaCompletionData schemaData) |
||||
{ |
||||
if (SchemaCompletionDataItems[schemaData.NamespaceUri] == null) { |
||||
|
||||
if (!Directory.Exists(UserSchemaFolder)) { |
||||
Directory.CreateDirectory(UserSchemaFolder); |
||||
} |
||||
|
||||
string fileName = Path.GetFileName(schemaData.FileName); |
||||
string destinationFileName = Path.Combine(UserSchemaFolder, fileName); |
||||
File.Copy(schemaData.FileName, destinationFileName); |
||||
schemaData.FileName = destinationFileName; |
||||
SchemaCompletionDataItems.Add(schemaData); |
||||
OnUserSchemaAdded(); |
||||
} else { |
||||
Console.WriteLine(String.Concat("Trying to add a schema that already exists. Namespace=", schemaData.NamespaceUri)); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Reads the system and user added schemas.
|
||||
/// </summary>
|
||||
void ReadSchemas() |
||||
{ |
||||
ReadSchemas(SchemaFolder, true); |
||||
ReadSchemas(UserSchemaFolder, false); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Reads all .xsd files in the specified folder.
|
||||
/// </summary>
|
||||
void ReadSchemas(string folder, bool readOnly) |
||||
{ |
||||
if (Directory.Exists(folder)) { |
||||
foreach (string fileName in Directory.GetFiles(folder, "*.xsd")) { |
||||
ReadSchema(fileName, readOnly); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Reads an individual schema and adds it to the collection.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If the schema namespace exists in the collection it is not added.
|
||||
/// </remarks>
|
||||
void ReadSchema(string fileName, bool readOnly) |
||||
{ |
||||
try { |
||||
XmlSchemaCompletionData data = new XmlSchemaCompletionData(fileName); |
||||
if (data.NamespaceUri != null) { |
||||
if (schemas[data.NamespaceUri] == null) { |
||||
data.ReadOnly = readOnly; |
||||
schemas.Add(data); |
||||
} else { |
||||
// Namespace already exists.
|
||||
Console.WriteLine(String.Concat("Ignoring duplicate schema namespace ", data.NamespaceUri)); |
||||
} |
||||
} else { |
||||
// Namespace is null.
|
||||
Console.WriteLine(String.Concat("Ignoring schema with no namespace ", data.FileName)); |
||||
} |
||||
} catch (Exception ex) { |
||||
Console.WriteLine(String.Concat("Unable to read schema '", fileName, "'. ", ex.Message)); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the folder where the schemas for all users on the
|
||||
/// local machine are stored.
|
||||
/// </summary>
|
||||
static string SchemaFolder { |
||||
get { |
||||
return Path.Combine(PropertyService.DataDirectory, "schemas"); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the folder where schemas are stored for an individual user.
|
||||
/// </summary>
|
||||
static string UserSchemaFolder { |
||||
get { |
||||
return Path.Combine(PropertyService.ConfigDirectory, "schemas"); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Should really pass schema info with the event.
|
||||
/// </summary>
|
||||
static void OnUserSchemaAdded() |
||||
{ |
||||
if (UserSchemaAdded != null) { |
||||
UserSchemaAdded(manager, new EventArgs()); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Should really pass schema info with the event.
|
||||
/// </summary>
|
||||
static void OnUserSchemaRemoved() |
||||
{ |
||||
if (UserSchemaRemoved != null) { |
||||
UserSchemaRemoved(manager, new EventArgs()); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,426 @@
@@ -0,0 +1,426 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Specialized; |
||||
using System.ComponentModel; |
||||
using System.Drawing; |
||||
using System.IO; |
||||
using System.Windows.Forms; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Shows the xml schemas that SharpDevelop knows about.
|
||||
/// </summary>
|
||||
public class XmlSchemasPanel : AbstractOptionPanel |
||||
{ |
||||
ListBox schemaListBox; |
||||
Button removeButton; |
||||
ComboBox fileExtensionComboBox; |
||||
TextBox schemaTextBox; |
||||
TextBox namespacePrefixTextBox; |
||||
|
||||
bool ignoreNamespacePrefixTextChanges; |
||||
|
||||
bool changed; |
||||
XmlSchemaCompletionDataCollection addedSchemas = new XmlSchemaCompletionDataCollection(); |
||||
StringCollection removedSchemaNamespaces = new StringCollection(); |
||||
|
||||
SolidBrush readonlyTextBrush = new SolidBrush(SystemColors.GrayText); |
||||
SolidBrush selectedTextBrush = new SolidBrush(SystemColors.HighlightText); |
||||
SolidBrush normalTextBrush = new SolidBrush(SystemColors.WindowText); |
||||
|
||||
/// <summary>
|
||||
/// Initialises the panel.
|
||||
/// </summary>
|
||||
public override void LoadPanelContents() |
||||
{ |
||||
SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("ICSharpCode.XmlEditor.XmlSchemasPanel.xfrm")); |
||||
|
||||
schemaListBox = (ListBox)ControlDictionary["schemaListBox"]; |
||||
schemaListBox.DrawMode = DrawMode.OwnerDrawFixed; |
||||
schemaListBox.DrawItem += new DrawItemEventHandler(SchemaListBoxDrawItem); |
||||
schemaListBox.Sorted = true; |
||||
PopulateSchemaListBox(); |
||||
schemaListBox.SelectedIndexChanged += new EventHandler(SchemaListBoxSelectedIndexChanged); |
||||
|
||||
namespacePrefixTextBox = (TextBox)ControlDictionary["namespacePrefixTextBox"]; |
||||
namespacePrefixTextBox.TextChanged += new EventHandler(NamespacePrefixTextBoxTextChanged); |
||||
|
||||
ControlDictionary["addButton"].Click += new EventHandler(AddButtonClick); |
||||
removeButton = (Button)ControlDictionary["removeButton"]; |
||||
removeButton.Click += new EventHandler(RemoveButtonClick); |
||||
removeButton.Enabled = false; |
||||
|
||||
ControlDictionary["changeSchemaButton"].Click += new EventHandler(ChangeSchemaButtonClick); |
||||
|
||||
schemaTextBox = (TextBox)ControlDictionary["schemaTextBox"]; |
||||
fileExtensionComboBox = (ComboBox)ControlDictionary["fileExtensionComboBox"]; |
||||
fileExtensionComboBox.Sorted = true; |
||||
PopulateFileExtensionComboBox(); |
||||
fileExtensionComboBox.SelectedIndexChanged += new EventHandler(FileExtensionComboBoxSelectedIndexChanged); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Saves any changes to the configured schemas.
|
||||
/// </summary>
|
||||
public override bool StorePanelContents() |
||||
{ |
||||
if (changed) { |
||||
try { |
||||
return SaveSchemaChanges(); |
||||
} catch (Exception ex) { |
||||
MessageService.ShowError(ex, "${res:ICSharpCode.XmlEditor.XmlSchemasPanel.UnableToSaveChanges}"); |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
// Update schema associations after we have added any new schemas to
|
||||
// the schema manager.
|
||||
UpdateSchemaAssociations(); |
||||
|
||||
return true; |
||||
} |
||||
|
||||
void AddButtonClick(object source, EventArgs e) |
||||
{ |
||||
try { |
||||
// Browse for schema.
|
||||
|
||||
string schemaFileName = BrowseForSchema(); |
||||
|
||||
// Add schema if the namespace does not already exist.
|
||||
|
||||
if (schemaFileName.Length > 0) { |
||||
changed = AddSchema(schemaFileName); |
||||
} |
||||
} catch (Exception ex) { |
||||
MessageService.ShowError(ex, "${res:ICSharpCode.XmlEditor.XmlSchemasPanel.UnableToAddSchema}"); |
||||
} |
||||
} |
||||
|
||||
void RemoveButtonClick(object source, EventArgs e) |
||||
{ |
||||
// Remove selected schema.
|
||||
XmlSchemaListBoxItem item = schemaListBox.SelectedItem as XmlSchemaListBoxItem; |
||||
if (item != null) { |
||||
RemoveSchema(item.NamespaceUri); |
||||
changed = true; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Enables the remove button if a list box item is selected.
|
||||
/// </summary>
|
||||
void SchemaListBoxSelectedIndexChanged(object source, EventArgs e) |
||||
{ |
||||
XmlSchemaListBoxItem item = schemaListBox.SelectedItem as XmlSchemaListBoxItem; |
||||
if (item != null) { |
||||
if (item.ReadOnly) { |
||||
removeButton.Enabled = false; |
||||
} else { |
||||
removeButton.Enabled = true; |
||||
} |
||||
} else { |
||||
removeButton.Enabled = false; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds the schema namespaces to the list.
|
||||
/// </summary>
|
||||
void PopulateSchemaListBox() |
||||
{ |
||||
foreach (XmlSchemaCompletionData schema in XmlSchemaManager.SchemaCompletionDataItems) { |
||||
XmlSchemaListBoxItem item = new XmlSchemaListBoxItem(schema.NamespaceUri, schema.ReadOnly); |
||||
schemaListBox.Items.Add(item); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Saves any changes to the configured schemas.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
bool SaveSchemaChanges() |
||||
{ |
||||
RemoveUserSchemas(); |
||||
AddUserSchemas(); |
||||
|
||||
return true; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Allows the user to browse the file system for a schema.
|
||||
/// </summary>
|
||||
/// <returns>The schema file name the user selected; otherwise an
|
||||
/// empty string.</returns>
|
||||
string BrowseForSchema() |
||||
{ |
||||
string fileName = String.Empty; |
||||
|
||||
using (OpenFileDialog openFileDialog = new OpenFileDialog()) { |
||||
openFileDialog.CheckFileExists = true; |
||||
openFileDialog.Multiselect = false; |
||||
openFileDialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.XmlSchemaFiles}|*.xsd|${res:SharpDevelop.FileFilter.AllFiles}|*.*"); |
||||
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK) { |
||||
fileName = openFileDialog.FileName; |
||||
} |
||||
} |
||||
|
||||
return fileName; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Loads the specified schema and adds it to an internal collection.
|
||||
/// </summary>
|
||||
/// <remarks>The schema file is not copied to the user's schema folder
|
||||
/// until they click the OK button.</remarks>
|
||||
/// <returns><see langword="true"/> if the schema namespace
|
||||
/// does not already exist; otherwise <see langword="false"/>
|
||||
/// </returns>
|
||||
bool AddSchema(string fileName) |
||||
{ |
||||
// Load the schema.
|
||||
XmlSchemaCompletionData schema = new XmlSchemaCompletionData(fileName); |
||||
|
||||
// Make sure the schema has a target namespace.
|
||||
if (schema.NamespaceUri == null) { |
||||
MessageService.ShowErrorFormatted("${res:ICSharpCode.XmlEditor.XmlSchemasPanel.NoTargetNamespace}", Path.GetFileName(schema.FileName)); |
||||
return false; |
||||
} |
||||
|
||||
// Check that the schema does not exist.
|
||||
if (SchemaNamespaceExists(schema.NamespaceUri)) { |
||||
MessageService.ShowErrorFormatted("${res:ICSharpCode.XmlEditor.XmlSchemasPanel.NamespaceExists}", schema.NamespaceUri); |
||||
return false; |
||||
} |
||||
|
||||
// Store the schema so we can add it later.
|
||||
int index = schemaListBox.Items.Add(new XmlSchemaListBoxItem(schema.NamespaceUri)); |
||||
schemaListBox.SelectedIndex = index; |
||||
addedSchemas.Add(schema); |
||||
if (removedSchemaNamespaces.Contains(schema.NamespaceUri)) { |
||||
removedSchemaNamespaces.Remove(schema.NamespaceUri); |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Checks that the schema namespace does not already exist.
|
||||
/// </summary>
|
||||
bool SchemaNamespaceExists(string namespaceURI) |
||||
{ |
||||
bool exists = true; |
||||
if ((XmlSchemaManager.SchemaCompletionDataItems[namespaceURI] == null) && |
||||
(addedSchemas[namespaceURI] == null)){ |
||||
exists = false; |
||||
} else { |
||||
// Makes sure it has not been flagged for removal.
|
||||
exists = !removedSchemaNamespaces.Contains(namespaceURI); |
||||
} |
||||
return exists; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Schedules the schema for removal.
|
||||
/// </summary>
|
||||
void RemoveSchema(string namespaceUri) |
||||
{ |
||||
RemoveListBoxItem(namespaceUri); |
||||
|
||||
XmlSchemaCompletionData addedSchema = addedSchemas[namespaceUri]; |
||||
if (addedSchema != null) { |
||||
addedSchemas.Remove(addedSchema); |
||||
} else { |
||||
removedSchemaNamespaces.Add(namespaceUri); |
||||
} |
||||
} |
||||
|
||||
void RemoveListBoxItem(string namespaceUri) |
||||
{ |
||||
foreach (XmlSchemaListBoxItem item in schemaListBox.Items) { |
||||
if (item.NamespaceUri == namespaceUri) { |
||||
schemaListBox.Items.Remove(item); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes the schemas from the schema manager.
|
||||
/// </summary>
|
||||
void RemoveUserSchemas() |
||||
{ |
||||
while (removedSchemaNamespaces.Count > 0) { |
||||
XmlSchemaManager.RemoveUserSchema(removedSchemaNamespaces[0]); |
||||
removedSchemaNamespaces.RemoveAt(0); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds the schemas to the schema manager.
|
||||
/// </summary>
|
||||
void AddUserSchemas() |
||||
{ |
||||
while (addedSchemas.Count > 0) { |
||||
XmlSchemaManager.AddUserSchema(addedSchemas[0]); |
||||
addedSchemas.RemoveAt(0); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Draws the list box items so we can show the read only schemas in
|
||||
/// a different colour.
|
||||
/// </summary>
|
||||
void SchemaListBoxDrawItem(object sender, DrawItemEventArgs e) |
||||
{ |
||||
e.DrawBackground(); |
||||
|
||||
if (e.Index >= 0) { |
||||
XmlSchemaListBoxItem item = (XmlSchemaListBoxItem)schemaListBox.Items[e.Index]; |
||||
|
||||
if (IsListBoxItemSelected(e.State)) { |
||||
e.Graphics.DrawString(item.NamespaceUri, schemaListBox.Font, selectedTextBrush, e.Bounds); |
||||
} else if (item.ReadOnly) { |
||||
e.Graphics.DrawString(item.NamespaceUri, schemaListBox.Font, readonlyTextBrush, e.Bounds); |
||||
} else { |
||||
e.Graphics.DrawString(item.NamespaceUri, schemaListBox.Font, normalTextBrush, e.Bounds); |
||||
} |
||||
} |
||||
|
||||
e.DrawFocusRectangle(); |
||||
} |
||||
|
||||
bool IsListBoxItemSelected(DrawItemState state) |
||||
{ |
||||
return ((state & DrawItemState.Selected) == DrawItemState.Selected); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Shows the namespace associated with the selected xml file extension.
|
||||
/// </summary>
|
||||
void FileExtensionComboBoxSelectedIndexChanged(object source, EventArgs e) |
||||
{ |
||||
schemaTextBox.Text = String.Empty; |
||||
ignoreNamespacePrefixTextChanges = true; |
||||
namespacePrefixTextBox.Text = String.Empty; |
||||
|
||||
try { |
||||
XmlSchemaAssociationListBoxItem association = fileExtensionComboBox.SelectedItem as XmlSchemaAssociationListBoxItem; |
||||
if (association != null) { |
||||
schemaTextBox.Text = association.NamespaceUri; |
||||
namespacePrefixTextBox.Text = association.NamespacePrefix; |
||||
} |
||||
} finally { |
||||
ignoreNamespacePrefixTextChanges = false; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Allows the user to change the schema associated with an xml file
|
||||
/// extension.
|
||||
/// </summary>
|
||||
void ChangeSchemaButtonClick(object source, EventArgs e) |
||||
{ |
||||
string[] namespaces = GetSchemaListBoxNamespaces(); |
||||
using (SelectXmlSchemaForm form = new SelectXmlSchemaForm(namespaces)) { |
||||
form.SelectedNamespaceUri = schemaTextBox.Text; |
||||
if (form.ShowDialog(this) == DialogResult.OK) { |
||||
schemaTextBox.Text = form.SelectedNamespaceUri; |
||||
XmlSchemaAssociationListBoxItem item = (XmlSchemaAssociationListBoxItem)fileExtensionComboBox.SelectedItem; |
||||
item.NamespaceUri = form.SelectedNamespaceUri; |
||||
item.IsDirty = true; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Reads the configured xml file extensions and their associated namespaces.
|
||||
/// </summary>
|
||||
void PopulateFileExtensionComboBox() |
||||
{ |
||||
string [] extensions = XmlView.GetXmlFileExtensions(); |
||||
|
||||
foreach (string extension in extensions) { |
||||
XmlSchemaAssociation association = XmlEditorAddInOptions.GetSchemaAssociation(extension); |
||||
XmlSchemaAssociationListBoxItem item = new XmlSchemaAssociationListBoxItem(association.Extension, association.NamespaceUri, association.NamespacePrefix); |
||||
fileExtensionComboBox.Items.Add(item); |
||||
} |
||||
|
||||
if (fileExtensionComboBox.Items.Count > 0) { |
||||
fileExtensionComboBox.SelectedIndex = 0; |
||||
FileExtensionComboBoxSelectedIndexChanged(this, new EventArgs()); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Updates the configured file extension to namespace mappings.
|
||||
/// </summary>
|
||||
void UpdateSchemaAssociations() |
||||
{ |
||||
foreach (XmlSchemaAssociationListBoxItem item in fileExtensionComboBox.Items) { |
||||
if (item.IsDirty) { |
||||
XmlSchemaAssociation association = new XmlSchemaAssociation(item.Extension, item.NamespaceUri, item.NamespacePrefix); |
||||
XmlEditorAddInOptions.SetSchemaAssociation(association); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns an array of schema namespace strings that will be displayed
|
||||
/// when the user chooses to associated a namespace to a file extension
|
||||
/// by default.
|
||||
/// </summary>
|
||||
string[] GetSchemaListBoxNamespaces() |
||||
{ |
||||
string[] namespaces = new string[schemaListBox.Items.Count]; |
||||
|
||||
for (int i = 0; i < schemaListBox.Items.Count; ++i) { |
||||
XmlSchemaListBoxItem item = (XmlSchemaListBoxItem)schemaListBox.Items[i]; |
||||
namespaces[i] = item.NamespaceUri; |
||||
} |
||||
|
||||
return namespaces; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// User has changed the namespace prefix.
|
||||
/// </summary>
|
||||
void NamespacePrefixTextBoxTextChanged(object source, EventArgs e) |
||||
{ |
||||
if (!ignoreNamespacePrefixTextChanges) { |
||||
XmlSchemaAssociationListBoxItem item = fileExtensionComboBox.SelectedItem as XmlSchemaAssociationListBoxItem; |
||||
if (item != null) { |
||||
item.NamespacePrefix = namespacePrefixTextBox.Text; |
||||
item.IsDirty = true; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,110 @@
@@ -0,0 +1,110 @@
|
||||
<Components version="1.0"> |
||||
<System.Windows.Forms.UserControl> |
||||
<Name value="XmlEditorOptionsPanel" /> |
||||
<DockPadding value="" /> |
||||
<ClientSize value="{Width=352, Height=328}" /> |
||||
<SnapToGrid value="False" /> |
||||
<Controls> |
||||
<System.Windows.Forms.GroupBox> |
||||
<Name value="xmlFileExtensionGroupBox" /> |
||||
<TabIndex value="4" /> |
||||
<Location value="{X=8,Y=186}" /> |
||||
<Anchor value="Top, Left, Right" /> |
||||
<Size value="{Width=336, Height=126}" /> |
||||
<Text value="${res:ICSharpCode.XmlEditor.XmlSchemaPanel.FileExtensionsGroupBoxText}" /> |
||||
<Controls> |
||||
<System.Windows.Forms.TextBox> |
||||
<Name value="namespacePrefixTextBox" /> |
||||
<Anchor value="Top, Left, Right" /> |
||||
<TabIndex value="10" /> |
||||
<Location value="{X=80,Y=84}" /> |
||||
<Size value="{Width=248, Height=21}" /> |
||||
<Text value="" /> |
||||
</System.Windows.Forms.TextBox> |
||||
<System.Windows.Forms.Label> |
||||
<Name value="prefixLabel" /> |
||||
<Text value="${res:ICSharpCode.XmlEditor.XmlSchemaPanel.NamespacePrefixLabelText}" /> |
||||
<TextAlign value="MiddleLeft" /> |
||||
<TabIndex value="9" /> |
||||
<Size value="{Width=72, Height=16}" /> |
||||
<Location value="{X=8,Y=84}" /> |
||||
</System.Windows.Forms.Label> |
||||
<System.Windows.Forms.TextBox> |
||||
<Name value="schemaTextBox" /> |
||||
<ReadOnly value="True" /> |
||||
<Anchor value="Top, Left, Right" /> |
||||
<TabIndex value="8" /> |
||||
<Location value="{X=80,Y=58}" /> |
||||
<Size value="{Width=216, Height=21}" /> |
||||
<Text value="" /> |
||||
</System.Windows.Forms.TextBox> |
||||
<System.Windows.Forms.ComboBox> |
||||
<Name value="fileExtensionComboBox" /> |
||||
<Anchor value="Top, Left, Right" /> |
||||
<TabIndex value="7" /> |
||||
<Location value="{X=80,Y=34}" /> |
||||
<Size value="{Width=248, Height=21}" /> |
||||
<DropDownStyle value="DropDownList" /> |
||||
</System.Windows.Forms.ComboBox> |
||||
<System.Windows.Forms.Label> |
||||
<Name value="schemaLabel" /> |
||||
<Text value="${res:ICSharpCode.XmlEditor.XmlSchemaPanel.SchemaLabelText}" /> |
||||
<TextAlign value="MiddleLeft" /> |
||||
<TabIndex value="1" /> |
||||
<Size value="{Width=72, Height=16}" /> |
||||
<Location value="{X=8,Y=58}" /> |
||||
</System.Windows.Forms.Label> |
||||
<System.Windows.Forms.Label> |
||||
<Name value="fileExtensionLabel" /> |
||||
<Text value="${res:ICSharpCode.XmlEditor.XmlSchemaPanel.FileExtensionLabelText}" /> |
||||
<TextAlign value="MiddleLeft" /> |
||||
<TabIndex value="0" /> |
||||
<Size value="{Width=72, Height=16}" /> |
||||
<Location value="{X=8,Y=34}" /> |
||||
</System.Windows.Forms.Label> |
||||
<System.Windows.Forms.Button> |
||||
<Name value="changeSchemaButton" /> |
||||
<Location value="{X=304,Y=58}" /> |
||||
<Size value="{Width=24, Height=21}" /> |
||||
<Text value="..." /> |
||||
<Anchor value="Top, Right" /> |
||||
<TabIndex value="6" /> |
||||
</System.Windows.Forms.Button> |
||||
</Controls> |
||||
</System.Windows.Forms.GroupBox> |
||||
<System.Windows.Forms.GroupBox> |
||||
<Name value="schemasGroupBox" /> |
||||
<TabIndex value="3" /> |
||||
<Location value="{X=8,Y=8}" /> |
||||
<Anchor value="Top, Left, Right" /> |
||||
<Size value="{Width=336, Height=170}" /> |
||||
<Text value="${res:ICSharpCode.XmlEditor.XmlSchemaPanel.SchemasGroupBoxText}" /> |
||||
<Controls> |
||||
<System.Windows.Forms.Button> |
||||
<Name value="addButton" /> |
||||
<Location value="{X=160,Y=140}" /> |
||||
<Size value="{Width=80, Height=24}" /> |
||||
<Text value="${res:Global.AddButtonText}..." /> |
||||
<Anchor value="Bottom, Right" /> |
||||
<TabIndex value="4" /> |
||||
</System.Windows.Forms.Button> |
||||
<System.Windows.Forms.Button> |
||||
<Name value="removeButton" /> |
||||
<Location value="{X=247,Y=140}" /> |
||||
<Size value="{Width=80, Height=24}" /> |
||||
<Text value="${res:Global.RemoveButtonText}" /> |
||||
<Anchor value="Bottom, Right" /> |
||||
<TabIndex value="5" /> |
||||
</System.Windows.Forms.Button> |
||||
<System.Windows.Forms.ListBox> |
||||
<Name value="schemaListBox" /> |
||||
<Size value="{Width=320, Height=108}" /> |
||||
<Anchor value="Top, Left, Right" /> |
||||
<TabIndex value="3" /> |
||||
<Location value="{X=8,Y=29}" /> |
||||
</System.Windows.Forms.ListBox> |
||||
</Controls> |
||||
</System.Windows.Forms.GroupBox> |
||||
</Controls> |
||||
</System.Windows.Forms.UserControl> |
||||
</Components> |
@ -0,0 +1,650 @@
@@ -0,0 +1,650 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.TextEditor; |
||||
using ICSharpCode.TextEditor.Document; |
||||
using System; |
||||
using System.Drawing; |
||||
using System.Drawing.Printing; |
||||
using System.IO; |
||||
using System.Windows.Forms; |
||||
using System.Xml; |
||||
using System.Xml.Schema; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Wrapper class for the XmlEditor used when displaying the xml file.
|
||||
/// </summary>
|
||||
public class XmlView : AbstractViewContent, IEditable, IClipboardHandler, IParseInformationListener, IMementoCapable, IPrintable, ITextEditorControlProvider, IPositionable |
||||
{ |
||||
/// <summary>
|
||||
/// The language handled by this view.
|
||||
/// </summary>
|
||||
public static readonly string Language = "XML"; |
||||
|
||||
delegate void RefreshDelegate(AbstractMargin margin); |
||||
|
||||
XmlEditorControl xmlEditor = new XmlEditorControl(); |
||||
FileSystemWatcher watcher; |
||||
bool wasChangedExternally; |
||||
MessageViewCategory category; |
||||
|
||||
public XmlView() |
||||
{ |
||||
xmlEditor.Dock = DockStyle.Fill; |
||||
|
||||
xmlEditor.SchemaCompletionDataItems = XmlSchemaManager.SchemaCompletionDataItems; |
||||
xmlEditor.Document.DocumentChanged += new DocumentEventHandler(DocumentChanged); |
||||
|
||||
xmlEditor.ActiveTextAreaControl.Caret.CaretModeChanged += new EventHandler(CaretModeChanged); |
||||
xmlEditor.ActiveTextAreaControl.Enter += new EventHandler(CaretUpdate); |
||||
((Form)ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.Workbench).Activated += new EventHandler(GotFocusEvent); |
||||
|
||||
// Listen for changes to the xml editor properties.
|
||||
XmlEditorAddInOptions.PropertyChanged += PropertyChanged; |
||||
XmlSchemaManager.UserSchemaAdded += new EventHandler(UserSchemaAdded); |
||||
XmlSchemaManager.UserSchemaRemoved += new EventHandler(UserSchemaRemoved); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Loads the string content into the view.
|
||||
/// </summary>
|
||||
public void LoadContent(string content) |
||||
{ |
||||
xmlEditor.Document.TextContent = StringParser.Parse(content); |
||||
xmlEditor.Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategy(XmlView.Language); |
||||
UpdateFolding(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Can create content for the 'XML' language.
|
||||
/// </summary>
|
||||
public static bool IsLanguageHandled(string language) |
||||
{ |
||||
return language == XmlView.Language; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns whether the view can handle the specified file.
|
||||
/// </summary>
|
||||
public static bool IsFileNameHandled(string fileName) |
||||
{ |
||||
return IsXmlFileExtension(Path.GetExtension(fileName)); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the known xml file extensions.
|
||||
/// </summary>
|
||||
public static string[] GetXmlFileExtensions() |
||||
{ |
||||
IHighlightingStrategy strategy = HighlightingManager.Manager.FindHighlighter(XmlView.Language); |
||||
if (strategy != null) { |
||||
return strategy.Extensions; |
||||
} |
||||
|
||||
return new string[0]; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Validates the xml against known schemas.
|
||||
/// </summary>
|
||||
public void ValidateXml() |
||||
{ |
||||
ClearTasks(); |
||||
Category.ClearText(); |
||||
OutputWindowWriteLine(StringParser.Parse("${res:MainWindow.XmlValidationMessages.ValidationStarted}")); |
||||
|
||||
try { |
||||
StringReader stringReader = new StringReader(xmlEditor.Document.TextContent); |
||||
XmlTextReader xmlReader = new XmlTextReader(stringReader); |
||||
xmlReader.XmlResolver = null; |
||||
XmlValidatingReader reader = new XmlValidatingReader(xmlReader); |
||||
reader.XmlResolver = null; |
||||
|
||||
foreach (XmlSchemaCompletionData schemaData in XmlSchemaManager.SchemaCompletionDataItems) { |
||||
reader.Schemas.Add(schemaData.Schema); |
||||
} |
||||
|
||||
XmlDocument doc = new XmlDocument(); |
||||
doc.Load(reader); |
||||
|
||||
OutputWindowWriteLine(String.Empty); |
||||
OutputWindowWriteLine(StringParser.Parse("${res:MainWindow.XmlValidationMessages.ValidationSuccess}")); |
||||
|
||||
} catch (XmlSchemaException ex) { |
||||
DisplayValidationError(xmlEditor.FileName, ex.Message, ex.LinePosition - 1, ex.LineNumber - 1); |
||||
} catch (XmlException ex) { |
||||
DisplayValidationError(xmlEditor.FileName, ex.Message, ex.LinePosition - 1, ex.LineNumber - 1); |
||||
} |
||||
|
||||
// Show tasks.
|
||||
if (HasTasks && ShowTaskListAfterBuild) { |
||||
ShowTasks(); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the name of a new view.
|
||||
/// </summary>
|
||||
public override string UntitledName { |
||||
get { |
||||
return base.UntitledName; |
||||
} |
||||
set { |
||||
base.UntitledName = value; |
||||
xmlEditor.FileName = value; |
||||
SetDefaultSchema(Path.GetExtension(xmlEditor.FileName)); |
||||
} |
||||
} |
||||
|
||||
public override void Dispose() |
||||
{ |
||||
((Form)ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.Workbench).Activated -= new EventHandler(GotFocusEvent); |
||||
|
||||
XmlEditorAddInOptions.PropertyChanged -= PropertyChanged; |
||||
XmlSchemaManager.UserSchemaAdded -= new EventHandler(UserSchemaAdded); |
||||
XmlSchemaManager.UserSchemaRemoved -= new EventHandler(UserSchemaRemoved); |
||||
|
||||
xmlEditor.Dispose(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Sets the filename associated with the view.
|
||||
/// </summary>
|
||||
public override string FileName { |
||||
set { |
||||
if (Path.GetExtension(FileName) != Path.GetExtension(value)) { |
||||
if (xmlEditor.Document.HighlightingStrategy != null) { |
||||
xmlEditor.Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategyForFile(value); |
||||
xmlEditor.Refresh(); |
||||
} |
||||
} |
||||
base.FileName = value; |
||||
base.TitleName = Path.GetFileName(value); |
||||
|
||||
SetDefaultSchema(Path.GetExtension(xmlEditor.FileName)); |
||||
} |
||||
} |
||||
|
||||
#region IEditable interface
|
||||
|
||||
public IClipboardHandler ClipboardHandler { |
||||
get { |
||||
return this; |
||||
} |
||||
} |
||||
|
||||
public bool EnableUndo { |
||||
get { |
||||
return xmlEditor.EnableUndo; |
||||
} |
||||
} |
||||
|
||||
public bool EnableRedo { |
||||
get { |
||||
return xmlEditor.EnableUndo; |
||||
} |
||||
} |
||||
|
||||
public string Text { |
||||
get { |
||||
return xmlEditor.Document.TextContent; |
||||
} |
||||
set { |
||||
xmlEditor.Document.TextContent = value; |
||||
} |
||||
} |
||||
|
||||
public void Redo() |
||||
{ |
||||
xmlEditor.Redo(); |
||||
} |
||||
|
||||
public void Undo() |
||||
{ |
||||
xmlEditor.Undo(); |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
#region AbstractViewContent implementation
|
||||
|
||||
public override Control Control { |
||||
get { |
||||
return xmlEditor; |
||||
} |
||||
} |
||||
|
||||
public override void Load(string fileName) |
||||
{ |
||||
xmlEditor.IsReadOnly = IsFileReadOnly(fileName); |
||||
xmlEditor.LoadFile(fileName); |
||||
FileName = fileName; |
||||
TitleName = Path.GetFileName(fileName); |
||||
IsDirty = false; |
||||
UpdateFolding(); |
||||
SetWatcher(); |
||||
} |
||||
|
||||
public override void Save(string fileName) |
||||
{ |
||||
OnSaving(EventArgs.Empty); |
||||
|
||||
if (watcher != null) { |
||||
watcher.EnableRaisingEvents = false; |
||||
} |
||||
|
||||
xmlEditor.SaveFile(fileName); |
||||
FileName = fileName; |
||||
TitleName = Path.GetFileName(fileName); |
||||
IsDirty = false; |
||||
|
||||
SetWatcher(); |
||||
OnSaved(new SaveEventArgs(true)); |
||||
} |
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region IClipboardHandler interface
|
||||
|
||||
public bool EnableCut { |
||||
get { |
||||
return xmlEditor.ActiveTextAreaControl.TextArea.ClipboardHandler.EnableCut; |
||||
} |
||||
} |
||||
|
||||
public bool EnableCopy { |
||||
get { |
||||
return xmlEditor.ActiveTextAreaControl.TextArea.ClipboardHandler.EnableCopy; |
||||
} |
||||
} |
||||
|
||||
public bool EnablePaste { |
||||
get { |
||||
return xmlEditor.ActiveTextAreaControl.TextArea.ClipboardHandler.EnablePaste; |
||||
} |
||||
} |
||||
|
||||
public bool EnableDelete { |
||||
get { |
||||
return xmlEditor.ActiveTextAreaControl.TextArea.ClipboardHandler.EnableDelete; |
||||
} |
||||
} |
||||
|
||||
public bool EnableSelectAll { |
||||
get { |
||||
return xmlEditor.ActiveTextAreaControl.TextArea.ClipboardHandler.EnableSelectAll; |
||||
} |
||||
} |
||||
|
||||
public void SelectAll() |
||||
{ |
||||
xmlEditor.ActiveTextAreaControl.TextArea.ClipboardHandler.SelectAll(null, EventArgs.Empty); |
||||
} |
||||
|
||||
public void Delete() |
||||
{ |
||||
xmlEditor.ActiveTextAreaControl.TextArea.ClipboardHandler.Delete(null, EventArgs.Empty); |
||||
} |
||||
|
||||
public void Paste() |
||||
{ |
||||
xmlEditor.ActiveTextAreaControl.TextArea.ClipboardHandler.Paste(null, EventArgs.Empty); |
||||
} |
||||
|
||||
public void Copy() |
||||
{ |
||||
xmlEditor.ActiveTextAreaControl.TextArea.ClipboardHandler.Copy(null, EventArgs.Empty); |
||||
} |
||||
|
||||
public void Cut() |
||||
{ |
||||
xmlEditor.ActiveTextAreaControl.TextArea.ClipboardHandler.Cut(null, EventArgs.Empty); |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
#region IParseInformationListener interface
|
||||
|
||||
public void ParseInformationUpdated(ParseInformation parseInfo) |
||||
{ |
||||
UpdateFolding(); |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
#region IMementoCapable interface
|
||||
|
||||
public void SetMemento(Properties properties) |
||||
{ |
||||
xmlEditor.ActiveTextAreaControl.Caret.Position = xmlEditor.Document.OffsetToPosition(Math.Min(xmlEditor.Document.TextLength, Math.Max(0, properties.Get("CaretOffset", xmlEditor.ActiveTextAreaControl.Caret.Offset)))); |
||||
|
||||
if (xmlEditor.Document.HighlightingStrategy.Name != properties.Get("HighlightingLanguage", xmlEditor.Document.HighlightingStrategy.Name)) { |
||||
IHighlightingStrategy highlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategy(properties.Get("HighlightingLanguage", xmlEditor.Document.HighlightingStrategy.Name)); |
||||
if (highlightingStrategy != null) { |
||||
xmlEditor.Document.HighlightingStrategy = highlightingStrategy; |
||||
} |
||||
} |
||||
xmlEditor.ActiveTextAreaControl.TextArea.TextView.FirstVisibleLine = properties.Get("VisibleLine", 0); |
||||
|
||||
xmlEditor.Document.FoldingManager.DeserializeFromString(properties.Get("Foldings", "")); |
||||
} |
||||
|
||||
public Properties CreateMemento() |
||||
{ |
||||
Properties properties = new Properties(); |
||||
properties.Set("CaretOffset", xmlEditor.ActiveTextAreaControl.Caret.Offset); |
||||
properties.Set("VisibleLine", xmlEditor.ActiveTextAreaControl.TextArea.TextView.FirstVisibleLine); |
||||
properties.Set("HighlightingLanguage", xmlEditor.Document.HighlightingStrategy.Name); |
||||
properties.Set("Foldings", xmlEditor.Document.FoldingManager.SerializeToString()); |
||||
return properties; |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
#region IPrintable interface
|
||||
|
||||
public PrintDocument PrintDocument{ |
||||
get { |
||||
return xmlEditor.PrintDocument; |
||||
} |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
#region ITextEditorControlProvider interface
|
||||
|
||||
public TextEditorControl TextEditorControl { |
||||
get { |
||||
return xmlEditor; |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
#region IPositionable interface
|
||||
|
||||
/// <summary>
|
||||
/// Moves the cursor to the specified line and column.
|
||||
/// </summary>
|
||||
public void JumpTo(int line, int column) |
||||
{ |
||||
xmlEditor.ActiveTextAreaControl.JumpTo(line, column); |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
protected override void OnFileNameChanged(EventArgs e) |
||||
{ |
||||
base.OnFileNameChanged(e); |
||||
xmlEditor.FileName = base.FileName; |
||||
} |
||||
|
||||
static bool IsFileReadOnly(string fileName) |
||||
{ |
||||
return (File.GetAttributes(fileName) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Checks that the file extension refers to an xml file as
|
||||
/// specified in the SyntaxModes.xml file.
|
||||
/// </summary>
|
||||
static bool IsXmlFileExtension(string extension) |
||||
{ |
||||
bool isXmlFileExtension = false; |
||||
|
||||
IHighlightingStrategy strategy = HighlightingManager.Manager.FindHighlighter(XmlView.Language); |
||||
if (strategy != null) { |
||||
foreach (string currentExtension in strategy.Extensions) { |
||||
if (String.Compare(extension, currentExtension, true) == 0) { |
||||
isXmlFileExtension = true; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
return isXmlFileExtension; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Forces the editor to update its folds.
|
||||
/// </summary>
|
||||
void UpdateFolding() |
||||
{ |
||||
xmlEditor.Document.FoldingManager.UpdateFoldings(String.Empty, null); |
||||
RefreshMargin(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Repaints the folds in the margin.
|
||||
/// </summary>
|
||||
void RefreshMargin() |
||||
{ |
||||
RefreshDelegate refreshDelegate = new RefreshDelegate(xmlEditor.ActiveTextAreaControl.TextArea.Refresh); |
||||
xmlEditor.ActiveTextAreaControl.TextArea.Invoke(refreshDelegate, new object[] { xmlEditor.ActiveTextAreaControl.TextArea.FoldMargin}); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Sets the dirty flag since the document has changed.
|
||||
/// </summary>
|
||||
void DocumentChanged(object sender, DocumentEventArgs e) |
||||
{ |
||||
IsDirty = true; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Updates the line, col, overwrite/insert mode in the status bar.
|
||||
/// </summary>
|
||||
void CaretUpdate(object sender, EventArgs e) |
||||
{ |
||||
CaretChanged(sender, e); |
||||
CaretModeChanged(sender, e); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Updates the line, col information in the status bar.
|
||||
/// </summary>
|
||||
void CaretChanged(object sender, EventArgs e) |
||||
{ |
||||
Point pos = xmlEditor.Document.OffsetToPosition(xmlEditor.ActiveTextAreaControl.Caret.Offset); |
||||
LineSegment line = xmlEditor.Document.GetLineSegment(pos.Y); |
||||
StatusBarService.SetCaretPosition(pos.X + 1, pos.Y + 1, xmlEditor.ActiveTextAreaControl.Caret.Offset - line.Offset + 1); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Updates the insert/overwrite mode text in the status bar.
|
||||
/// </summary>
|
||||
void CaretModeChanged(object sender, EventArgs e) |
||||
{ |
||||
StatusBarService.SetInsertMode(xmlEditor.ActiveTextAreaControl.Caret.CaretMode == CaretMode.InsertMode); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates the file system watcher.
|
||||
/// </summary>
|
||||
void SetWatcher() |
||||
{ |
||||
try { |
||||
if (this.watcher == null) { |
||||
this.watcher = new FileSystemWatcher(); |
||||
this.watcher.Changed += new FileSystemEventHandler(this.OnFileChangedEvent); |
||||
} else { |
||||
this.watcher.EnableRaisingEvents = false; |
||||
} |
||||
this.watcher.Path = Path.GetDirectoryName(xmlEditor.FileName); |
||||
this.watcher.Filter = Path.GetFileName(xmlEditor.FileName); |
||||
this.watcher.NotifyFilter = NotifyFilters.LastWrite; |
||||
this.watcher.EnableRaisingEvents = true; |
||||
} catch (Exception) { |
||||
watcher = null; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Shows the "File was changed" dialog if the file was
|
||||
/// changed externally.
|
||||
/// </summary>
|
||||
void GotFocusEvent(object sender, EventArgs e) |
||||
{ |
||||
lock (this) { |
||||
if (wasChangedExternally) { |
||||
wasChangedExternally = false; |
||||
string message = StringParser.Parse("${res:ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor.TextEditorDisplayBinding.FileAlteredMessage}", new string[,] {{"File", Path.GetFullPath(xmlEditor.FileName)}}); |
||||
if (MessageService.AskQuestion(message, "${res:MainWindow.DialogName}")) { |
||||
Load(xmlEditor.FileName); |
||||
} else { |
||||
IsDirty = true; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
void OnFileChangedEvent(object sender, FileSystemEventArgs e) |
||||
{ |
||||
lock (this) { |
||||
if(e.ChangeType != WatcherChangeTypes.Deleted) { |
||||
wasChangedExternally = true; |
||||
if (((Form)ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.Workbench).Focused) { |
||||
GotFocusEvent(this, EventArgs.Empty); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the xml validation output window.
|
||||
/// </summary>
|
||||
MessageViewCategory Category { |
||||
get { |
||||
if (category == null) { |
||||
category = new MessageViewCategory("Xml", "Xml"); |
||||
CompilerMessageView cmv = (CompilerMessageView)WorkbenchSingleton.Workbench.GetPad(typeof(CompilerMessageView)).PadContent; |
||||
cmv.AddCategory(category); |
||||
} |
||||
|
||||
return category; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Writes a line of text to the output window.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to send to the output
|
||||
/// window.</param>
|
||||
void OutputWindowWriteLine(string message) |
||||
{ |
||||
Category.AppendText(String.Concat(message, Environment.NewLine)); |
||||
} |
||||
|
||||
void ClearTasks() |
||||
{ |
||||
if (HasTasks) { |
||||
TaskService.Clear(); |
||||
} |
||||
} |
||||
|
||||
bool ShowTaskListAfterBuild { |
||||
get { |
||||
return PropertyService.Get("SharpDevelop.ShowTaskListAfterBuild", true); |
||||
} |
||||
} |
||||
|
||||
bool HasTasks { |
||||
get { |
||||
bool hasTasks = false; |
||||
if (TaskService.TaskCount > 0) { |
||||
hasTasks = true; |
||||
} |
||||
return hasTasks; |
||||
} |
||||
} |
||||
|
||||
void ShowTasks() |
||||
{ |
||||
PadDescriptor pad = WorkbenchSingleton.Workbench.GetPad(typeof(OpenTaskView)); |
||||
if (pad != null) { |
||||
WorkbenchSingleton.Workbench.ShowPad(pad); |
||||
} |
||||
} |
||||
|
||||
void AddTask(string fileName, string message, int column, int line, TaskType taskType) |
||||
{ |
||||
TaskService.Add(new Task(fileName, message, column, line, taskType)); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Displays the validation error.
|
||||
/// </summary>
|
||||
void DisplayValidationError(string fileName, string message, int column, int line) |
||||
{ |
||||
OutputWindowWriteLine(message); |
||||
OutputWindowWriteLine(String.Empty); |
||||
OutputWindowWriteLine(StringParser.Parse("${res:MainWindow.XmlValidationMessages.ValidationFailed}")); |
||||
AddTask(fileName, message, column, line, TaskType.Error); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Updates the default schema associated with the xml editor.
|
||||
/// </summary>
|
||||
void PropertyChanged(object sender, PropertyChangedEventArgs e) |
||||
{ |
||||
string extension = Path.GetExtension(xmlEditor.FileName).ToLower(); |
||||
if (e.Key == extension) { |
||||
SetDefaultSchema(extension); |
||||
} else if (e.Key == XmlEditorAddInOptions.ShowAttributesWhenFoldedPropertyName) { |
||||
UpdateFolding(); |
||||
xmlEditor.Refresh(); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Sets the default schema and namespace prefix that the xml editor will use.
|
||||
/// </summary>
|
||||
void SetDefaultSchema(string extension) |
||||
{ |
||||
xmlEditor.DefaultSchemaCompletionData = XmlSchemaManager.GetSchemaCompletionData(extension); |
||||
xmlEditor.DefaultNamespacePrefix = XmlSchemaManager.GetNamespacePrefix(extension); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Updates the default schema association since the schema
|
||||
/// may have been added.
|
||||
/// </summary>
|
||||
void UserSchemaAdded(object source, EventArgs e) |
||||
{ |
||||
SetDefaultSchema(Path.GetExtension(xmlEditor.FileName).ToLower()); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Updates the default schema association since the schema
|
||||
/// may have been removed.
|
||||
/// </summary>
|
||||
void UserSchemaRemoved(object source, EventArgs e) |
||||
{ |
||||
SetDefaultSchema(Path.GetExtension(xmlEditor.FileName).ToLower()); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
using System.Reflection; |
||||
using System.Runtime.CompilerServices; |
||||
|
||||
// Information about this assembly is defined by the following
|
||||
// attributes.
|
||||
//
|
||||
// change them to the information which is associated with the assembly
|
||||
// you compile.
|
||||
|
||||
[assembly: AssemblyTitle("")] |
||||
[assembly: AssemblyDescription("")] |
||||
[assembly: AssemblyConfiguration("")] |
||||
[assembly: AssemblyCompany("")] |
||||
[assembly: AssemblyProduct("")] |
||||
[assembly: AssemblyCopyright("")] |
||||
[assembly: AssemblyTrademark("")] |
||||
[assembly: AssemblyCulture("")] |
||||
|
||||
// The assembly version has following format :
|
||||
//
|
||||
// Major.Minor.Build.Revision
|
||||
//
|
||||
// You can specify all values by your own or you can build default build and revision
|
||||
// numbers with the '*' character (the default):
|
||||
|
||||
[assembly: AssemblyVersion("1.1.0.1964")] |
||||
|
||||
// The following attributes specify the key for the sign of your assembly. See the
|
||||
// .NET Framework documentation for more information about signing.
|
||||
// This is not required, if you don't want signing let these attributes like they're.
|
||||
[assembly: AssemblyDelaySign(false)] |
||||
[assembly: AssemblyKeyFile("")] |
@ -0,0 +1,129 @@
@@ -0,0 +1,129 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.Xml; |
||||
|
||||
namespace XmlEditor.Tests.Parser |
||||
{ |
||||
[TestFixture] |
||||
public class ActiveElementStartPathTestFixture |
||||
{ |
||||
XmlElementPath elementPath; |
||||
XmlElementPath expectedElementPath; |
||||
string namespaceURI = "http://foo.com/foo.xsd"; |
||||
|
||||
[Test] |
||||
public void PathTest1() |
||||
{ |
||||
string text = "<foo xmlns='" + namespaceURI + "' "; |
||||
elementPath = XmlParser.GetActiveElementStartPath(text, text.Length); |
||||
|
||||
expectedElementPath = new XmlElementPath(); |
||||
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); |
||||
Assert.IsTrue(elementPath.Equals(expectedElementPath), |
||||
"Incorrect active element path."); |
||||
} |
||||
|
||||
[Test] |
||||
public void PathTest2() |
||||
{ |
||||
string text = "<foo xmlns='" + namespaceURI + "' ><bar "; |
||||
elementPath = XmlParser.GetActiveElementStartPath(text, text.Length); |
||||
|
||||
expectedElementPath = new XmlElementPath(); |
||||
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); |
||||
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI)); |
||||
Assert.IsTrue(expectedElementPath.Equals(elementPath), |
||||
"Incorrect active element path."); |
||||
} |
||||
|
||||
[Test] |
||||
public void PathTest3() |
||||
{ |
||||
string text = "<f:foo xmlns:f='" + namespaceURI + "' ><f:bar "; |
||||
elementPath = XmlParser.GetActiveElementStartPath(text, text.Length); |
||||
|
||||
expectedElementPath = new XmlElementPath(); |
||||
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI, "f")); |
||||
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI, "f")); |
||||
Assert.IsTrue(expectedElementPath.Equals(elementPath), |
||||
"Incorrect active element path."); |
||||
} |
||||
|
||||
[Test] |
||||
public void PathTest4() |
||||
{ |
||||
string text = "<x:foo xmlns:x='" + namespaceURI + "' "; |
||||
elementPath = XmlParser.GetActiveElementStartPath(text, text.Length); |
||||
|
||||
expectedElementPath = new XmlElementPath(); |
||||
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI, "x")); |
||||
Assert.IsTrue(expectedElementPath.Equals(elementPath), |
||||
"Incorrect active element path."); |
||||
} |
||||
|
||||
[Test] |
||||
public void PathTest5() |
||||
{ |
||||
string text = "<foo xmlns='" + namespaceURI + "'>\r\n"+ |
||||
"<y\r\n" + |
||||
"Id = 'foo' "; |
||||
|
||||
elementPath = XmlParser.GetActiveElementStartPath(text, text.Length); |
||||
|
||||
expectedElementPath = new XmlElementPath(); |
||||
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); |
||||
expectedElementPath.Elements.Add(new QualifiedName("y", namespaceURI)); |
||||
Assert.IsTrue(expectedElementPath.Equals(elementPath), |
||||
"Incorrect active element path."); |
||||
} |
||||
|
||||
[Test] |
||||
public void PathTest6() |
||||
{ |
||||
string text = "<bar xmlns='http://bar'>\r\n" + |
||||
"<foo xmlns='" + namespaceURI + "' "; |
||||
|
||||
elementPath = XmlParser.GetActiveElementStartPath(text, text.Length); |
||||
|
||||
expectedElementPath = new XmlElementPath(); |
||||
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); |
||||
Assert.IsTrue(expectedElementPath.Equals(elementPath), |
||||
"Incorrect active element path."); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that we get no path back if we are outside the start
|
||||
/// tag.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void OutOfStartTagPathTest1() |
||||
{ |
||||
string text = "<foo xmlns='" + namespaceURI + "'> "; |
||||
|
||||
elementPath = XmlParser.GetActiveElementStartPath(text, text.Length); |
||||
Assert.AreEqual(0, elementPath.Elements.Count, "Should have no path."); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,105 @@
@@ -0,0 +1,105 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.Xml; |
||||
|
||||
namespace XmlEditor.Tests.Parser |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that we can detect the attribute's name.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class AttributeNameTestFixture |
||||
{ |
||||
[Test] |
||||
public void SuccessTest1() |
||||
{ |
||||
string text = " foo='a"; |
||||
Assert.AreEqual("foo", XmlParser.GetAttributeName(text, text.Length), "Should have retrieved the attribute name 'foo'"); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest2() |
||||
{ |
||||
string text = " foo='"; |
||||
Assert.AreEqual("foo", XmlParser.GetAttributeName(text, text.Length), "Should have retrieved the attribute name 'foo'"); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest3() |
||||
{ |
||||
string text = " foo="; |
||||
Assert.AreEqual("foo", XmlParser.GetAttributeName(text, text.Length), "Should have retrieved the attribute name 'foo'"); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest4() |
||||
{ |
||||
string text = " foo=\""; |
||||
Assert.AreEqual("foo", XmlParser.GetAttributeName(text, text.Length), "Should have retrieved the attribute name 'foo'"); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest5() |
||||
{ |
||||
string text = " foo = \""; |
||||
Assert.AreEqual("foo", XmlParser.GetAttributeName(text, text.Length), "Should have retrieved the attribute name 'foo'"); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest6() |
||||
{ |
||||
string text = " foo = '#"; |
||||
Assert.AreEqual("foo", XmlParser.GetAttributeName(text, text.Length), "Should have retrieved the attribute name 'foo'"); |
||||
} |
||||
|
||||
[Test] |
||||
public void FailureTest1() |
||||
{ |
||||
string text = "foo="; |
||||
Assert.AreEqual(String.Empty, XmlParser.GetAttributeName(text, text.Length), "Should have retrieved the attribute name 'foo'"); |
||||
} |
||||
|
||||
[Test] |
||||
public void FailureTest2() |
||||
{ |
||||
string text = "foo=<"; |
||||
Assert.AreEqual(String.Empty, XmlParser.GetAttributeName(text, text.Length), "Should have retrieved the attribute name 'foo'"); |
||||
} |
||||
|
||||
[Test] |
||||
public void FailureTest3() |
||||
{ |
||||
string text = "a"; |
||||
Assert.AreEqual(String.Empty, XmlParser.GetAttributeName(text, text.Length), "Should have retrieved the attribute name 'foo'"); |
||||
} |
||||
|
||||
[Test] |
||||
public void FailureTest4() |
||||
{ |
||||
string text = " a"; |
||||
Assert.AreEqual(String.Empty, XmlParser.GetAttributeName(text, text.Length), "Should have retrieved the attribute name 'foo'"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,134 @@
@@ -0,0 +1,134 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.Xml; |
||||
|
||||
namespace XmlEditor.Tests.Parser |
||||
{ |
||||
/// <summary>
|
||||
/// When the user hits the '=' key we need to produce intellisense
|
||||
/// if the attribute is of the form 'xmlns' or 'xmlns:foo'. This
|
||||
/// tests the parsing of the text before the cursor to see if the
|
||||
/// attribute is a namespace declaration.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class NamespaceDeclarationTestFixture |
||||
{ |
||||
[Test] |
||||
public void SuccessTest1() |
||||
{ |
||||
string text = "<foo xmlns="; |
||||
bool isNamespace = XmlParser.IsNamespaceDeclaration(text, text.Length); |
||||
Assert.IsTrue(isNamespace, "Namespace should be recognised."); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest2() |
||||
{ |
||||
string text = "<foo xmlns ="; |
||||
bool isNamespace = XmlParser.IsNamespaceDeclaration(text, text.Length); |
||||
Assert.IsTrue(isNamespace, "Namespace should be recognised."); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest3() |
||||
{ |
||||
string text = "<foo \r\nxmlns\r\n="; |
||||
bool isNamespace = XmlParser.IsNamespaceDeclaration(text, text.Length); |
||||
Assert.IsTrue(isNamespace, "Namespace should be recognised."); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest4() |
||||
{ |
||||
string text = "<foo xmlns:nant="; |
||||
bool isNamespace = XmlParser.IsNamespaceDeclaration(text, text.Length); |
||||
Assert.IsTrue(isNamespace, "Namespace should be recognised."); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest5() |
||||
{ |
||||
string text = "<foo xmlns"; |
||||
bool isNamespace = XmlParser.IsNamespaceDeclaration(text, text.Length); |
||||
Assert.IsTrue(isNamespace, "Namespace should be recognised."); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest6() |
||||
{ |
||||
string text = "<foo xmlns:nant"; |
||||
bool isNamespace = XmlParser.IsNamespaceDeclaration(text, text.Length); |
||||
Assert.IsTrue(isNamespace, "Namespace should be recognised."); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest7() |
||||
{ |
||||
string text = " xmlns="; |
||||
bool isNamespace = XmlParser.IsNamespaceDeclaration(text, text.Length); |
||||
Assert.IsTrue(isNamespace, "Namespace should be recognised."); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest8() |
||||
{ |
||||
string text = " xmlns"; |
||||
bool isNamespace = XmlParser.IsNamespaceDeclaration(text, text.Length); |
||||
Assert.IsTrue(isNamespace, "Namespace should be recognised."); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest9() |
||||
{ |
||||
string text = " xmlns:f"; |
||||
bool isNamespace = XmlParser.IsNamespaceDeclaration(text, text.Length); |
||||
Assert.IsTrue(isNamespace, "Namespace should be recognised."); |
||||
} |
||||
|
||||
[Test] |
||||
public void FailureTest1() |
||||
{ |
||||
string text = "<foo bar="; |
||||
bool isNamespace = XmlParser.IsNamespaceDeclaration(text, text.Length); |
||||
Assert.IsFalse(isNamespace, "Namespace should not be recognised."); |
||||
} |
||||
|
||||
[Test] |
||||
public void FailureTest2() |
||||
{ |
||||
string text = ""; |
||||
bool isNamespace = XmlParser.IsNamespaceDeclaration(text, text.Length); |
||||
Assert.IsFalse(isNamespace, "Namespace should not be recognised."); |
||||
} |
||||
|
||||
[Test] |
||||
public void FailureTest3() |
||||
{ |
||||
string text = " "; |
||||
bool isNamespace = XmlParser.IsNamespaceDeclaration(text, text.Length); |
||||
Assert.IsFalse(isNamespace, "Namespace should not be recognised."); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,84 @@
@@ -0,0 +1,84 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.Xml; |
||||
|
||||
namespace XmlEditor.Tests.Parser |
||||
{ |
||||
[TestFixture] |
||||
public class ParentElementPathTestFixture |
||||
{ |
||||
XmlElementPath elementPath; |
||||
XmlElementPath expectedElementPath; |
||||
string namespaceURI = "http://foo/foo.xsd"; |
||||
|
||||
[Test] |
||||
public void SuccessTest1() |
||||
{ |
||||
string text = "<foo xmlns='" + namespaceURI + "' ><"; |
||||
elementPath = XmlParser.GetParentElementPath(text, text.Length); |
||||
|
||||
expectedElementPath = new XmlElementPath(); |
||||
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); |
||||
Assert.IsTrue(elementPath.Equals(expectedElementPath), |
||||
"Incorrect active element path."); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest2() |
||||
{ |
||||
string text = "<foo xmlns='" + namespaceURI + "' ><bar></bar><"; |
||||
elementPath = XmlParser.GetParentElementPath(text, text.Length); |
||||
|
||||
expectedElementPath = new XmlElementPath(); |
||||
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); |
||||
Assert.IsTrue(elementPath.Equals(expectedElementPath), |
||||
"Incorrect active element path."); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest3() |
||||
{ |
||||
string text = "<foo xmlns='" + namespaceURI + "' ><bar/><"; |
||||
elementPath = XmlParser.GetParentElementPath(text, text.Length); |
||||
|
||||
expectedElementPath = new XmlElementPath(); |
||||
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); |
||||
Assert.IsTrue(elementPath.Equals(expectedElementPath), |
||||
"Incorrect active element path."); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest4() |
||||
{ |
||||
string text = "<bar xmlns='http://test.com'><foo xmlns='" + namespaceURI + "' ><"; |
||||
elementPath = XmlParser.GetParentElementPath(text, text.Length); |
||||
|
||||
expectedElementPath = new XmlElementPath(); |
||||
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); |
||||
Assert.IsTrue(elementPath.Equals(expectedElementPath), |
||||
"Incorrect active element path."); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
|
||||
namespace XmlEditor.Tests.Parser |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the comparison of <see cref="QualifiedName"/> items.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class QualifiedNameTestFixture |
||||
{ |
||||
[Test] |
||||
public void EqualsTest1() |
||||
{ |
||||
QualifiedName name1 = new QualifiedName("foo", "http://foo.com"); |
||||
QualifiedName name2 = new QualifiedName("foo", "http://foo.com"); |
||||
|
||||
Assert.AreEqual(name1, name2, "Should be the same."); |
||||
} |
||||
|
||||
[Test] |
||||
public void EqualsTest2() |
||||
{ |
||||
QualifiedName name1 = new QualifiedName("foo", "http://foo.com", "f"); |
||||
QualifiedName name2 = new QualifiedName("foo", "http://foo.com", "f"); |
||||
|
||||
Assert.AreEqual(name1, name2, "Should be the same."); |
||||
} |
||||
|
||||
[Test] |
||||
public void EqualsTest3() |
||||
{ |
||||
QualifiedName name1 = new QualifiedName("foo", "http://foo.com", "f"); |
||||
QualifiedName name2 = new QualifiedName("foo", "http://foo.com", "ggg"); |
||||
|
||||
Assert.IsTrue(name1 == name2, "Should be the same."); |
||||
} |
||||
|
||||
[Test] |
||||
public void NotEqualsTest1() |
||||
{ |
||||
QualifiedName name1 = new QualifiedName("foo", "http://foo.com", "f"); |
||||
QualifiedName name2 = new QualifiedName("foo", "http://bar.com", "f"); |
||||
|
||||
Assert.IsFalse(name1 == name2, "Should not be the same."); |
||||
} |
||||
|
||||
[Test] |
||||
public void NotEqualsTest2() |
||||
{ |
||||
QualifiedName name1 = new QualifiedName("foo", "http://foo.com", "f"); |
||||
QualifiedName name2 = null; |
||||
|
||||
Assert.IsFalse(name1 == name2, "Should not be the same."); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,70 @@
@@ -0,0 +1,70 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
|
||||
namespace XmlEditor.Tests.Paths |
||||
{ |
||||
[TestFixture] |
||||
public class NoElementPathTestFixture |
||||
{ |
||||
XmlElementPath path; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureSetUp() |
||||
{ |
||||
path = new XmlElementPath(); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasNoItems() |
||||
{ |
||||
Assert.AreEqual(0, path.Elements.Count, |
||||
"Should not be any elements."); |
||||
} |
||||
|
||||
[Test] |
||||
public void Equality() |
||||
{ |
||||
XmlElementPath newPath = new XmlElementPath(); |
||||
|
||||
Assert.IsTrue(newPath.Equals(path), "Should be equal."); |
||||
} |
||||
|
||||
[Test] |
||||
public void NotEqual() |
||||
{ |
||||
XmlElementPath newPath = new XmlElementPath(); |
||||
newPath.Elements.Add(new QualifiedName("Foo", "bar")); |
||||
|
||||
Assert.IsFalse(newPath.Equals(path), "Should not be equal."); |
||||
} |
||||
|
||||
[Test] |
||||
public void Compact() |
||||
{ |
||||
path.Compact(); |
||||
Equality(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,81 @@
@@ -0,0 +1,81 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
|
||||
namespace XmlEditor.Tests.Paths |
||||
{ |
||||
[TestFixture] |
||||
public class SingleElementPathTestFixture |
||||
{ |
||||
XmlElementPath path; |
||||
QualifiedName qualifiedName; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
path = new XmlElementPath(); |
||||
qualifiedName = new QualifiedName("foo", "http://foo"); |
||||
path.Elements.Add(qualifiedName); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasOneItem() |
||||
{ |
||||
Assert.AreEqual(1, path.Elements.Count, |
||||
"Should have 1 element."); |
||||
} |
||||
|
||||
[Test] |
||||
public void RemoveLastItem() |
||||
{ |
||||
path.Elements.RemoveLast(); |
||||
Assert.AreEqual(0, path.Elements.Count, "Should have no items."); |
||||
} |
||||
|
||||
[Test] |
||||
public void Equality() |
||||
{ |
||||
XmlElementPath newPath = new XmlElementPath(); |
||||
newPath.Elements.Add(new QualifiedName("foo", "http://foo")); |
||||
|
||||
Assert.IsTrue(newPath.Equals(path), "Should be equal."); |
||||
} |
||||
|
||||
[Test] |
||||
public void NotEqual() |
||||
{ |
||||
XmlElementPath newPath = new XmlElementPath(); |
||||
newPath.Elements.Add(new QualifiedName("Foo", "bar")); |
||||
|
||||
Assert.IsFalse(newPath.Equals(path), "Should not be equal."); |
||||
} |
||||
|
||||
[Test] |
||||
public void Compact() |
||||
{ |
||||
path.Compact(); |
||||
Equality(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,111 @@
@@ -0,0 +1,111 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
|
||||
namespace XmlEditor.Tests.Paths |
||||
{ |
||||
[TestFixture] |
||||
public class TwoElementPathTestFixture |
||||
{ |
||||
XmlElementPath path; |
||||
QualifiedName firstQualifiedName; |
||||
QualifiedName secondQualifiedName; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
path = new XmlElementPath(); |
||||
firstQualifiedName = new QualifiedName("foo", "http://foo", "f"); |
||||
path.Elements.Add(firstQualifiedName); |
||||
|
||||
secondQualifiedName = new QualifiedName("bar", "http://bar", "b"); |
||||
path.Elements.Add(secondQualifiedName); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasTwoItems() |
||||
{ |
||||
Assert.AreEqual(2, path.Elements.Count, |
||||
"Should have 2 elements."); |
||||
} |
||||
|
||||
[Test] |
||||
public void RemoveLastItem() |
||||
{ |
||||
path.Elements.RemoveLast(); |
||||
Assert.AreEqual(firstQualifiedName, path.Elements[0], |
||||
"Wrong item removed."); |
||||
} |
||||
|
||||
[Test] |
||||
public void LastPrefix() |
||||
{ |
||||
Assert.AreEqual("b", path.Elements.LastPrefix, "Incorrect last prefix."); |
||||
} |
||||
|
||||
[Test] |
||||
public void LastPrefixAfterLastItemRemoved() |
||||
{ |
||||
path.Elements.RemoveLast(); |
||||
Assert.AreEqual("f", path.Elements.LastPrefix, "Incorrect last prefix."); |
||||
} |
||||
|
||||
[Test] |
||||
public void Equality() |
||||
{ |
||||
XmlElementPath newPath = new XmlElementPath(); |
||||
newPath.Elements.Add(new QualifiedName("foo", "http://foo", "f")); |
||||
newPath.Elements.Add(new QualifiedName("bar", "http://bar", "b")); |
||||
|
||||
Assert.IsTrue(newPath.Equals(path), "Should be equal."); |
||||
} |
||||
|
||||
[Test] |
||||
public void NotEqual() |
||||
{ |
||||
XmlElementPath newPath = new XmlElementPath(); |
||||
newPath.Elements.Add(new QualifiedName("aaa", "a", "a")); |
||||
newPath.Elements.Add(new QualifiedName("bbb", "b", "b")); |
||||
|
||||
Assert.IsFalse(newPath.Equals(path), "Should not be equal."); |
||||
} |
||||
|
||||
[Test] |
||||
public void CompactedPathItemCount() |
||||
{ |
||||
path.Compact(); |
||||
Assert.AreEqual(1, path.Elements.Count, "Should only be one item."); |
||||
} |
||||
|
||||
[Test] |
||||
public void CompactPathItem() |
||||
{ |
||||
XmlElementPath newPath = new XmlElementPath(); |
||||
newPath.Elements.Add(new QualifiedName("bar", "http://bar", "b")); |
||||
|
||||
path.Compact(); |
||||
Assert.IsTrue(newPath.Equals(path), "Should be equal."); |
||||
} |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,95 @@
@@ -0,0 +1,95 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
using System.Xml; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that the completion data retrieves the annotation documentation
|
||||
/// that an attribute may have.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class AttributeAnnotationTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
ICompletionData[] fooAttributeCompletionData; |
||||
ICompletionData[] barAttributeCompletionData; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
StringReader reader = new StringReader(GetSchema()); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
|
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("foo", "http://foo.com")); |
||||
|
||||
fooAttributeCompletionData = schemaCompletionData.GetAttributeCompletionData(path); |
||||
|
||||
path.Elements.Add(new QualifiedName("bar", "http://foo.com")); |
||||
barAttributeCompletionData = schemaCompletionData.GetAttributeCompletionData(path); |
||||
} |
||||
|
||||
[Test] |
||||
public void FooAttributeDocumentation() |
||||
{ |
||||
Assert.AreEqual("Documentation for foo attribute.", fooAttributeCompletionData[0].Description); |
||||
} |
||||
|
||||
[Test] |
||||
public void BarAttributeDocumentation() |
||||
{ |
||||
Assert.AreEqual("Documentation for bar attribute.", barAttributeCompletionData[0].Description); |
||||
} |
||||
|
||||
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:complexType>\r\n" + |
||||
"\t\t\t<xs:sequence>\t\r\n" + |
||||
"\t\t\t\t<xs:element name=\"bar\" type=\"bar\">\r\n" + |
||||
"\t\t\t</xs:element>\r\n" + |
||||
"\t\t\t</xs:sequence>\r\n" + |
||||
"\t\t\t<xs:attribute name=\"id\">\r\n" + |
||||
"\t\t\t\t\t<xs:annotation>\r\n" + |
||||
"\t\t\t\t\t\t<xs:documentation>Documentation for foo attribute.</xs:documentation>\r\n" + |
||||
"\t\t\t\t</xs:annotation>\t\r\n" + |
||||
"\t\t\t</xs:attribute>\t\r\n" + |
||||
"\t\t</xs:complexType>\r\n" + |
||||
"\t</xs:element>\r\n" + |
||||
"\t<xs:complexType name=\"bar\">\r\n" + |
||||
"\t\t<xs:attribute name=\"name\">\r\n" + |
||||
"\t\t\t<xs:annotation>\r\n" + |
||||
"\t\t\t\t<xs:documentation>Documentation for bar attribute.</xs:documentation>\r\n" + |
||||
"\t\t\t</xs:annotation>\t\r\n" + |
||||
"\t\t</xs:attribute>\t\r\n" + |
||||
"\t</xs:complexType>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,101 @@
@@ -0,0 +1,101 @@
|
||||
//
|
||||
// ${App.Name}
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Element that uses an attribute group ref.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class AttributeGroupRefTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
ICompletionData[] attributeCompletionData; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
StringReader reader = new StringReader(GetSchema()); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
|
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); |
||||
attributeCompletionData = schemaCompletionData.GetAttributeCompletionData(path); |
||||
} |
||||
|
||||
[Test] |
||||
public void AttributeCount() |
||||
{ |
||||
Assert.AreEqual(4, attributeCompletionData.Length, "Should be 4 attributes."); |
||||
} |
||||
|
||||
[Test] |
||||
public void NameAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(attributeCompletionData, "name"), |
||||
"Attribute name does not exist."); |
||||
} |
||||
|
||||
[Test] |
||||
public void IdAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(attributeCompletionData, "id"), |
||||
"Attribute id does not exist."); |
||||
} |
||||
|
||||
[Test] |
||||
public void StyleAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(attributeCompletionData, "style"), |
||||
"Attribute style does not exist."); |
||||
} |
||||
|
||||
[Test] |
||||
public void TitleAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(attributeCompletionData, "title"), |
||||
"Attribute title does not exist."); |
||||
} |
||||
|
||||
string GetSchema() |
||||
{ |
||||
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://www.w3schools.com\" xmlns=\"http://www.w3schools.com\" elementFormDefault=\"qualified\">\r\n" + |
||||
"<xs:attributeGroup name=\"coreattrs\">" + |
||||
"\t<xs:attribute name=\"id\" type=\"xs:string\"/>" + |
||||
"\t<xs:attribute name=\"style\" type=\"xs:string\"/>" + |
||||
"\t<xs:attribute name=\"title\" type=\"xs:string\"/>" + |
||||
"</xs:attributeGroup>" + |
||||
"\t<xs:element name=\"note\">\r\n" + |
||||
"\t\t<xs:complexType>\r\n" + |
||||
"\t\t\t<xs:attributeGroup ref=\"coreattrs\"/>" + |
||||
"\t\t\t<xs:attribute name=\"name\" type=\"xs:string\"/>\r\n" + |
||||
"\t\t</xs:complexType>\r\n" + |
||||
"\t</xs:element>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,125 @@
@@ -0,0 +1,125 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Tests attribute refs
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class AttributeRefTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
ICompletionData[] attributes; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
StringReader reader = new StringReader(GetSchema()); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("html", "http://foo/xhtml")); |
||||
attributes = schemaCompletionData.GetAttributeCompletionData(path); |
||||
} |
||||
|
||||
[Test] |
||||
public void HtmlAttributeCount() |
||||
{ |
||||
Assert.AreEqual(4, attributes.Length, |
||||
"Should be 4 attributes."); |
||||
} |
||||
|
||||
[Test] |
||||
public void HtmlLangAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(attributes, "lang"), "Attribute lang not found."); |
||||
} |
||||
|
||||
[Test] |
||||
public void HtmlIdAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(attributes, "id"), "Attribute id not found."); |
||||
} |
||||
|
||||
[Test] |
||||
public void HtmlDirAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(attributes, "dir"), "Attribute dir not found."); |
||||
} |
||||
|
||||
[Test] |
||||
public void HtmlXmlLangAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(attributes, "xml:lang"), "Attribute xml:lang not found."); |
||||
} |
||||
|
||||
string GetSchema() |
||||
{ |
||||
return "<xs:schema version=\"1.0\" xml:lang=\"en\"\r\n" + |
||||
" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\r\n" + |
||||
" targetNamespace=\"http://foo/xhtml\"\r\n" + |
||||
" xmlns=\"http://foo/xhtml\"\r\n" + |
||||
" elementFormDefault=\"qualified\">\r\n" + |
||||
" <xs:element name=\"html\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:sequence>\r\n" + |
||||
" <xs:element ref=\"head\"/>\r\n" + |
||||
" <xs:element ref=\"body\"/>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" <xs:attributeGroup ref=\"i18n\"/>\r\n" + |
||||
" <xs:attribute name=\"id\" type=\"xs:ID\"/>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
" </xs:element>\r\n" + |
||||
"\r\n" + |
||||
" <xs:element name=\"head\" type=\"xs:string\"/>\r\n" + |
||||
" <xs:element name=\"body\" type=\"xs:string\"/>\r\n" + |
||||
"\r\n" + |
||||
" <xs:attributeGroup name=\"i18n\">\r\n" + |
||||
" <xs:annotation>\r\n" + |
||||
" <xs:documentation>\r\n" + |
||||
" internationalization attributes\r\n" + |
||||
" lang language code (backwards compatible)\r\n" + |
||||
" xml:lang language code (as per XML 1.0 spec)\r\n" + |
||||
" dir direction for weak/neutral text\r\n" + |
||||
" </xs:documentation>\r\n" + |
||||
" </xs:annotation>\r\n" + |
||||
" <xs:attribute name=\"lang\" type=\"LanguageCode\"/>\r\n" + |
||||
" <xs:attribute ref=\"xml:lang\"/>\r\n" + |
||||
"\r\n" + |
||||
" <xs:attribute name=\"dir\">\r\n" + |
||||
" <xs:simpleType>\r\n" + |
||||
" <xs:restriction base=\"xs:token\">\r\n" + |
||||
" <xs:enumeration value=\"ltr\"/>\r\n" + |
||||
" <xs:enumeration value=\"rtl\"/>\r\n" + |
||||
" </xs:restriction>\r\n" + |
||||
" </xs:simpleType>\r\n" + |
||||
" </xs:attribute>\r\n" + |
||||
" </xs:attributeGroup>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,92 @@
@@ -0,0 +1,92 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
using System.Xml; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that the completion data retrieves the annotation documentation
|
||||
/// that an attribute value may have.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class AttributeValueAnnotationTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
ICompletionData[] barAttributeValuesCompletionData; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
StringReader reader = new StringReader(GetSchema()); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
|
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("foo", "http://foo.com")); |
||||
barAttributeValuesCompletionData = schemaCompletionData.GetAttributeValueCompletionData(path, "bar"); |
||||
} |
||||
|
||||
[Test] |
||||
public void BarAttributeValueDefaultDocumentation() |
||||
{ |
||||
Assert.IsTrue(base.ContainsDescription(barAttributeValuesCompletionData, "default", "Default attribute value info."), |
||||
"Description for attribute value 'default' is incorrect."); |
||||
} |
||||
|
||||
string GetSchema() |
||||
{ |
||||
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\r\n" + |
||||
"\ttargetNamespace=\"http://foo.com\"\r\n" + |
||||
"\txmlns=\"http://foo.com\">\r\n" + |
||||
"\t<xs:element name=\"foo\">\r\n" + |
||||
"\t\t<xs:complexType>\r\n" + |
||||
"\t\t\t<xs:attribute name=\"bar\">\r\n" + |
||||
"\t\t\t\t<xs:simpleType>\r\n" + |
||||
"\t\t\t\t\t<xs:restriction base=\"xs:NMTOKEN\">\r\n" + |
||||
"\t\t\t\t\t\t<xs:enumeration value=\"default\">\r\n" + |
||||
"\t\t\t\t\t\t\t<xs:annotation><xs:documentation>Default attribute value info.</xs:documentation></xs:annotation>\r\n" + |
||||
"\t\t\t\t\t\t</xs:enumeration>\r\n" + |
||||
"\t\t\t\t\t\t<xs:enumeration value=\"enable\">\r\n" + |
||||
"\t\t\t\t\t\t\t<xs:annotation><xs:documentation>Enable attribute value info.</xs:documentation></xs:annotation>\r\n" + |
||||
"\t\t\t\t\t\t</xs:enumeration>\r\n" + |
||||
"\t\t\t\t\t\t<xs:enumeration value=\"disable\">\r\n" + |
||||
"\t\t\t\t\t\t\t<xs:annotation><xs:documentation>Disable attribute value info.</xs:documentation></xs:annotation>\r\n" + |
||||
"\t\t\t\t\t\t</xs:enumeration>\r\n" + |
||||
"\t\t\t\t\t\t<xs:enumeration value=\"hide\">\r\n" + |
||||
"\t\t\t\t\t\t\t<xs:annotation><xs:documentation>Hide attribute value info.</xs:documentation></xs:annotation>\r\n" + |
||||
"\t\t\t\t\t\t</xs:enumeration>\r\n" + |
||||
"\t\t\t\t\t\t<xs:enumeration value=\"show\">\r\n" + |
||||
"\t\t\t\t\t\t\t<xs:annotation><xs:documentation>Show attribute value info.</xs:documentation></xs:annotation>\r\n" + |
||||
"\t\t\t\t\t\t</xs:enumeration>\r\n" + |
||||
"\t\t\t\t\t</xs:restriction>\r\n" + |
||||
"\t\t\t\t</xs:simpleType>\r\n" + |
||||
"\t\t\t</xs:attribute>\r\n" + |
||||
"\t\t</xs:complexType>\r\n" + |
||||
"\t</xs:element>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,98 @@
@@ -0,0 +1,98 @@
|
||||
//
|
||||
// ${App.Name}
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Child element attributes.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class ChildElementAttributesTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
ICompletionData[] attributes; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
StringReader reader = new StringReader(GetSchema()); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
|
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("project", "http://nant.sf.net//nant-0.84.xsd")); |
||||
path.Elements.Add(new QualifiedName("attrib", "http://nant.sf.net//nant-0.84.xsd")); |
||||
|
||||
attributes = schemaCompletionData.GetAttributeCompletionData(path); |
||||
} |
||||
|
||||
[Test] |
||||
public void AttributeCount() |
||||
{ |
||||
Assert.AreEqual(10, attributes.Length, "Should be one attribute."); |
||||
} |
||||
|
||||
[Test] |
||||
public void FileAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(attributes, "file"), |
||||
"Attribute file does not exist."); |
||||
} |
||||
|
||||
string GetSchema() |
||||
{ |
||||
return "<xs:schema xmlns:vs=\"urn:schemas-microsoft-com:HTML-Intellisense\" xmlns:nant=\"http://nant.sf.net//nant-0.84.xsd\" targetNamespace=\"http://nant.sf.net//nant-0.84.xsd\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\r\n" + |
||||
" <xs:element name=\"project\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:sequence minOccurs=\"0\" maxOccurs=\"unbounded\">\r\n" + |
||||
" <xs:sequence minOccurs=\"0\" maxOccurs=\"unbounded\">\r\n" + |
||||
" <xs:sequence minOccurs=\"0\" maxOccurs=\"unbounded\">\r\n" + |
||||
" <xs:element name=\"attrib\" type=\"nant:attrib\" />\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" <xs:attribute name=\"name\" use=\"required\" />\r\n" + |
||||
" <xs:attribute name=\"default\" use=\"optional\" />\r\n" + |
||||
" <xs:attribute name=\"basedir\" use=\"optional\" />\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
" </xs:element>\r\n" + |
||||
"\r\n" + |
||||
" <xs:complexType id=\"NAnt.Core.Tasks.AttribTask\" name=\"attrib\">\r\n" + |
||||
" <xs:attribute name=\"file\" use=\"optional\" />\r\n" + |
||||
" <xs:attribute name=\"archive\" use=\"optional\" />\r\n" + |
||||
" <xs:attribute name=\"hidden\" use=\"optional\" />\r\n" + |
||||
" <xs:attribute name=\"normal\" use=\"optional\" />\r\n" + |
||||
" <xs:attribute name=\"readonly\" use=\"optional\" />\r\n" + |
||||
" <xs:attribute name=\"system\" use=\"optional\" />\r\n" + |
||||
" <xs:attribute name=\"failonerror\" use=\"optional\" />\r\n" + |
||||
" <xs:attribute name=\"verbose\" use=\"optional\" />\r\n" + |
||||
" <xs:attribute name=\"if\" use=\"optional\" />\r\n" + |
||||
" <xs:attribute name=\"unless\" use=\"optional\" />\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,107 @@
@@ -0,0 +1,107 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that nested schema choice elements are handled.
|
||||
/// This happens in the NAnt schema 0.85.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class ChoiceTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
ICompletionData[] noteChildElements; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
StringReader reader = new StringReader(GetSchema()); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
|
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); |
||||
|
||||
noteChildElements = schemaCompletionData.GetChildElementCompletionData(path); |
||||
} |
||||
|
||||
[Test] |
||||
public void TitleHasNoChildElements() |
||||
{ |
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); |
||||
path.Elements.Add(new QualifiedName("title", "http://www.w3schools.com")); |
||||
Assert.AreEqual(0, schemaCompletionData.GetChildElementCompletionData(path).Length, |
||||
"Should be no child elements."); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextHasNoChildElements() |
||||
{ |
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); |
||||
path.Elements.Add(new QualifiedName("text", "http://www.w3schools.com")); |
||||
Assert.AreEqual(0, schemaCompletionData.GetChildElementCompletionData(path).Length, |
||||
"Should be no child elements."); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoteHasTwoChildElements() |
||||
{ |
||||
Assert.AreEqual(2, noteChildElements.Length, |
||||
"Should be two child elements."); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoteChildElementIsText() |
||||
{ |
||||
Assert.IsTrue(base.Contains(noteChildElements, "text"), |
||||
"Should have a child element called text."); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoteChildElementIsTitle() |
||||
{ |
||||
Assert.IsTrue(base.Contains(noteChildElements, "title"), |
||||
"Should have a child element called title."); |
||||
} |
||||
|
||||
string GetSchema() |
||||
{ |
||||
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://www.w3schools.com\" xmlns=\"http://www.w3schools.com\" elementFormDefault=\"qualified\">\r\n" + |
||||
"\t<xs:element name=\"note\">\r\n" + |
||||
"\t\t<xs:complexType> \r\n" + |
||||
"\t\t\t<xs:choice>\r\n" + |
||||
"\t\t\t\t<xs:element name=\"title\" type=\"xs:string\"/>\r\n" + |
||||
"\t\t\t\t<xs:element name=\"text\" type=\"xs:string\"/>\r\n" + |
||||
"\t\t\t</xs:choice>\r\n" + |
||||
"\t\t</xs:complexType>\r\n" + |
||||
"\t</xs:element>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,131 @@
@@ -0,0 +1,131 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Tests complex content extension elements.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class ComplexContentExtensionTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
ICompletionData[] bodyChildElements; |
||||
ICompletionData[] bodyAttributes; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
StringReader reader = new StringReader(GetSchema()); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
|
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("body", "http://www.w3schools.com")); |
||||
|
||||
bodyChildElements = schemaCompletionData.GetChildElementCompletionData(path); |
||||
bodyAttributes = schemaCompletionData.GetAttributeCompletionData(path); |
||||
} |
||||
|
||||
[Test] |
||||
public void TitleHasNoChildElements() |
||||
{ |
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("body", "http://www.w3schools.com")); |
||||
path.Elements.Add(new QualifiedName("title", "http://www.w3schools.com")); |
||||
|
||||
Assert.AreEqual(0, schemaCompletionData.GetChildElementCompletionData(path).Length, |
||||
"Should be no child elements."); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextHasNoChildElements() |
||||
{ |
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("body", "http://www.w3schools.com")); |
||||
path.Elements.Add(new QualifiedName("text", "http://www.w3schools.com")); |
||||
|
||||
Assert.AreEqual(0, schemaCompletionData.GetChildElementCompletionData(path).Length, |
||||
"Should be no child elements."); |
||||
} |
||||
|
||||
[Test] |
||||
public void BodyHasTwoChildElements() |
||||
{ |
||||
Assert.AreEqual(2, bodyChildElements.Length, |
||||
"Should be two child elements."); |
||||
} |
||||
|
||||
[Test] |
||||
public void BodyChildElementIsText() |
||||
{ |
||||
Assert.IsTrue(base.Contains(bodyChildElements, "text"), |
||||
"Should have a child element called text."); |
||||
} |
||||
|
||||
[Test] |
||||
public void BodyChildElementIsTitle() |
||||
{ |
||||
Assert.IsTrue(base.Contains(bodyChildElements, "title"), |
||||
"Should have a child element called title."); |
||||
} |
||||
|
||||
[Test] |
||||
public void BodyAttributeCount() |
||||
{ |
||||
Assert.AreEqual(1, bodyAttributes.Length, |
||||
"Should be one attribute."); |
||||
} |
||||
|
||||
[Test] |
||||
public void BodyAttributeName() |
||||
{ |
||||
Assert.IsTrue(base.Contains(bodyAttributes, "id"), "Attribute id not found."); |
||||
} |
||||
|
||||
string GetSchema() |
||||
{ |
||||
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://www.w3schools.com\" xmlns=\"http://www.w3schools.com\" elementFormDefault=\"qualified\">\r\n" + |
||||
"\t<xs:complexType name=\"Block\">\r\n" + |
||||
"\t\t<xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\">\r\n" + |
||||
"\t\t\t<xs:element name=\"title\" type=\"xs:string\"/>\r\n" + |
||||
"\t\t\t<xs:element name=\"text\" type=\"xs:string\"/>\r\n" + |
||||
"\t\t</xs:choice>\r\n" + |
||||
"\t</xs:complexType>\r\n" + |
||||
"\r\n" + |
||||
"\t<xs:element name=\"body\">\r\n" + |
||||
"\t\t<xs:complexType>\r\n" + |
||||
"\t\t\t<xs:complexContent>\r\n" + |
||||
"\t\t\t\t<xs:extension base=\"Block\">\r\n" + |
||||
"\t\t\t\t\t<xs:attribute name=\"id\" type=\"xs:string\"/>\r\n" + |
||||
"\t\t\t\t</xs:extension>\r\n" + |
||||
"\t\t\t</xs:complexContent>\r\n" + |
||||
"\t\t</xs:complexType>\r\n" + |
||||
"\t</xs:element>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,97 @@
@@ -0,0 +1,97 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Tests duplicate elements in the schema.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class DuplicateElementTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
ICompletionData[] htmlChildElements; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
StringReader reader = new StringReader(GetSchema()); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
|
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("html", "http://foo/xhtml")); |
||||
|
||||
htmlChildElements = schemaCompletionData.GetChildElementCompletionData(path); |
||||
} |
||||
|
||||
[Test] |
||||
public void HtmlHasTwoChildElements() |
||||
{ |
||||
Assert.AreEqual(2, htmlChildElements.Length, |
||||
"Should be 2 child elements."); |
||||
} |
||||
|
||||
[Test] |
||||
public void HtmlChildElementHead() |
||||
{ |
||||
Assert.IsTrue(base.Contains(htmlChildElements, "head"), |
||||
"Should have a child element called head."); |
||||
} |
||||
|
||||
[Test] |
||||
public void HtmlChildElementBody() |
||||
{ |
||||
Assert.IsTrue(base.Contains(htmlChildElements, "body"), |
||||
"Should have a child element called body."); |
||||
} |
||||
|
||||
string GetSchema() |
||||
{ |
||||
return "<xs:schema version=\"1.0\" xml:lang=\"en\"\r\n" + |
||||
" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\r\n" + |
||||
" targetNamespace=\"http://foo/xhtml\"\r\n" + |
||||
" xmlns=\"http://foo/xhtml\"\r\n" + |
||||
" elementFormDefault=\"qualified\">\r\n" + |
||||
"\r\n" + |
||||
" <xs:element name=\"html\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:choice>\r\n" + |
||||
" <xs:sequence>\r\n" + |
||||
" <xs:element name=\"head\"/>\r\n" + |
||||
" <xs:element name=\"body\"/>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" <xs:sequence>\r\n" + |
||||
" <xs:element name=\"body\"/>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" </xs:choice>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
" </xs:element>\r\n" + |
||||
"\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,93 @@
@@ -0,0 +1,93 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
using System.Xml; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that the completion data retrieves the annotation documentation
|
||||
/// that an element may have.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class ElementAnnotationTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
ICompletionData[] fooChildElementCompletionData; |
||||
ICompletionData[] rootElementCompletionData; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
StringReader reader = new StringReader(GetSchema()); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
rootElementCompletionData = schemaCompletionData.GetElementCompletionData(); |
||||
|
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("foo", "http://foo.com")); |
||||
|
||||
fooChildElementCompletionData = schemaCompletionData.GetChildElementCompletionData(path); |
||||
} |
||||
|
||||
[Test] |
||||
public void RootElementDocumentation() |
||||
{ |
||||
Assert.AreEqual("Documentation for foo element.", rootElementCompletionData[0].Description); |
||||
} |
||||
|
||||
[Test] |
||||
public void FooChildElementDocumentation() |
||||
{ |
||||
Assert.AreEqual("Documentation for bar element.", fooChildElementCompletionData[0].Description); |
||||
} |
||||
|
||||
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>Documentation for foo element.</xs:documentation>\r\n" + |
||||
"\t\t</xs:annotation>\r\n" + |
||||
"\t\t<xs:complexType>\r\n" + |
||||
"\t\t\t<xs:sequence>\t\r\n" + |
||||
"\t\t\t\t<xs:element name=\"bar\" type=\"bar\">\r\n" + |
||||
"\t\t\t\t\t<xs:annotation>\r\n" + |
||||
"\t\t\t\t\t\t<xs:documentation>Documentation for bar element.</xs:documentation>\r\n" + |
||||
"\t\t\t\t</xs:annotation>\t\r\n" + |
||||
"\t\t\t</xs:element>\r\n" + |
||||
"\t\t\t</xs:sequence>\r\n" + |
||||
"\t\t</xs:complexType>\r\n" + |
||||
"\t</xs:element>\r\n" + |
||||
"\t<xs:complexType name=\"bar\">\r\n" + |
||||
"\t\t<xs:annotation>\r\n" + |
||||
"\t\t\t<xs:documentation>Documentation for bar element.</xs:documentation>\r\n" + |
||||
"\t\t</xs:annotation>\t\r\n" + |
||||
"\t\t<xs:attribute name=\"id\"/>\r\n" + |
||||
"\t</xs:complexType>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,82 @@
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
using System.Xml; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that the completion data retrieves the annotation documentation
|
||||
/// that an element ref may have.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class ElementRefAnnotationTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
ICompletionData[] fooChildElementCompletionData; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
StringReader reader = new StringReader(GetSchema()); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
|
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("foo", "http://foo.com")); |
||||
|
||||
fooChildElementCompletionData = schemaCompletionData.GetChildElementCompletionData(path); |
||||
} |
||||
|
||||
[Test] |
||||
public void BarElementDocumentation() |
||||
{ |
||||
Assert.IsTrue(base.ContainsDescription(fooChildElementCompletionData, "bar", "Documentation for bar element."), |
||||
"Missing documentation for bar element"); |
||||
} |
||||
|
||||
string GetSchema() |
||||
{ |
||||
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://foo.com\" xmlns=\"http://foo.com\">\r\n" + |
||||
"\t<xs:element name=\"foo\">\r\n" + |
||||
"\t\t<xs:complexType>\r\n" + |
||||
"\t\t\t<xs:sequence>\r\n" + |
||||
"\t\t\t\t<xs:element ref=\"bar\"/>\r\n" + |
||||
"\t\t\t</xs:sequence>\r\n" + |
||||
"\t\t</xs:complexType>\r\n" + |
||||
"\t</xs:element>\r\n" + |
||||
"\r\n" + |
||||
"\t<xs:element name=\"bar\">\r\n" + |
||||
"\t\t<xs:annotation>\r\n" + |
||||
"\t\t\t<xs:documentation>Documentation for bar element.</xs:documentation>\r\n" + |
||||
"\t\t</xs:annotation>\r\n" + |
||||
"\t\t<xs:complexType>\r\n" + |
||||
"\t\t\t<xs:attribute name=\"id\"/>\r\n" + |
||||
"\t\t</xs:complexType>\r\n" + |
||||
"\t</xs:element>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,86 @@
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Element that has a single attribute.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class ElementWithAttributeSchemaTestFixture |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
ICompletionData[] attributeCompletionData; |
||||
string attributeName; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
StringReader reader = new StringReader(GetSchema()); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
|
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); |
||||
|
||||
attributeCompletionData = schemaCompletionData.GetAttributeCompletionData(path); |
||||
attributeName = attributeCompletionData[0].Text; |
||||
} |
||||
|
||||
[Test] |
||||
public void AttributeCount() |
||||
{ |
||||
Assert.AreEqual(1, attributeCompletionData.Length, "Should be one attribute."); |
||||
} |
||||
|
||||
[Test] |
||||
public void AttributeName() |
||||
{ |
||||
Assert.AreEqual("name", attributeName, "Attribute name is incorrect."); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoAttributesForUnknownElement() |
||||
{ |
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("foobar", "http://www.w3schools.com")); |
||||
ICompletionData[] attributes = schemaCompletionData.GetAttributeCompletionData(path); |
||||
|
||||
Assert.AreEqual(0, attributes.Length, "Should not find attributes for unknown element."); |
||||
} |
||||
|
||||
string GetSchema() |
||||
{ |
||||
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://www.w3schools.com\" xmlns=\"http://www.w3schools.com\" elementFormDefault=\"qualified\">\r\n" + |
||||
" <xs:element name=\"note\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
"\t<xs:attribute name=\"name\" type=\"xs:string\"/>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
" </xs:element>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,87 @@
@@ -0,0 +1,87 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Tests attribute refs
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class EnumAttributeValueTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
ICompletionData[] attributeValues; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
StringReader reader = new StringReader(GetSchema()); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("foo", "http://foo.com")); |
||||
attributeValues = schemaCompletionData.GetAttributeValueCompletionData(path, "id"); |
||||
} |
||||
|
||||
[Test] |
||||
public void IdAttributeHasValueOne() |
||||
{ |
||||
Assert.IsTrue(base.Contains(attributeValues, "one"), |
||||
"Missing attribute value 'one'"); |
||||
} |
||||
|
||||
[Test] |
||||
public void IdAttributeHasValueTwo() |
||||
{ |
||||
Assert.IsTrue(base.Contains(attributeValues, "two"), |
||||
"Missing attribute value 'two'"); |
||||
} |
||||
|
||||
[Test] |
||||
public void IdAttributeValueCount() |
||||
{ |
||||
Assert.AreEqual(2, attributeValues.Length, "Expecting 2 attribute values."); |
||||
} |
||||
|
||||
string GetSchema() |
||||
{ |
||||
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://foo.com\" targetNamespace=\"http://foo.com\" elementFormDefault=\"qualified\">\r\n" + |
||||
"\t<xs:element name=\"foo\">\r\n" + |
||||
"\t\t<xs:complexType>\r\n" + |
||||
"\t\t\t<xs:attribute name=\"id\">\r\n" + |
||||
"\t\t\t\t<xs:simpleType>\r\n" + |
||||
"\t\t\t\t\t<xs:restriction base=\"xs:string\">\r\n" + |
||||
"\t\t\t\t\t\t<xs:enumeration value=\"one\"/>\r\n" + |
||||
"\t\t\t\t\t\t<xs:enumeration value=\"two\"/>\r\n" + |
||||
"\t\t\t\t\t</xs:restriction>\r\n" + |
||||
"\t\t\t\t</xs:simpleType>\r\n" + |
||||
"\t\t\t</xs:attribute>\r\n" + |
||||
"\t\t</xs:complexType>\r\n" + |
||||
"\t</xs:element>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,282 @@
@@ -0,0 +1,282 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Tests complex content extension elements.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class ExtensionElementTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
ICompletionData[] schemaChildElements; |
||||
ICompletionData[] annotationChildElements; |
||||
ICompletionData[] annotationAttributes; |
||||
ICompletionData[] includeAttributes; |
||||
ICompletionData[] appInfoAttributes; |
||||
ICompletionData[] schemaAttributes; |
||||
ICompletionData[] fooAttributes; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
StringReader reader = new StringReader(GetSchema()); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("schema", "http://www.w3.org/2001/XMLSchema")); |
||||
|
||||
schemaChildElements = schemaCompletionData.GetChildElementCompletionData(path); |
||||
schemaAttributes = schemaCompletionData.GetAttributeCompletionData(path); |
||||
|
||||
// Get include elements attributes.
|
||||
path.Elements.Add(new QualifiedName("include", "http://www.w3.org/2001/XMLSchema")); |
||||
includeAttributes = schemaCompletionData.GetAttributeCompletionData(path); |
||||
|
||||
// Get annotation element info.
|
||||
path.Elements.RemoveLast(); |
||||
path.Elements.Add(new QualifiedName("annotation", "http://www.w3.org/2001/XMLSchema")); |
||||
|
||||
annotationChildElements = schemaCompletionData.GetChildElementCompletionData(path); |
||||
annotationAttributes = schemaCompletionData.GetAttributeCompletionData(path); |
||||
|
||||
// Get app info attributes.
|
||||
path.Elements.Add(new QualifiedName("appinfo", "http://www.w3.org/2001/XMLSchema")); |
||||
appInfoAttributes = schemaCompletionData.GetAttributeCompletionData(path); |
||||
|
||||
// Get foo attributes.
|
||||
path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("foo", "http://www.w3.org/2001/XMLSchema")); |
||||
fooAttributes = schemaCompletionData.GetAttributeCompletionData(path); |
||||
} |
||||
|
||||
[Test] |
||||
public void SchemaHasSevenChildElements() |
||||
{ |
||||
Assert.AreEqual(7, schemaChildElements.Length, |
||||
"Should be 7 child elements."); |
||||
} |
||||
|
||||
[Test] |
||||
public void SchemaChildElementIsInclude() |
||||
{ |
||||
Assert.IsTrue(base.Contains(schemaChildElements, "include"), |
||||
"Should have a child element called include."); |
||||
} |
||||
|
||||
[Test] |
||||
public void SchemaChildElementIsImport() |
||||
{ |
||||
Assert.IsTrue(base.Contains(schemaChildElements, "import"), |
||||
"Should have a child element called import."); |
||||
} |
||||
|
||||
[Test] |
||||
public void SchemaChildElementIsNotation() |
||||
{ |
||||
Assert.IsTrue(base.Contains(schemaChildElements, "notation"), |
||||
"Should have a child element called notation."); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that the extended element has the base type's attributes.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void FooHasClassAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(fooAttributes, "class"), |
||||
"Should have an attribute called class."); |
||||
} |
||||
|
||||
[Test] |
||||
public void AnnotationElementHasOneAttribute() |
||||
{ |
||||
Assert.AreEqual(1, annotationAttributes.Length, "Should be one attribute."); |
||||
} |
||||
|
||||
[Test] |
||||
public void AnnotationHasIdAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(annotationAttributes, "id"), |
||||
"Should have an attribute called id."); |
||||
} |
||||
|
||||
[Test] |
||||
public void AnnotationHasTwoChildElements() |
||||
{ |
||||
Assert.AreEqual(2, annotationChildElements.Length, |
||||
"Should be 2 child elements."); |
||||
} |
||||
|
||||
[Test] |
||||
public void AnnotationChildElementIsAppInfo() |
||||
{ |
||||
Assert.IsTrue(base.Contains(annotationChildElements, "appinfo"), |
||||
"Should have a child element called appinfo."); |
||||
} |
||||
|
||||
[Test] |
||||
public void AnnotationChildElementIsDocumentation() |
||||
{ |
||||
Assert.IsTrue(base.Contains(annotationChildElements, "documentation"), |
||||
"Should have a child element called documentation."); |
||||
} |
||||
|
||||
[Test] |
||||
public void IncludeElementHasOneAttribute() |
||||
{ |
||||
Assert.AreEqual(1, includeAttributes.Length, "Should be one attribute."); |
||||
} |
||||
|
||||
[Test] |
||||
public void IncludeHasSchemaLocationAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(includeAttributes, "schemaLocation"), |
||||
"Should have an attribute called schemaLocation."); |
||||
} |
||||
|
||||
[Test] |
||||
public void AppInfoElementHasOneAttribute() |
||||
{ |
||||
Assert.AreEqual(1, appInfoAttributes.Length, "Should be one attribute."); |
||||
} |
||||
|
||||
[Test] |
||||
public void AppInfoHasIdAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(appInfoAttributes, "id"), |
||||
"Should have an attribute called id."); |
||||
} |
||||
|
||||
string GetSchema() |
||||
{ |
||||
return "<xs:schema targetNamespace=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\" version=\"1.0\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xml:lang=\"EN\">\r\n" + |
||||
"\r\n" + |
||||
" <xs:element name=\"schema\" id=\"schema\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:complexContent>\r\n" + |
||||
" <xs:extension base=\"xs:openAttrs\">\r\n" + |
||||
" <xs:sequence>\r\n" + |
||||
" <xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\">\r\n" + |
||||
" <xs:element ref=\"xs:include\"/>\r\n" + |
||||
" <xs:element name=\"import\"/>\r\n" + |
||||
" <xs:element name=\"redefine\"/>\r\n" + |
||||
" <xs:element ref=\"xs:annotation\"/>\r\n" + |
||||
" </xs:choice>\r\n" + |
||||
" <xs:sequence minOccurs=\"0\" maxOccurs=\"unbounded\">\r\n" + |
||||
" <xs:group ref=\"xs:schemaTop\"/>\r\n" + |
||||
" <xs:element ref=\"xs:annotation\" minOccurs=\"0\" maxOccurs=\"unbounded\"/>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" <xs:attribute name=\"targetNamespace\" type=\"xs:anyURI\"/>\r\n" + |
||||
" <xs:attribute name=\"version\" type=\"xs:token\"/>\r\n" + |
||||
" <xs:attribute name=\"finalDefault\" type=\"xs:fullDerivationSet\" use=\"optional\" default=\"\"/>\r\n" + |
||||
" <xs:attribute name=\"blockDefault\" type=\"xs:blockSet\" use=\"optional\" default=\"\"/>\r\n" + |
||||
" <xs:attribute name=\"attributeFormDefault\" type=\"xs:formChoice\" use=\"optional\" default=\"unqualified\"/>\r\n" + |
||||
" <xs:attribute name=\"elementFormDefault\" type=\"xs:formChoice\" use=\"optional\" default=\"unqualified\"/>\r\n" + |
||||
" <xs:attribute name=\"id\" type=\"xs:ID\"/>\r\n" + |
||||
" <xs:attribute ref=\"xml:lang\"/>\r\n" + |
||||
" </xs:extension>\r\n" + |
||||
" </xs:complexContent>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
"\r\n" + |
||||
"\r\n" + |
||||
" </xs:element>\r\n" + |
||||
"\r\n" + |
||||
"<xs:complexType name=\"openAttrs\">\r\n" + |
||||
" <xs:complexContent>\r\n" + |
||||
" <xs:restriction base=\"xs:anyType\">\r\n" + |
||||
" <xs:anyAttribute namespace=\"##other\" processContents=\"lax\"/>\r\n" + |
||||
" </xs:restriction>\r\n" + |
||||
" </xs:complexContent>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
"\r\n" + |
||||
"<xs:complexType name=\"anyType\" mixed=\"true\">\r\n" + |
||||
" <xs:annotation>\r\n" + |
||||
" <xs:documentation>\r\n" + |
||||
" Not the real urType, but as close an approximation as we can\r\n" + |
||||
" get in the XML representation</xs:documentation>\r\n" + |
||||
" </xs:annotation>\r\n" + |
||||
" <xs:sequence>\r\n" + |
||||
" <xs:any minOccurs=\"0\" maxOccurs=\"unbounded\" processContents=\"lax\"/>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" <xs:anyAttribute processContents=\"lax\"/>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
"\r\n" + |
||||
"<xs:element name=\"include\" id=\"include\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:attribute name=\"schemaLocation\" type=\"xs:anyURI\" use=\"required\"/>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
" </xs:element>\r\n" + |
||||
"\r\n" + |
||||
"<xs:element name=\"annotation\" id=\"annotation\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:complexContent>\r\n" + |
||||
" <xs:extension base=\"xs:openAttrs\">\r\n" + |
||||
" <xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\">\r\n" + |
||||
" <xs:element ref=\"xs:appinfo\"/>\r\n" + |
||||
" <xs:element name=\"documentation\"/>\r\n" + |
||||
" </xs:choice>\r\n" + |
||||
" <xs:attribute name=\"id\" type=\"xs:ID\"/>\r\n" + |
||||
" </xs:extension>\r\n" + |
||||
" </xs:complexContent>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
" </xs:element>\r\n" + |
||||
"\r\n" + |
||||
" <xs:group name=\"schemaTop\">\r\n" + |
||||
" <xs:choice>\r\n" + |
||||
" <xs:element name=\"element\"/>\r\n" + |
||||
" <xs:element name=\"attribute\"/>\r\n" + |
||||
" <xs:element name=\"notation\"/>\r\n" + |
||||
" </xs:choice>\r\n" + |
||||
" </xs:group>\r\n" + |
||||
"\r\n" + |
||||
"\r\n" + |
||||
"<xs:element name=\"appinfo\" id=\"appinfo\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:attribute name=\"id\" type=\"xs:anyURI\" use=\"required\"/>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
" </xs:element>\r\n" + |
||||
"\r\n" + |
||||
"\r\n" + |
||||
" <xs:element name=\"foo\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:complexContent>\r\n" + |
||||
" <xs:extension base=\"xs:fooBase\">\r\n" + |
||||
" <xs:attribute name=\"id\" type=\"xs:ID\"/>\r\n" + |
||||
" </xs:extension>\r\n" + |
||||
" </xs:complexContent>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
" </xs:element>\r\n" + |
||||
"\r\n" + |
||||
"<xs:complexType name=\"fooBase\">\r\n" + |
||||
" <xs:attribute name=\"class\" type=\"xs:string\"/>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,109 @@
@@ -0,0 +1,109 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that autocompletion data is correct for an xml schema containing:
|
||||
/// <![CDATA[ <xs:element name="foo">
|
||||
/// <xs:group ref="myGroup"/>
|
||||
/// </xs:element>
|
||||
/// </]]>
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class GroupRefAsCompositorTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
ICompletionData[] rootChildElements; |
||||
ICompletionData[] fooAttributes; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
StringReader reader = new StringReader(GetSchema()); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
|
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("root", "http://foo")); |
||||
|
||||
rootChildElements = schemaCompletionData.GetChildElementCompletionData(path); |
||||
|
||||
path.Elements.Add(new QualifiedName("foo", "http://foo")); |
||||
|
||||
fooAttributes = schemaCompletionData.GetAttributeCompletionData(path); |
||||
} |
||||
|
||||
[Test] |
||||
public void RootHasTwoChildElements() |
||||
{ |
||||
Assert.AreEqual(2, rootChildElements.Length, |
||||
"Should be two child elements."); |
||||
} |
||||
|
||||
[Test] |
||||
public void RootChildElementIsFoo() |
||||
{ |
||||
Assert.IsTrue(base.Contains(rootChildElements, "foo"), |
||||
"Should have a child element called foo."); |
||||
} |
||||
|
||||
[Test] |
||||
public void RootChildElementIsBar() |
||||
{ |
||||
Assert.IsTrue(base.Contains(rootChildElements, "bar"), |
||||
"Should have a child element called bar."); |
||||
} |
||||
|
||||
[Test] |
||||
public void FooElementHasIdAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(fooAttributes, "id"), |
||||
"Should have an attribute called id."); |
||||
} |
||||
|
||||
string GetSchema() |
||||
{ |
||||
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://foo\" xmlns=\"http://foo\" elementFormDefault=\"qualified\">\r\n" + |
||||
"\t<xs:element name=\"root\">\r\n" + |
||||
"\t\t<xs:complexType>\r\n" + |
||||
"\t\t\t<xs:group ref=\"fooGroup\"/>\r\n" + |
||||
"\t\t</xs:complexType>\r\n" + |
||||
"\t</xs:element>\r\n" + |
||||
"\t<xs:group name=\"fooGroup\">\r\n" + |
||||
"\t\t<xs:choice>\r\n" + |
||||
"\t\t\t<xs:element name=\"foo\">\r\n" + |
||||
"\t\t\t\t<xs:complexType>\r\n" + |
||||
"\t\t\t\t\t<xs:attribute name=\"id\" type=\"xs:string\"/>\r\n" + |
||||
"\t\t\t\t</xs:complexType>\r\n" + |
||||
"\t\t\t</xs:element>\r\n" + |
||||
"\t\t\t<xs:element name=\"bar\" type=\"xs:string\"/>\r\n" + |
||||
"\t\t</xs:choice>\r\n" + |
||||
"\t</xs:group>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,149 @@
@@ -0,0 +1,149 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Tests element group refs
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class GroupRefTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
ICompletionData[] childElements; |
||||
ICompletionData[] paraAttributes; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
StringReader reader = new StringReader(GetSchema()); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
XmlElementPath path = new XmlElementPath(); |
||||
|
||||
path.Elements.Add(new QualifiedName("html", "http://foo/xhtml")); |
||||
path.Elements.Add(new QualifiedName("body", "http://foo/xhtml")); |
||||
|
||||
childElements = schemaCompletionData.GetChildElementCompletionData(path); |
||||
|
||||
path.Elements.Add(new QualifiedName("p", "http://foo/xhtml")); |
||||
paraAttributes = schemaCompletionData.GetAttributeCompletionData(path); |
||||
} |
||||
|
||||
[Test] |
||||
public void BodyHasFourChildElements() |
||||
{ |
||||
Assert.AreEqual(4, childElements.Length, |
||||
"Should be 4 child elements."); |
||||
} |
||||
|
||||
[Test] |
||||
public void BodyChildElementForm() |
||||
{ |
||||
Assert.IsTrue(base.Contains(childElements, "form"), |
||||
"Should have a child element called form."); |
||||
} |
||||
|
||||
[Test] |
||||
public void BodyChildElementPara() |
||||
{ |
||||
Assert.IsTrue(base.Contains(childElements, "p"), |
||||
"Should have a child element called p."); |
||||
} |
||||
|
||||
[Test] |
||||
public void BodyChildElementTest() |
||||
{ |
||||
Assert.IsTrue(base.Contains(childElements, "test"), |
||||
"Should have a child element called test."); |
||||
} |
||||
|
||||
[Test] |
||||
public void BodyChildElementId() |
||||
{ |
||||
Assert.IsTrue(base.Contains(childElements, "id"), |
||||
"Should have a child element called id."); |
||||
} |
||||
|
||||
[Test] |
||||
public void ParaElementHasIdAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(paraAttributes, "id"), |
||||
"Should have an attribute called id."); |
||||
} |
||||
|
||||
string GetSchema() |
||||
{ |
||||
return "<xs:schema version=\"1.0\" xml:lang=\"en\"\r\n" + |
||||
" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\r\n" + |
||||
" targetNamespace=\"http://foo/xhtml\"\r\n" + |
||||
" xmlns=\"http://foo/xhtml\"\r\n" + |
||||
" elementFormDefault=\"qualified\">\r\n" + |
||||
"\r\n" + |
||||
" <xs:element name=\"html\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:sequence>\r\n" + |
||||
" <xs:element ref=\"head\"/>\r\n" + |
||||
" <xs:element ref=\"body\"/>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
" </xs:element>\r\n" + |
||||
"\r\n" + |
||||
" <xs:element name=\"head\" type=\"xs:string\"/>\r\n" + |
||||
" <xs:element name=\"body\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:sequence>\r\n" + |
||||
" <xs:group ref=\"block\"/>\r\n" + |
||||
" <xs:element name=\"form\"/>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
" </xs:element>\r\n" + |
||||
"\r\n" + |
||||
"\r\n" + |
||||
" <xs:group name=\"block\">\r\n" + |
||||
" <xs:choice>\r\n" + |
||||
" <xs:element ref=\"p\"/>\r\n" + |
||||
" <xs:group ref=\"heading\"/>\r\n" + |
||||
" </xs:choice>\r\n" + |
||||
" </xs:group>\r\n" + |
||||
"\r\n" + |
||||
" <xs:element name=\"p\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:attribute name=\"id\"/>" + |
||||
" </xs:complexType>\r\n" + |
||||
" </xs:element>\r\n" + |
||||
"\r\n" + |
||||
" <xs:group name=\"heading\">\r\n" + |
||||
" <xs:choice>\r\n" + |
||||
" <xs:element name=\"test\"/>\r\n" + |
||||
" <xs:element name=\"id\"/>\r\n" + |
||||
" </xs:choice>\r\n" + |
||||
" </xs:group>\r\n" + |
||||
"\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,87 @@
@@ -0,0 +1,87 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// The collection of schemas should provide completion data for the
|
||||
/// namespaces it holds.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class NamespaceCompletionTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
ICompletionData[] namespaceCompletionData; |
||||
string firstNamespace = "http://foo.com/foo.xsd"; |
||||
string secondNamespace = "http://bar.com/bar.xsd"; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
XmlSchemaCompletionDataCollection items = new XmlSchemaCompletionDataCollection(); |
||||
|
||||
StringReader reader = new StringReader(GetSchema(firstNamespace)); |
||||
XmlSchemaCompletionData schema = new XmlSchemaCompletionData(reader); |
||||
items.Add(schema); |
||||
|
||||
reader = new StringReader(GetSchema(secondNamespace)); |
||||
schema = new XmlSchemaCompletionData(reader); |
||||
items.Add(schema); |
||||
namespaceCompletionData = items.GetNamespaceCompletionData(); |
||||
} |
||||
|
||||
[Test] |
||||
public void NamespaceCount() |
||||
{ |
||||
Assert.AreEqual(2, namespaceCompletionData.Length, |
||||
"Should be 2 namespaces."); |
||||
} |
||||
|
||||
[Test] |
||||
public void ContainsFirstNamespace() |
||||
{ |
||||
Assert.IsTrue(Contains(namespaceCompletionData, firstNamespace)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ContainsSecondNamespace() |
||||
{ |
||||
Assert.IsTrue(Contains(namespaceCompletionData, secondNamespace)); |
||||
} |
||||
|
||||
string GetSchema(string namespaceURI) |
||||
{ |
||||
return "<?xml version=\"1.0\"?>\r\n" + |
||||
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\r\n" + |
||||
"targetNamespace=\"" + namespaceURI + "\"\r\n" + |
||||
"xmlns=\"" + namespaceURI + "\"\r\n" + |
||||
"elementFormDefault=\"qualified\">\r\n" + |
||||
"<xs:element name=\"note\">\r\n" + |
||||
"</xs:element>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,128 @@
@@ -0,0 +1,128 @@
|
||||
//
|
||||
// ${App.Name}
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Element that uses an attribute group ref.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class NestedAttributeGroupRefTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
ICompletionData[] attributeCompletionData; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
StringReader reader = new StringReader(GetSchema()); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
|
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); |
||||
attributeCompletionData = schemaCompletionData.GetAttributeCompletionData(path); |
||||
} |
||||
|
||||
[Test] |
||||
public void AttributeCount() |
||||
{ |
||||
Assert.AreEqual(7, attributeCompletionData.Length, "Should be 7 attributes."); |
||||
} |
||||
|
||||
[Test] |
||||
public void NameAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(attributeCompletionData, "name"), |
||||
"Attribute name does not exist."); |
||||
} |
||||
|
||||
[Test] |
||||
public void IdAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(attributeCompletionData, "id"), |
||||
"Attribute id does not exist."); |
||||
} |
||||
|
||||
[Test] |
||||
public void StyleAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(attributeCompletionData, "style"), |
||||
"Attribute style does not exist."); |
||||
} |
||||
|
||||
[Test] |
||||
public void TitleAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(attributeCompletionData, "title"), |
||||
"Attribute title does not exist."); |
||||
} |
||||
|
||||
[Test] |
||||
public void BaseIdAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(attributeCompletionData, "baseid"), |
||||
"Attribute baseid does not exist."); |
||||
} |
||||
|
||||
[Test] |
||||
public void BaseStyleAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(attributeCompletionData, "basestyle"), |
||||
"Attribute basestyle does not exist."); |
||||
} |
||||
|
||||
[Test] |
||||
public void BaseTitleAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(attributeCompletionData, "basetitle"), |
||||
"Attribute basetitle does not exist."); |
||||
} |
||||
|
||||
string GetSchema() |
||||
{ |
||||
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://www.w3schools.com\" xmlns=\"http://www.w3schools.com\" elementFormDefault=\"qualified\">\r\n" + |
||||
"<xs:attributeGroup name=\"coreattrs\">" + |
||||
"\t<xs:attribute name=\"id\" type=\"xs:string\"/>" + |
||||
"\t<xs:attribute name=\"style\" type=\"xs:string\"/>" + |
||||
"\t<xs:attribute name=\"title\" type=\"xs:string\"/>" + |
||||
"\t<xs:attributeGroup ref=\"baseattrs\"/>" + |
||||
"</xs:attributeGroup>" + |
||||
"<xs:attributeGroup name=\"baseattrs\">" + |
||||
"\t<xs:attribute name=\"baseid\" type=\"xs:string\"/>" + |
||||
"\t<xs:attribute name=\"basestyle\" type=\"xs:string\"/>" + |
||||
"\t<xs:attribute name=\"basetitle\" type=\"xs:string\"/>" + |
||||
"</xs:attributeGroup>" + |
||||
"\t<xs:element name=\"note\">\r\n" + |
||||
"\t\t<xs:complexType>\r\n" + |
||||
"\t\t\t<xs:attributeGroup ref=\"coreattrs\"/>" + |
||||
"\t\t\t<xs:attribute name=\"name\" type=\"xs:string\"/>\r\n" + |
||||
"\t\t</xs:complexType>\r\n" + |
||||
"\t</xs:element>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,118 @@
@@ -0,0 +1,118 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that nested schema choice elements are handled.
|
||||
/// This happens in the NAnt schema 0.85.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class NestedChoiceTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
ICompletionData[] noteChildElements; |
||||
ICompletionData[] titleChildElements; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
StringReader reader = new StringReader(GetSchema()); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
|
||||
// Get note child elements.
|
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); |
||||
|
||||
noteChildElements = schemaCompletionData.GetChildElementCompletionData(path); |
||||
|
||||
// Get title child elements.
|
||||
path.Elements.Add(new QualifiedName("title", "http://www.w3schools.com")); |
||||
titleChildElements = schemaCompletionData.GetChildElementCompletionData(path); |
||||
} |
||||
|
||||
[Test] |
||||
public void TitleHasTwoChildElements() |
||||
{ |
||||
Assert.AreEqual(2, titleChildElements.Length, |
||||
"Should be 2 child elements."); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextHasNoChildElements() |
||||
{ |
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); |
||||
path.Elements.Add(new QualifiedName("text", "http://www.w3schools.com")); |
||||
Assert.AreEqual(0, schemaCompletionData.GetChildElementCompletionData(path).Length, |
||||
"Should be no child elements."); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoteHasTwoChildElements() |
||||
{ |
||||
Assert.AreEqual(2, noteChildElements.Length, |
||||
"Should be two child elements."); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoteChildElementIsText() |
||||
{ |
||||
Assert.IsTrue(base.Contains(noteChildElements, "text"), |
||||
"Should have a child element called text."); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoteChildElementIsTitle() |
||||
{ |
||||
Assert.IsTrue(base.Contains(noteChildElements, "title"), |
||||
"Should have a child element called title."); |
||||
} |
||||
|
||||
string GetSchema() |
||||
{ |
||||
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://www.w3schools.com\" xmlns=\"http://www.w3schools.com\" elementFormDefault=\"qualified\">\r\n" + |
||||
"\t<xs:element name=\"note\">\r\n" + |
||||
"\t\t<xs:complexType> \r\n" + |
||||
"\t\t\t<xs:choice>\r\n" + |
||||
"\t\t\t\t<xs:element ref=\"title\"/>\r\n" + |
||||
"\t\t\t\t<xs:element name=\"text\" type=\"xs:string\"/>\r\n" + |
||||
"\t\t\t</xs:choice>\r\n" + |
||||
"\t\t</xs:complexType>\r\n" + |
||||
"\t</xs:element>\r\n" + |
||||
"\t<xs:element name=\"title\">\r\n" + |
||||
"\t\t<xs:complexType> \r\n" + |
||||
"\t\t\t<xs:choice>\r\n" + |
||||
"\t\t\t\t<xs:element name=\"foo\" type=\"xs:string\"/>\r\n" + |
||||
"\t\t\t\t<xs:element name=\"bar\" type=\"xs:string\"/>\r\n" + |
||||
"\t\t\t</xs:choice>\r\n" + |
||||
"\t\t</xs:complexType>\r\n" + |
||||
"\t</xs:element>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,75 @@
@@ -0,0 +1,75 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
[TestFixture] |
||||
public class NestedElementSchemaTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
XmlElementPath noteElementPath; |
||||
ICompletionData[] elementData; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
StringReader reader = new StringReader(GetSchema()); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
|
||||
noteElementPath = new XmlElementPath(); |
||||
noteElementPath.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); |
||||
|
||||
elementData = schemaCompletionData.GetChildElementCompletionData(noteElementPath); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoteHasOneChildElementCompletionDataItem() |
||||
{ |
||||
Assert.AreEqual(1, elementData.Length, "Should be one child element completion data item."); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoteChildElementCompletionDataText() |
||||
{ |
||||
Assert.IsTrue(base.Contains(elementData, "text"), |
||||
"Should be one child element called text."); |
||||
} |
||||
|
||||
string GetSchema() |
||||
{ |
||||
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://www.w3schools.com\" xmlns=\"http://www.w3schools.com\" elementFormDefault=\"qualified\">\r\n" + |
||||
"\t<xs:element name=\"note\">\r\n" + |
||||
"\t\t<xs:complexType> \r\n" + |
||||
"\t\t\t<xs:sequence>\r\n" + |
||||
"\t\t\t\t<xs:element name=\"text\" type=\"xs:string\"/>\r\n" + |
||||
"\t\t\t</xs:sequence>\r\n" + |
||||
"\t\t</xs:complexType>\r\n" + |
||||
"\t</xs:element>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,110 @@
@@ -0,0 +1,110 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that nested schema sequence elements are handled. This
|
||||
/// happens in the NAnt schema 0.84.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class NestedSequenceSchemaTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
ICompletionData[] noteChildElements; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
StringReader reader = new StringReader(GetSchema()); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
|
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); |
||||
noteChildElements = schemaCompletionData.GetChildElementCompletionData(path); |
||||
} |
||||
|
||||
[Test] |
||||
public void TitleHasNoChildElements() |
||||
{ |
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); |
||||
path.Elements.Add(new QualifiedName("title", "http://www.w3schools.com")); |
||||
Assert.AreEqual(0, schemaCompletionData.GetChildElementCompletionData(path).Length, |
||||
"Should be no child elements."); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextHasNoChildElements() |
||||
{ |
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); |
||||
path.Elements.Add(new QualifiedName("text", "http://www.w3schools.com")); |
||||
Assert.AreEqual(0, schemaCompletionData.GetChildElementCompletionData(path).Length, |
||||
"Should be no child elements."); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoteHasTwoChildElements() |
||||
{ |
||||
Assert.AreEqual(2, noteChildElements.Length, |
||||
"Should be two child elements."); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoteChildElementIsText() |
||||
{ |
||||
Assert.IsTrue(base.Contains(noteChildElements, "text"), |
||||
"Should have a child element called text."); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoteChildElementIsTitle() |
||||
{ |
||||
Assert.IsTrue(base.Contains(noteChildElements, "title"), |
||||
"Should have a child element called title."); |
||||
} |
||||
|
||||
string GetSchema() |
||||
{ |
||||
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://www.w3schools.com\" xmlns=\"http://www.w3schools.com\" elementFormDefault=\"qualified\">\r\n" + |
||||
"\t<xs:element name=\"note\">\r\n" + |
||||
"\t\t<xs:complexType> \r\n" + |
||||
"\t\t\t<xs:sequence>\r\n" + |
||||
"\t\t\t\t<xs:sequence>\r\n" + |
||||
"\t\t\t\t\t<xs:sequence>\r\n" + |
||||
"\t\t\t\t\t\t<xs:element name=\"title\" type=\"xs:string\"/>\r\n" + |
||||
"\t\t\t\t\t\t<xs:element name=\"text\" type=\"xs:string\"/>\r\n" + |
||||
"\t\t\t\t\t</xs:sequence>\r\n" + |
||||
"\t\t\t\t</xs:sequence>\r\n" + |
||||
"\t\t\t</xs:sequence>\r\n" + |
||||
"\t\t</xs:complexType>\r\n" + |
||||
"\t</xs:element>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,156 @@
@@ -0,0 +1,156 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
[TestFixture] |
||||
public class ReferencedElementsTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
ICompletionData[] shipOrderAttributes; |
||||
ICompletionData[] shipToAttributes; |
||||
XmlElementPath shipToPath; |
||||
XmlElementPath shipOrderPath; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
StringReader reader = new StringReader(GetSchema()); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
|
||||
// Get shipto attributes.
|
||||
shipToPath = new XmlElementPath(); |
||||
QualifiedName shipOrderName = new QualifiedName("shiporder", "http://www.w3schools.com"); |
||||
shipToPath.Elements.Add(shipOrderName); |
||||
shipToPath.Elements.Add(new QualifiedName("shipto", "http://www.w3schools.com")); |
||||
|
||||
shipToAttributes = schemaCompletionData.GetAttributeCompletionData(shipToPath); |
||||
|
||||
// Get shiporder attributes.
|
||||
shipOrderPath = new XmlElementPath(); |
||||
shipOrderPath.Elements.Add(shipOrderName); |
||||
|
||||
shipOrderAttributes = schemaCompletionData.GetAttributeCompletionData(shipOrderPath); |
||||
|
||||
} |
||||
|
||||
[Test] |
||||
public void OneShipOrderAttribute() |
||||
{ |
||||
Assert.AreEqual(1, shipOrderAttributes.Length, "Should only have one shiporder attribute."); |
||||
} |
||||
|
||||
[Test] |
||||
public void ShipOrderAttributeName() |
||||
{ |
||||
Assert.IsTrue(base.Contains(shipOrderAttributes,"id"), |
||||
"Incorrect shiporder attribute name."); |
||||
} |
||||
|
||||
[Test] |
||||
public void OneShipToAttribute() |
||||
{ |
||||
Assert.AreEqual(1, shipToAttributes.Length, "Should only have one shipto attribute."); |
||||
} |
||||
|
||||
[Test] |
||||
public void ShipToAttributeName() |
||||
{ |
||||
Assert.IsTrue(base.Contains(shipToAttributes, "address"), |
||||
"Incorrect shipto attribute name."); |
||||
} |
||||
|
||||
[Test] |
||||
public void ShipOrderChildElementsCount() |
||||
{ |
||||
Assert.AreEqual(1, schemaCompletionData.GetChildElementCompletionData(shipOrderPath).Length, |
||||
"Should be one child element."); |
||||
} |
||||
|
||||
[Test] |
||||
public void ShipOrderHasShipToChildElement() |
||||
{ |
||||
ICompletionData[] data = schemaCompletionData.GetChildElementCompletionData(shipOrderPath); |
||||
Assert.IsTrue(base.Contains(data, "shipto"), |
||||
"Incorrect child element name."); |
||||
} |
||||
|
||||
[Test] |
||||
public void ShipToChildElementsCount() |
||||
{ |
||||
Assert.AreEqual(2, schemaCompletionData.GetChildElementCompletionData(shipToPath).Length, |
||||
"Should be 2 child elements."); |
||||
} |
||||
|
||||
[Test] |
||||
public void ShipToHasNameChildElement() |
||||
{ |
||||
ICompletionData[] data = schemaCompletionData.GetChildElementCompletionData(shipToPath); |
||||
Assert.IsTrue(base.Contains(data, "name"), |
||||
"Incorrect child element name."); |
||||
} |
||||
|
||||
[Test] |
||||
public void ShipToHasAddressChildElement() |
||||
{ |
||||
ICompletionData[] data = schemaCompletionData.GetChildElementCompletionData(shipToPath); |
||||
Assert.IsTrue(base.Contains(data, "address"), |
||||
"Incorrect child element name."); |
||||
} |
||||
|
||||
string GetSchema() |
||||
{ |
||||
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://www.w3schools.com\" xmlns=\"http://www.w3schools.com\">\r\n" + |
||||
"\r\n" + |
||||
"<!-- definition of simple elements -->\r\n" + |
||||
"<xs:element name=\"name\" type=\"xs:string\"/>\r\n" + |
||||
"<xs:element name=\"address\" type=\"xs:string\"/>\r\n" + |
||||
"\r\n" + |
||||
"<!-- definition of complex elements -->\r\n" + |
||||
"<xs:element name=\"shipto\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:sequence>\r\n" + |
||||
" <xs:element ref=\"name\"/>\r\n" + |
||||
" <xs:element ref=\"address\"/>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" <xs:attribute name=\"address\"/>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
"</xs:element>\r\n" + |
||||
"\r\n" + |
||||
"<xs:element name=\"shiporder\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:sequence>\r\n" + |
||||
" <xs:element ref=\"shipto\"/>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" <xs:attribute name=\"id\"/>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
"</xs:element>\r\n" + |
||||
"\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,172 @@
@@ -0,0 +1,172 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Tests complex content restriction elements.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class RestrictionElementTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
ICompletionData[] childElements; |
||||
ICompletionData[] attributes; |
||||
ICompletionData[] annotationChildElements; |
||||
ICompletionData[] choiceChildElements; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
StringReader reader = new StringReader(GetSchema()); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
|
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("group", "http://www.w3.org/2001/XMLSchema")); |
||||
childElements = schemaCompletionData.GetChildElementCompletionData(path); |
||||
attributes = schemaCompletionData.GetAttributeCompletionData(path); |
||||
|
||||
// Get annotation child elements.
|
||||
path.Elements.Add(new QualifiedName("annotation", "http://www.w3.org/2001/XMLSchema")); |
||||
annotationChildElements = schemaCompletionData.GetChildElementCompletionData(path); |
||||
|
||||
// Get choice child elements.
|
||||
path.Elements.RemoveLast(); |
||||
path.Elements.Add(new QualifiedName("choice", "http://www.w3.org/2001/XMLSchema")); |
||||
choiceChildElements = schemaCompletionData.GetChildElementCompletionData(path); |
||||
} |
||||
|
||||
[Test] |
||||
public void GroupChildElementIsAnnotation() |
||||
{ |
||||
Assert.IsTrue(base.Contains(childElements, "annotation"), |
||||
"Should have a child element called annotation."); |
||||
} |
||||
|
||||
[Test] |
||||
public void GroupChildElementIsChoice() |
||||
{ |
||||
Assert.IsTrue(base.Contains(childElements, "choice"), |
||||
"Should have a child element called choice."); |
||||
} |
||||
|
||||
[Test] |
||||
public void GroupChildElementIsSequence() |
||||
{ |
||||
Assert.IsTrue(base.Contains(childElements, "sequence"), |
||||
"Should have a child element called sequence."); |
||||
} |
||||
|
||||
[Test] |
||||
public void GroupAttributeIsName() |
||||
{ |
||||
Assert.IsTrue(base.Contains(attributes, "name"), |
||||
"Should have an attribute called name."); |
||||
} |
||||
|
||||
[Test] |
||||
public void AnnotationChildElementIsAppInfo() |
||||
{ |
||||
Assert.IsTrue(base.Contains(annotationChildElements, "appinfo"), |
||||
"Should have a child element called appinfo."); |
||||
} |
||||
|
||||
[Test] |
||||
public void AnnotationChildElementIsDocumentation() |
||||
{ |
||||
Assert.IsTrue(base.Contains(annotationChildElements, "documentation"), |
||||
"Should have a child element called appinfo."); |
||||
} |
||||
|
||||
[Test] |
||||
public void ChoiceChildElementIsSequence() |
||||
{ |
||||
Assert.IsTrue(base.Contains(choiceChildElements, "element"), |
||||
"Should have a child element called element."); |
||||
} |
||||
|
||||
string GetSchema() |
||||
{ |
||||
return "<xs:schema targetNamespace=\"http://www.w3.org/2001/XMLSchema\" blockDefault=\"#all\" elementFormDefault=\"qualified\" version=\"1.0\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xml:lang=\"EN\" xmlns:hfp=\"http://www.w3.org/2001/XMLSchema-hasFacetAndProperty\">\r\n" + |
||||
"\r\n" + |
||||
" <xs:element name=\"group\" type=\"xs:namedGroup\" id=\"group\">\r\n" + |
||||
" </xs:element>\r\n" + |
||||
"\r\n" + |
||||
" <xs:element name=\"annotation\" id=\"annotation\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\">\r\n" + |
||||
" <xs:element name=\"appinfo\"/>\r\n" + |
||||
" <xs:element name=\"documentation\"/>\r\n" + |
||||
" </xs:choice>\r\n" + |
||||
" <xs:attribute name=\"id\" type=\"xs:ID\"/>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
" </xs:element>\r\n" + |
||||
"\r\n" + |
||||
"\r\n" + |
||||
" <xs:complexType name=\"namedGroup\">\r\n" + |
||||
" <xs:complexContent>\r\n" + |
||||
" <xs:restriction base=\"xs:realGroup\">\r\n" + |
||||
" <xs:sequence>\r\n" + |
||||
" <xs:element ref=\"xs:annotation\" minOccurs=\"0\"/>\r\n" + |
||||
" <xs:choice minOccurs=\"1\" maxOccurs=\"1\">\r\n" + |
||||
" <xs:element ref=\"xs:choice\"/>\r\n" + |
||||
" <xs:element name=\"sequence\"/>\r\n" + |
||||
" </xs:choice>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" <xs:attribute name=\"name\" use=\"required\" type=\"xs:NCName\"/>\r\n" + |
||||
" <xs:attribute name=\"ref\" use=\"prohibited\"/>\r\n" + |
||||
" <xs:attribute name=\"minOccurs\" use=\"prohibited\"/>\r\n" + |
||||
" <xs:attribute name=\"maxOccurs\" use=\"prohibited\"/>\r\n" + |
||||
" <xs:anyAttribute namespace=\"##other\" processContents=\"lax\"/>\r\n" + |
||||
" </xs:restriction>\r\n" + |
||||
" </xs:complexContent>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
"\r\n" + |
||||
" <xs:complexType name=\"realGroup\">\r\n" + |
||||
" <xs:sequence>\r\n" + |
||||
" <xs:element ref=\"xs:annotation\" minOccurs=\"0\"/>\r\n" + |
||||
" <xs:choice minOccurs=\"0\" maxOccurs=\"1\">\r\n" + |
||||
" <xs:element name=\"all\"/>\r\n" + |
||||
" <xs:element ref=\"xs:choice\"/>\r\n" + |
||||
" <xs:element name=\"sequence\"/>\r\n" + |
||||
" </xs:choice>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" <xs:anyAttribute namespace=\"##other\" processContents=\"lax\"/>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
"\r\n" + |
||||
" <xs:element name=\"choice\" id=\"choice\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:choice minOccurs=\"0\" maxOccurs=\"1\">\r\n" + |
||||
" <xs:element name=\"element\"/>\r\n" + |
||||
" <xs:element name=\"sequence\"/>\r\n" + |
||||
" </xs:choice>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
" </xs:element>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,84 @@
@@ -0,0 +1,84 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using NUnit.Framework; |
||||
using System; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
public abstract class SchemaTestFixtureBase |
||||
{ |
||||
/// <summary>
|
||||
/// Checks whether the specified name exists in the completion data.
|
||||
/// </summary>
|
||||
protected bool Contains(ICompletionData[] items, string name) |
||||
{ |
||||
bool Contains = false; |
||||
|
||||
foreach (ICompletionData data in items) { |
||||
if (data.Text == name) { |
||||
Contains = true; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
return Contains; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Checks whether the completion data specified by name has
|
||||
/// the correct description.
|
||||
/// </summary>
|
||||
protected bool ContainsDescription(ICompletionData[] items, string name, string description) |
||||
{ |
||||
bool Contains = false; |
||||
|
||||
foreach (ICompletionData data in items) { |
||||
if (data.Text == name) { |
||||
if (data.Description == description) { |
||||
Contains = true; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
return Contains; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets a count of the number of occurrences of a particular name
|
||||
/// in the completion data.
|
||||
/// </summary>
|
||||
protected int GetItemCount(ICompletionData[] items, string name) |
||||
{ |
||||
int count = 0; |
||||
|
||||
foreach (ICompletionData data in items) { |
||||
if (data.Text == name) { |
||||
++count; |
||||
} |
||||
} |
||||
|
||||
return count; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,111 @@
@@ -0,0 +1,111 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that nested schema choice elements inside a sequence are handled.
|
||||
/// This happens in the NAnt schema 0.85.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class SequencedChoiceTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
ICompletionData[] noteChildElements; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
StringReader reader = new StringReader(GetSchema()); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
|
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); |
||||
|
||||
noteChildElements = schemaCompletionData.GetChildElementCompletionData(path); |
||||
} |
||||
|
||||
[Test] |
||||
public void TitleHasNoChildElements() |
||||
{ |
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); |
||||
path.Elements.Add(new QualifiedName("title", "http://www.w3schools.com")); |
||||
|
||||
Assert.AreEqual(0, schemaCompletionData.GetChildElementCompletionData(path).Length, |
||||
"Should be no child elements."); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextHasNoChildElements() |
||||
{ |
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); |
||||
path.Elements.Add(new QualifiedName("title", "http://www.w3schools.com")); |
||||
|
||||
Assert.AreEqual(0, schemaCompletionData.GetChildElementCompletionData(path).Length, |
||||
"Should be no child elements."); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoteHasTwoChildElements() |
||||
{ |
||||
Assert.AreEqual(2, noteChildElements.Length, |
||||
"Should be two child elements."); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoteChildElementIsText() |
||||
{ |
||||
Assert.IsTrue(base.Contains(noteChildElements, "text"), |
||||
"Should have a child element called text."); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoteChildElementIsTitle() |
||||
{ |
||||
Assert.IsTrue(base.Contains(noteChildElements, "title"), |
||||
"Should have a child element called title."); |
||||
} |
||||
|
||||
string GetSchema() |
||||
{ |
||||
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://www.w3schools.com\" xmlns=\"http://www.w3schools.com\" elementFormDefault=\"qualified\">\r\n" + |
||||
"\t<xs:element name=\"note\">\r\n" + |
||||
"\t\t<xs:complexType> \r\n" + |
||||
"\t\t\t<xs:sequence>\r\n" + |
||||
"\t\t\t\t<xs:choice>\r\n" + |
||||
"\t\t\t\t\t<xs:element name=\"title\" type=\"xs:string\"/>\r\n" + |
||||
"\t\t\t\t\t<xs:element name=\"text\" type=\"xs:string\"/>\r\n" + |
||||
"\t\t\t\t</xs:choice>\r\n" + |
||||
"\t\t\t</xs:sequence>\r\n" + |
||||
"\t\t</xs:complexType>\r\n" + |
||||
"\t</xs:element>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,87 @@
@@ -0,0 +1,87 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Element that is a simple content type.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class SimpleContentWithAttributeSchemaTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
ICompletionData[] attributeCompletionData; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
StringReader reader = new StringReader(GetSchema()); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
|
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("foo", "http://foo.com")); |
||||
|
||||
attributeCompletionData = schemaCompletionData.GetAttributeCompletionData(path); |
||||
} |
||||
|
||||
[Test] |
||||
public void BarAttributeExists() |
||||
{ |
||||
Assert.IsTrue(base.Contains(attributeCompletionData, "bar"), |
||||
"Attribute bar does not exist."); |
||||
} |
||||
|
||||
string GetSchema() |
||||
{ |
||||
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\r\n" + |
||||
"\ttargetNamespace=\"http://foo.com\"\r\n" + |
||||
"\txmlns=\"http://foo.com\">\r\n" + |
||||
"\t<xs:element name=\"foo\">\r\n" + |
||||
"\t\t<xs:complexType>\r\n" + |
||||
"\t\t\t<xs:simpleContent>\r\n" + |
||||
"\t\t\t\t<xs:extension base=\"xs:string\">\r\n" + |
||||
"\t\t\t\t\t<xs:attribute name=\"bar\">\r\n" + |
||||
"\t\t\t\t\t\t<xs:simpleType>\r\n" + |
||||
"\t\t\t\t\t\t\t<xs:restriction base=\"xs:NMTOKEN\">\r\n" + |
||||
"\t\t\t\t\t\t\t\t<xs:enumeration value=\"default\"/>\r\n" + |
||||
"\t\t\t\t\t\t\t\t<xs:enumeration value=\"enable\"/>\r\n" + |
||||
"\t\t\t\t\t\t\t\t<xs:enumeration value=\"disable\"/>\r\n" + |
||||
"\t\t\t\t\t\t\t\t<xs:enumeration value=\"hide\"/>\r\n" + |
||||
"\t\t\t\t\t\t\t\t<xs:enumeration value=\"show\"/>\r\n" + |
||||
"\t\t\t\t\t\t\t</xs:restriction>\r\n" + |
||||
"\t\t\t\t\t\t</xs:simpleType>\r\n" + |
||||
"\t\t\t\t\t</xs:attribute>\r\n" + |
||||
"\t\t\t\t\t<xs:attribute name=\"id\" type=\"xs:string\"/>\r\n" + |
||||
"\t\t\t\t\t<xs:attribute name=\"msg\" type=\"xs:string\"/>\r\n" + |
||||
"\t\t\t\t</xs:extension>\r\n" + |
||||
"\t\t\t</xs:simpleContent>\r\n" + |
||||
"\t\t</xs:complexType>\r\n" + |
||||
"\t</xs:element>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,91 @@
@@ -0,0 +1,91 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Retrieve completion data for an xml schema that specifies only one
|
||||
/// element.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class SingleElementSchemaTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
ICompletionData[] childElementCompletionData; |
||||
ICompletionData[] attributeCompletionData; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
StringReader reader = new StringReader(GetSchema()); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
|
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); |
||||
|
||||
attributeCompletionData = |
||||
schemaCompletionData.GetAttributeCompletionData(path); |
||||
|
||||
childElementCompletionData = |
||||
schemaCompletionData.GetChildElementCompletionData(path); |
||||
} |
||||
|
||||
[Test] |
||||
public void NamespaceUri() |
||||
{ |
||||
Assert.AreEqual("http://www.w3schools.com", |
||||
schemaCompletionData.NamespaceUri, |
||||
"Unexpected namespace."); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoteElementHasNoAttributes() |
||||
{ |
||||
Assert.AreEqual(0, attributeCompletionData.Length, |
||||
"Not expecting any attributes."); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoteElementHasNoChildElements() |
||||
{ |
||||
Assert.AreEqual(0, childElementCompletionData.Length, "" + |
||||
"Not expecting any child elements."); |
||||
} |
||||
|
||||
string GetSchema() |
||||
{ |
||||
return "<?xml version=\"1.0\"?>\r\n" + |
||||
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\r\n" + |
||||
"targetNamespace=\"http://www.w3schools.com\"\r\n" + |
||||
"xmlns=\"http://www.w3schools.com\"\r\n" + |
||||
"elementFormDefault=\"qualified\">\r\n" + |
||||
"<xs:element name=\"note\">\r\n" + |
||||
"</xs:element>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,130 @@
@@ -0,0 +1,130 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Two elements defined in a schema, one uses the 'type' attribute to
|
||||
/// link to the complex type definition.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class TwoElementSchemaTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
XmlElementPath noteElementPath; |
||||
XmlElementPath textElementPath; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
StringReader reader = new StringReader(GetSchema()); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
|
||||
// Note element path.
|
||||
noteElementPath = new XmlElementPath(); |
||||
QualifiedName noteQualifiedName = new QualifiedName("note", "http://www.w3schools.com"); |
||||
noteElementPath.Elements.Add(noteQualifiedName); |
||||
|
||||
// Text element path.
|
||||
textElementPath = new XmlElementPath(); |
||||
textElementPath.Elements.Add(noteQualifiedName); |
||||
textElementPath.Elements.Add(new QualifiedName("text", "http://www.w3schools.com")); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextElementHasOneAttribute() |
||||
{ |
||||
ICompletionData[] attributesCompletionData = schemaCompletionData.GetAttributeCompletionData(textElementPath); |
||||
|
||||
Assert.AreEqual(1, attributesCompletionData.Length, |
||||
"Should have 1 text attribute."); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextElementAttributeName() |
||||
{ |
||||
ICompletionData[] attributesCompletionData = schemaCompletionData.GetAttributeCompletionData(textElementPath); |
||||
Assert.IsTrue(base.Contains(attributesCompletionData, "foo"), |
||||
"Unexpected text attribute name."); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoteElementHasChildElement() |
||||
{ |
||||
ICompletionData[] childElementCompletionData |
||||
= schemaCompletionData.GetChildElementCompletionData(noteElementPath); |
||||
|
||||
Assert.AreEqual(1, childElementCompletionData.Length, |
||||
"Should be one child."); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoteElementHasNoAttributes() |
||||
{ |
||||
ICompletionData[] attributeCompletionData |
||||
= schemaCompletionData.GetAttributeCompletionData(noteElementPath); |
||||
|
||||
Assert.AreEqual(0, attributeCompletionData.Length, |
||||
"Should no attributes."); |
||||
} |
||||
|
||||
[Test] |
||||
public void OneRootElement() |
||||
{ |
||||
ICompletionData[] elementCompletionData |
||||
= schemaCompletionData.GetElementCompletionData(); |
||||
|
||||
Assert.AreEqual(1, elementCompletionData.Length, "Should be 1 root element."); |
||||
} |
||||
|
||||
[Test] |
||||
public void RootElementIsNote() |
||||
{ |
||||
ICompletionData[] elementCompletionData |
||||
= schemaCompletionData.GetElementCompletionData(); |
||||
|
||||
Assert.IsTrue(Contains(elementCompletionData, "note"), |
||||
"Should be called note."); |
||||
} |
||||
|
||||
string GetSchema() |
||||
{ |
||||
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://www.w3schools.com\" xmlns=\"http://www.w3schools.com\" elementFormDefault=\"qualified\">\r\n" + |
||||
"\t<xs:element name=\"note\">\r\n" + |
||||
"\t\t<xs:complexType> \r\n" + |
||||
"\t\t\t<xs:sequence>\r\n" + |
||||
"\t\t\t\t<xs:element name=\"text\" type=\"text-type\"/>\r\n" + |
||||
"\t\t\t</xs:sequence>\r\n" + |
||||
"\t\t</xs:complexType>\r\n" + |
||||
"\t</xs:element>\r\n" + |
||||
"\t<xs:complexType name=\"text-type\">\r\n" + |
||||
"\t\t<xs:attribute name=\"foo\"/>\r\n" + |
||||
"\t</xs:complexType>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,65 @@
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// ${App.Name}
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
using System.Xml; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the xhtml1-strict schema.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class XhtmlStrictSchemaTestFixture |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
XmlElementPath h1Path; |
||||
ICompletionData[] h1Attributes; |
||||
string namespaceURI = "http://www.w3.org/1999/xhtml"; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
XmlTextReader reader = ResourceManager.GetXhtmlStrictSchema(); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
|
||||
// Set up h1 element's path.
|
||||
h1Path = new XmlElementPath(); |
||||
h1Path.Elements.Add(new QualifiedName("html", namespaceURI)); |
||||
h1Path.Elements.Add(new QualifiedName("body", namespaceURI)); |
||||
h1Path.Elements.Add(new QualifiedName("h1", namespaceURI)); |
||||
|
||||
// Get h1 element info.
|
||||
h1Attributes = schemaCompletionData.GetAttributeCompletionData(h1Path); |
||||
} |
||||
|
||||
[Test] |
||||
public void H1HasAttributes() |
||||
{ |
||||
Assert.IsTrue(h1Attributes.Length > 0, "Should have at least one attribute."); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,225 @@
@@ -0,0 +1,225 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
using System.Xml; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the xsd schema.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class XsdSchemaTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaCompletionData schemaCompletionData; |
||||
XmlElementPath choicePath; |
||||
XmlElementPath elementPath; |
||||
XmlElementPath simpleEnumPath; |
||||
XmlElementPath enumPath; |
||||
ICompletionData[] choiceAttributes; |
||||
ICompletionData[] elementAttributes; |
||||
ICompletionData[] simpleEnumElements; |
||||
ICompletionData[] enumAttributes; |
||||
ICompletionData[] elementFormDefaultAttributeValues; |
||||
ICompletionData[] blockDefaultAttributeValues; |
||||
ICompletionData[] finalDefaultAttributeValues; |
||||
ICompletionData[] mixedAttributeValues; |
||||
ICompletionData[] maxOccursAttributeValues; |
||||
|
||||
string namespaceURI = "http://www.w3.org/2001/XMLSchema"; |
||||
string prefix = "xs"; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void FixtureInit() |
||||
{ |
||||
XmlTextReader reader = ResourceManager.GetXsdSchema(); |
||||
schemaCompletionData = new XmlSchemaCompletionData(reader); |
||||
|
||||
// Set up choice element's path.
|
||||
choicePath = new XmlElementPath(); |
||||
choicePath.Elements.Add(new QualifiedName("schema", namespaceURI, prefix)); |
||||
choicePath.Elements.Add(new QualifiedName("element", namespaceURI, prefix)); |
||||
choicePath.Elements.Add(new QualifiedName("complexType", namespaceURI, prefix)); |
||||
|
||||
mixedAttributeValues = schemaCompletionData.GetAttributeValueCompletionData(choicePath, "mixed"); |
||||
|
||||
choicePath.Elements.Add(new QualifiedName("choice", namespaceURI, prefix)); |
||||
|
||||
// Get choice element info.
|
||||
choiceAttributes = schemaCompletionData.GetAttributeCompletionData(choicePath); |
||||
maxOccursAttributeValues = schemaCompletionData.GetAttributeValueCompletionData(choicePath, "maxOccurs"); |
||||
|
||||
// Set up element path.
|
||||
elementPath = new XmlElementPath(); |
||||
elementPath.Elements.Add(new QualifiedName("schema", namespaceURI, prefix)); |
||||
|
||||
elementFormDefaultAttributeValues = schemaCompletionData.GetAttributeValueCompletionData(elementPath, "elementFormDefault"); |
||||
blockDefaultAttributeValues = schemaCompletionData.GetAttributeValueCompletionData(elementPath, "blockDefault"); |
||||
finalDefaultAttributeValues = schemaCompletionData.GetAttributeValueCompletionData(elementPath, "finalDefault"); |
||||
|
||||
elementPath.Elements.Add(new QualifiedName("element", namespaceURI, prefix)); |
||||
|
||||
// Get element attribute info.
|
||||
elementAttributes = schemaCompletionData.GetAttributeCompletionData(elementPath); |
||||
|
||||
// Set up simple enum type path.
|
||||
simpleEnumPath = new XmlElementPath(); |
||||
simpleEnumPath.Elements.Add(new QualifiedName("schema", namespaceURI, prefix)); |
||||
simpleEnumPath.Elements.Add(new QualifiedName("simpleType", namespaceURI, prefix)); |
||||
simpleEnumPath.Elements.Add(new QualifiedName("restriction", namespaceURI, prefix)); |
||||
|
||||
// Get child elements.
|
||||
simpleEnumElements = schemaCompletionData.GetChildElementCompletionData(simpleEnumPath); |
||||
|
||||
// Set up enum path.
|
||||
enumPath = new XmlElementPath(); |
||||
enumPath.Elements.Add(new QualifiedName("schema", namespaceURI, prefix)); |
||||
enumPath.Elements.Add(new QualifiedName("simpleType", namespaceURI, prefix)); |
||||
enumPath.Elements.Add(new QualifiedName("restriction", namespaceURI, prefix)); |
||||
enumPath.Elements.Add(new QualifiedName("enumeration", namespaceURI, prefix)); |
||||
|
||||
// Get attributes.
|
||||
enumAttributes = schemaCompletionData.GetAttributeCompletionData(enumPath); |
||||
} |
||||
|
||||
[Test] |
||||
public void ChoiceHasAttributes() |
||||
{ |
||||
Assert.IsTrue(choiceAttributes.Length > 0, "Should have at least one attribute."); |
||||
} |
||||
|
||||
[Test] |
||||
public void ChoiceHasMinOccursAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(choiceAttributes, "minOccurs"), |
||||
"Attribute minOccurs missing."); |
||||
} |
||||
|
||||
[Test] |
||||
public void ChoiceHasMaxOccursAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(choiceAttributes, "maxOccurs"), |
||||
"Attribute maxOccurs missing."); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that prohibited attributes are not added to the completion data.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void ChoiceDoesNotHaveNameAttribute() |
||||
{ |
||||
Assert.IsFalse(base.Contains(choiceAttributes, "name"), |
||||
"Attribute name should not exist."); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that prohibited attributes are not added to the completion data.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void ChoiceDoesNotHaveRefAttribute() |
||||
{ |
||||
Assert.IsFalse(base.Contains(choiceAttributes, "ref"), |
||||
"Attribute ref should not exist."); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Duplicate attribute test.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void ElementNameAttributeAppearsOnce() |
||||
{ |
||||
int nameAttributeCount = base.GetItemCount(elementAttributes, "name"); |
||||
Assert.AreEqual(1, nameAttributeCount, "Should be only one name attribute."); |
||||
} |
||||
|
||||
[Test] |
||||
public void ElementHasIdAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(elementAttributes, "id"), |
||||
"id attribute missing."); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleRestrictionTypeHasEnumChildElement() |
||||
{ |
||||
Assert.IsTrue(base.Contains(simpleEnumElements, "xs:enumeration"), |
||||
"enumeration element missing."); |
||||
} |
||||
|
||||
[Test] |
||||
public void EnumHasValueAttribute() |
||||
{ |
||||
Assert.IsTrue(base.Contains(enumAttributes, "value"), |
||||
"Attribute value missing."); |
||||
} |
||||
|
||||
[Test] |
||||
public void ElementFormDefaultAttributeHasValueQualified() |
||||
{ |
||||
Assert.IsTrue(base.Contains(elementFormDefaultAttributeValues, "qualified"), |
||||
"Attribute value 'qualified' missing."); |
||||
} |
||||
|
||||
[Test] |
||||
public void BlockDefaultAttributeHasValueAll() |
||||
{ |
||||
Assert.IsTrue(base.Contains(blockDefaultAttributeValues, "#all"), |
||||
"Attribute value '#all' missing."); |
||||
} |
||||
|
||||
[Test] |
||||
public void BlockDefaultAttributeHasValueExtension() |
||||
{ |
||||
Assert.IsTrue(base.Contains(blockDefaultAttributeValues, "extension"), |
||||
"Attribute value 'extension' missing."); |
||||
} |
||||
|
||||
[Test] |
||||
public void FinalDefaultAttributeHasValueList() |
||||
{ |
||||
Assert.IsTrue(base.Contains(finalDefaultAttributeValues, "list"), |
||||
"Attribute value 'list' missing."); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// xs:boolean tests.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void MixedAttributeHasValueTrue() |
||||
{ |
||||
Assert.IsTrue(base.Contains(mixedAttributeValues, "true"), |
||||
"Attribute value 'true' missing."); |
||||
} |
||||
|
||||
[Test] |
||||
public void MaxOccursAttributeHasValueUnbounded() |
||||
{ |
||||
Assert.IsTrue(base.Contains(maxOccursAttributeValues, "unbounded"), |
||||
"Attribute value 'unbounded' missing."); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,76 @@
@@ -0,0 +1,76 @@
|
||||
//
|
||||
// SharpDevelop Xml Editor
|
||||
//
|
||||
// Copyright (C) 2005 Matthew Ward
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Matthew Ward (mrward@users.sourceforge.net)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Reflection; |
||||
using System.Xml; |
||||
|
||||
namespace XmlEditor.Tests.Utils |
||||
{ |
||||
/// <summary>
|
||||
/// Returns strings from the embedded test resources.
|
||||
/// </summary>
|
||||
public class ResourceManager |
||||
{ |
||||
static ResourceManager manager; |
||||
|
||||
static ResourceManager() |
||||
{ |
||||
manager = new ResourceManager(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the xhtml strict schema xml.
|
||||
/// </summary>
|
||||
public static XmlTextReader GetXhtmlStrictSchema() |
||||
{ |
||||
return manager.GetXml("xhtml1-strict-modified.xsd"); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the xsd schema.
|
||||
/// </summary>
|
||||
public static XmlTextReader GetXsdSchema() |
||||
{ |
||||
return manager.GetXml("XMLSchema.xsd"); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the xml read from the specified file which is embedded
|
||||
/// in this assembly as a resource.
|
||||
/// </summary>
|
||||
public XmlTextReader GetXml(string fileName) |
||||
{ |
||||
XmlTextReader reader = null; |
||||
|
||||
Assembly assembly = Assembly.GetAssembly(this.GetType()); |
||||
|
||||
Stream resourceStream = assembly.GetManifestResourceStream(fileName); |
||||
if (resourceStream != null) { |
||||
reader = new XmlTextReader(resourceStream); |
||||
} |
||||
|
||||
return reader; |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,101 @@
@@ -0,0 +1,101 @@
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<PropertyGroup> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||
<SchemaVersion>2.0</SchemaVersion> |
||||
<ProjectGuid>{FC0FE702-A87D-4D70-A9B6-1ECCD611125F}</ProjectGuid> |
||||
<RootNamespace>XmlEditor.Tests</RootNamespace> |
||||
<AssemblyName>XmlEditor.Tests</AssemblyName> |
||||
<OutputType>Library</OutputType> |
||||
<WarningLevel>4</WarningLevel> |
||||
<NoStdLib>False</NoStdLib> |
||||
<NoConfig>False</NoConfig> |
||||
<RunPostBuildEvent>OnSuccessfulBuild</RunPostBuildEvent> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
||||
<DebugSymbols>True</DebugSymbols> |
||||
<Optimize>False</Optimize> |
||||
<AllowUnsafeBlocks>False</AllowUnsafeBlocks> |
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> |
||||
<OutputPath>..\..\..\..\..\AddIns\AddIns\DisplayBindings\XmlEditor\</OutputPath> |
||||
<TreatWarningsAsErrors>False</TreatWarningsAsErrors> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
||||
<DebugSymbols>False</DebugSymbols> |
||||
<Optimize>True</Optimize> |
||||
<AllowUnsafeBlocks>False</AllowUnsafeBlocks> |
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> |
||||
<OutputPath>..\..\..\..\..\AddIns\AddIns\DisplayBindings\XmlEditor\</OutputPath> |
||||
<TreatWarningsAsErrors>False</TreatWarningsAsErrors> |
||||
</PropertyGroup> |
||||
<ItemGroup> |
||||
<Reference Include="System" /> |
||||
<Reference Include="System.Data" /> |
||||
<Reference Include="System.Drawing" /> |
||||
<Reference Include="System.Windows.Forms" /> |
||||
<Reference Include="System.Xml" /> |
||||
<Reference Include="nunit.framework, Version=2.2.0.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77"> |
||||
<Private>False</Private> |
||||
</Reference> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="AssemblyInfo.cs" /> |
||||
<Compile Include="Schema\SingleElementSchemaTestFixture.cs" /> |
||||
<Compile Include="Schema\ElementWithAttributeSchemaTestFixture.cs" /> |
||||
<Compile Include="Schema\NestedElementSchemaTestFixture.cs" /> |
||||
<Compile Include="Schema\TwoElementSchemaTestFixture.cs" /> |
||||
<Compile Include="Schema\ReferencedElementsTestFixture.cs" /> |
||||
<Compile Include="Schema\NamespaceCompletionTestFixture.cs" /> |
||||
<Compile Include="Schema\SchemaTestFixtureBase.cs" /> |
||||
<Compile Include="Parser\NamespaceDeclarationTestFixture.cs" /> |
||||
<Compile Include="Parser\ParentElementPathTestFixture.cs" /> |
||||
<Compile Include="Schema\NestedSequenceTestFixture.cs" /> |
||||
<Compile Include="Schema\SequencedChoiceTestFixture.cs" /> |
||||
<Compile Include="Schema\ChoiceTestFixture.cs" /> |
||||
<Compile Include="Schema\AttributeGroupRefTestFixture.cs" /> |
||||
<Compile Include="Schema\NestedAttributeGroupRefTestFixture.cs" /> |
||||
<Compile Include="Schema\ComplexContentExtensionTestFixture.cs" /> |
||||
<Compile Include="Schema\AttributeRefTestFixture.cs" /> |
||||
<Compile Include="Schema\GroupRefTestFixture.cs" /> |
||||
<Compile Include="Schema\DuplicateElementTestFixture.cs" /> |
||||
<Compile Include="Schema\ExtensionElementTestFixture.cs" /> |
||||
<Compile Include="Schema\RestrictionElementTestFixture.cs" /> |
||||
<Compile Include="Parser\QualifiedNameTestFixture.cs" /> |
||||
<Compile Include="Paths\NoElementPathTestFixture.cs" /> |
||||
<Compile Include="Paths\SingleElementPathTestFixture.cs" /> |
||||
<Compile Include="Paths\TwoElementPathTestFixture.cs" /> |
||||
<Compile Include="Schema\NestedChoiceTestFixture.cs" /> |
||||
<Compile Include="Schema\ChildElementAttributesTestFixture.cs" /> |
||||
<Compile Include="Utils\ResourceManager.cs" /> |
||||
<Compile Include="Schema\XhtmlStrictSchemaTestFixture.cs" /> |
||||
<Compile Include="Schema\XsdSchemaTestFixture.cs" /> |
||||
<Compile Include="Schema\GroupRefCompositorTestFixture.cs" /> |
||||
<Compile Include="Schema\ElementAnnotationTestFixture.cs" /> |
||||
<Compile Include="Parser\ActiveElementStartPathTestFixture.cs" /> |
||||
<Compile Include="Schema\AttributeAnnotationTestFixture.cs" /> |
||||
<Compile Include="Schema\EnumAttributeValueTestFixture.cs" /> |
||||
<Compile Include="Parser\AttributeNameTestFixture.cs" /> |
||||
<Compile Include="Schema\AttributeValueAnnotationTestFixture.cs" /> |
||||
<Compile Include="Schema\ElementRefAnnotationTestFixture.cs" /> |
||||
<Compile Include="Schema\SimpleContentWithAttributeTestFixture.cs" /> |
||||
<EmbeddedResource Include="Resources\xhtml1-strict-modified.xsd" /> |
||||
<EmbeddedResource Include="Resources\XMLSchema.xsd" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Folder Include="Schema\" /> |
||||
<Folder Include="Parser\" /> |
||||
<Folder Include="Paths\" /> |
||||
<Folder Include="Utils\" /> |
||||
<ProjectReference Include="..\Project\XmlEditor.csproj"> |
||||
<Project>{63B6CA43-58D0-4BF0-9D4F-1ABE4009E488}</Project> |
||||
<Name>XmlEditor</Name> |
||||
<Private>False</Private> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\..\..\..\Libraries\ICSharpCode.TextEditor\Project\ICSharpCode.TextEditor.csproj"> |
||||
<Project>{2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}</Project> |
||||
<Name>ICSharpCode.TextEditor</Name> |
||||
<Private>False</Private> |
||||
</ProjectReference> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> |
||||
</Project> |
@ -0,0 +1,4 @@
@@ -0,0 +1,4 @@
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' " /> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " /> |
||||
</Project> |
@ -0,0 +1,8 @@
@@ -0,0 +1,8 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 9.00 |
||||
# SharpDevelop 2.0.0.309 |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmlEditor", "Project\XmlEditor.csproj", "{63B6CA43-58D0-4BF0-9D4F-1ABE4009E488}" |
||||
EndProject |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmlEditor.Tests", "Test\XmlEditor.Tests.csproj", "{FC0FE702-A87D-4D70-A9B6-1ECCD611125F}" |
||||
EndProject |
||||
Global |
||||
EndGlobal |
Loading…
Reference in new issue