Browse Source

Now using one based line and column numbers in Wix addin to match the text editor.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5283 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Matt Ward 16 years ago
parent
commit
d6475f8009
  1. 16
      src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/PackageFilesView.cs
  2. 1
      src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/SetupDialogListPad.cs
  3. 25
      src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesigner.cs
  4. 3
      src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerGenerator.cs
  5. 17
      src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentEditor.cs
  6. 10
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocumentLineSegment.cs
  7. 38
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocumentReader.cs
  8. 16
      src/AddIns/BackendBindings/WixBinding/Project/WixBinding.addin
  9. 25
      src/AddIns/BackendBindings/WixBinding/Test/Document/GetDialogElementRegionTests.cs
  10. 16
      src/AddIns/BackendBindings/WixBinding/Test/Document/GetDialogIdAtLineTestFixture.cs
  11. 12
      src/AddIns/BackendBindings/WixBinding/Test/Document/GetDirectoryElementRegionTests.cs
  12. 12
      src/AddIns/BackendBindings/WixBinding/Test/Document/GetEmptyElementDialogIdAtLineTestFixture.cs
  13. 6
      src/AddIns/BackendBindings/WixBinding/Test/Document/GetProductEndElementLocationTests.cs
  14. 13
      src/AddIns/BackendBindings/WixBinding/Test/Document/GetTwoDialogIdsFromWixDocumentTestFixture.cs
  15. 10
      src/AddIns/BackendBindings/WixBinding/Test/Document/RegionToOffsetTests.cs
  16. 4
      src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorInsertTextTestFixture.cs
  17. 4
      src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorInsertUsesTextEditorPropertiesTestFixture.cs
  18. 8
      src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorReplaceTextTestFixture.cs

16
src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/PackageFilesView.cs

@ -218,14 +218,8 @@ namespace ICSharpCode.WixBinding
return; return;
} }
// Find the product end element location. Location location = FindProductElementEndLocation(textEditor, document);
XmlElement productElement = document.GetProduct();
StringReader reader = new StringReader(textEditor.Document.Text);
string productId = productElement.GetAttribute("Id");
WixDocumentReader wixReader = new WixDocumentReader(reader);
Location location = wixReader.GetEndElementLocation("Product", productId);
if (!location.IsEmpty) { if (!location.IsEmpty) {
// Insert the xml with an extra new line at the end.
documentEditor.InsertIndented(location, String.Concat(xml, "\r\n")); documentEditor.InsertIndented(location, String.Concat(xml, "\r\n"));
} }
} }
@ -238,5 +232,13 @@ namespace ICSharpCode.WixBinding
WixDocumentEditor documentEditor = new WixDocumentEditor(textEditor); WixDocumentEditor documentEditor = new WixDocumentEditor(textEditor);
documentEditor.ReplaceElement(rootDirectoryRef.Id, WixDirectoryRefElement.DirectoryRefElementName, xml); documentEditor.ReplaceElement(rootDirectoryRef.Id, WixDirectoryRefElement.DirectoryRefElementName, xml);
} }
Location FindProductElementEndLocation(ITextEditor textEditor, WixDocument document)
{
XmlElement productElement = document.GetProduct();
string productId = productElement.GetAttribute("Id");
WixDocumentReader wixReader = new WixDocumentReader(textEditor.Document.Text);
return wixReader.GetEndElementLocation("Product", productId);
}
} }
} }

1
src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/SetupDialogListPad.cs

@ -189,7 +189,6 @@ namespace ICSharpCode.WixBinding
{ {
try { try {
setupDialogListView.BeginUpdate(); setupDialogListView.BeginUpdate();
// TODO: Intelligent updating.
ShowDialogList(); ShowDialogList();
} finally { } finally {
setupDialogListView.EndUpdate(); setupDialogListView.EndUpdate();

25
src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesigner.cs

@ -68,9 +68,9 @@ namespace ICSharpCode.WixBinding
JumpToDialogElement(id); JumpToDialogElement(id);
if (base.Host != null) { if (base.Host != null) {
// Reload so the correct dialog is displayed. // Reload so the correct dialog is displayed.
this.MergeAndUnloadDesigner(); MergeAndUnloadDesigner();
DialogId = id; DialogId = id;
this.ReloadDesignerFromMemory(); ReloadDesignerFromMemory();
} else { } else {
// Need to open the designer. // Need to open the designer.
DialogId = id; DialogId = id;
@ -148,7 +148,7 @@ namespace ICSharpCode.WixBinding
/// Gets the Wix document filename. /// Gets the Wix document filename.
/// </summary> /// </summary>
public string DocumentFileName { public string DocumentFileName {
get { return this.PrimaryFileName; } get { return PrimaryFileName; }
} }
/// <summary> /// <summary>
@ -163,19 +163,15 @@ namespace ICSharpCode.WixBinding
/// </summary> /// </summary>
public string GetDocumentXml() public string GetDocumentXml()
{ {
return this.DesignerCodeFileContent; return DesignerCodeFileContent;
} }
/// <summary> /// <summary>
/// Gets or sets the dialog id currently being designed. /// Gets or sets the dialog id currently being designed.
/// </summary> /// </summary>
public string DialogId { public string DialogId {
get { get { return dialogId; }
return dialogId; set { dialogId = value; }
}
set {
dialogId = value;
}
} }
/// <summary> /// <summary>
@ -200,8 +196,7 @@ namespace ICSharpCode.WixBinding
{ {
ITextEditor textEditor = ActiveTextEditor; ITextEditor textEditor = ActiveTextEditor;
if (textEditor != null) { if (textEditor != null) {
StringReader reader = new StringReader(textEditor.Document.Text); WixDocumentReader wixReader = new WixDocumentReader(textEditor.Document.Text);
WixDocumentReader wixReader = new WixDocumentReader(reader);
return wixReader.GetDialogId(textEditor.Caret.Line); return wixReader.GetDialogId(textEditor.Caret.Line);
} }
return null; return null;
@ -214,8 +209,7 @@ namespace ICSharpCode.WixBinding
{ {
ITextEditor textEditor = ActiveTextEditor; ITextEditor textEditor = ActiveTextEditor;
if (textEditor != null) { if (textEditor != null) {
StringReader reader = new StringReader(textEditor.Document.Text); WixDocumentReader wixReader = new WixDocumentReader(textEditor.Document.Text);
WixDocumentReader wixReader = new WixDocumentReader(reader);
ReadOnlyCollection<string> ids = wixReader.GetDialogIds(); ReadOnlyCollection<string> ids = wixReader.GetDialogIds();
if (ids.Count > 0) { if (ids.Count > 0) {
return ids[0]; return ids[0];
@ -274,8 +268,7 @@ namespace ICSharpCode.WixBinding
if (dialogId != null) { if (dialogId != null) {
ITextEditor textEditor = ActiveTextEditor; ITextEditor textEditor = ActiveTextEditor;
if (textEditor != null) { if (textEditor != null) {
StringReader reader = new StringReader(textEditor.Document.Text); WixDocumentReader wixReader = new WixDocumentReader(textEditor.Document.Text);
WixDocumentReader wixReader = new WixDocumentReader(reader);
Location location = wixReader.GetStartElementLocation("Dialog", dialogId); Location location = wixReader.GetStartElementLocation("Dialog", dialogId);
textEditor.JumpTo(location.Y, 1); textEditor.JumpTo(location.Y, 1);
} }

3
src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerGenerator.cs

@ -91,8 +91,7 @@ namespace ICSharpCode.WixBinding
DomRegion GetTextEditorRegionForDialogElement(string dialogId) DomRegion GetTextEditorRegionForDialogElement(string dialogId)
{ {
IDocument document = view.DesignerCodeFileDocument; IDocument document = view.DesignerCodeFileDocument;
StringReader reader = new StringReader(document.Text); WixDocumentReader wixReader = new WixDocumentReader(document.Text);
WixDocumentReader wixReader = new WixDocumentReader(reader);
return wixReader.GetElementRegion("Dialog", dialogId); return wixReader.GetElementRegion("Dialog", dialogId);
} }

17
src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentEditor.cs

@ -29,7 +29,6 @@ namespace ICSharpCode.WixBinding
this.document = textEditor.Document; this.document = textEditor.Document;
} }
/// <summary> /// <summary>
/// Tries to replace the element defined by element name and its Id attribute in the /// Tries to replace the element defined by element name and its Id attribute in the
/// text editor with the specified xml. /// text editor with the specified xml.
@ -39,7 +38,7 @@ namespace ICSharpCode.WixBinding
/// <param name="xml">The replacement xml.</param> /// <param name="xml">The replacement xml.</param>
public DomRegion ReplaceElement(string elementAttributeId, string elementName, string replacementXml) public DomRegion ReplaceElement(string elementAttributeId, string elementName, string replacementXml)
{ {
WixDocumentReader wixReader = new WixDocumentReader(new StringReader(document.Text)); WixDocumentReader wixReader = new WixDocumentReader(document.Text);
DomRegion region = wixReader.GetElementRegion(elementName, elementAttributeId); DomRegion region = wixReader.GetElementRegion(elementName, elementAttributeId);
if (!region.IsEmpty) { if (!region.IsEmpty) {
Replace(region, replacementXml); Replace(region, replacementXml);
@ -67,7 +66,7 @@ namespace ICSharpCode.WixBinding
int insertedCharacterCount = IndentAllLinesTheSame(region.BeginLine + 1, region.EndLine + addedLineCount, initialIndent); int insertedCharacterCount = IndentAllLinesTheSame(region.BeginLine + 1, region.EndLine + addedLineCount, initialIndent);
// Make sure the text inserted is visible. // Make sure the text inserted is visible.
textEditor.JumpTo(region.BeginLine + 1, 1); textEditor.JumpTo(region.BeginLine, 1);
// Select the text just inserted. // Select the text just inserted.
int textInsertedLength = insertedCharacterCount + xml.Length; int textInsertedLength = insertedCharacterCount + xml.Length;
@ -84,16 +83,16 @@ namespace ICSharpCode.WixBinding
/// Inserts and indents the xml at the specified location. /// Inserts and indents the xml at the specified location.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// Lines and columns are zero based. /// Lines and columns are one based.
/// </remarks> /// </remarks>
public void InsertIndented(int line, int column, string xml) public void InsertIndented(int line, int column, string xml)
{ {
using (textEditor.Document.OpenUndoGroup()) { using (textEditor.Document.OpenUndoGroup()) {
// Insert the xml and indent it. // Insert the xml and indent it.
IDocumentLine documentLine = document.GetLine(line + 1); IDocumentLine documentLine = document.GetLine(line);
int initialIndent = GetIndent(line); int initialIndent = GetIndent(line);
int offset = documentLine.Offset + column; int offset = documentLine.Offset + column - 1;
int originalLineCount = document.TotalNumberOfLines; int originalLineCount = document.TotalNumberOfLines;
document.Insert(offset, xml); document.Insert(offset, xml);
int addedLineCount = document.TotalNumberOfLines - originalLineCount; int addedLineCount = document.TotalNumberOfLines - originalLineCount;
@ -102,7 +101,7 @@ namespace ICSharpCode.WixBinding
int insertedCharacterCount = IndentLines(line, line + addedLineCount, initialIndent); int insertedCharacterCount = IndentLines(line, line + addedLineCount, initialIndent);
// Make sure the text inserted is visible. // Make sure the text inserted is visible.
textEditor.JumpTo(line + 1, 1); textEditor.JumpTo(line, 1);
// Select the text just inserted. // Select the text just inserted.
int textInsertedLength = xml.Length + insertedCharacterCount; int textInsertedLength = xml.Length + insertedCharacterCount;
@ -158,13 +157,13 @@ namespace ICSharpCode.WixBinding
string GetLineAsString(int line) string GetLineAsString(int line)
{ {
IDocumentLine documentLine = document.GetLine(line + 1); IDocumentLine documentLine = document.GetLine(line);
return documentLine.Text; return documentLine.Text;
} }
int IndentLine(int line, int howManyIndents) int IndentLine(int line, int howManyIndents)
{ {
IDocumentLine documentLine = document.GetLine(line + 1); IDocumentLine documentLine = document.GetLine(line);
int offset = documentLine.Offset; int offset = documentLine.Offset;
string indentationString = GetIndentationString(howManyIndents); string indentationString = GetIndentationString(howManyIndents);

10
src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocumentLineSegment.cs

@ -67,9 +67,9 @@ namespace ICSharpCode.WixBinding
static WixDocumentLineSegment ConvertRegionToSingleLineSegment(IDocument document, DomRegion region) static WixDocumentLineSegment ConvertRegionToSingleLineSegment(IDocument document, DomRegion region)
{ {
IDocumentLine documentLine = document.GetLine(region.BeginLine + 1); IDocumentLine documentLine = document.GetLine(region.BeginLine);
return new WixDocumentLineSegment(documentLine.Offset + region.BeginColumn, return new WixDocumentLineSegment(documentLine.Offset + region.BeginColumn - 1,
region.EndColumn + 1 - region.BeginColumn); region.EndColumn - region.BeginColumn + 1);
} }
static WixDocumentLineSegment ConvertRegionToMultiLineSegment(IDocument document, DomRegion region) static WixDocumentLineSegment ConvertRegionToMultiLineSegment(IDocument document, DomRegion region)
@ -77,10 +77,10 @@ namespace ICSharpCode.WixBinding
int length = 0; int length = 0;
int startOffset = 0; int startOffset = 0;
for (int line = region.BeginLine; line <= region.EndLine; ++line) { for (int line = region.BeginLine; line <= region.EndLine; ++line) {
IDocumentLine currentDocumentLine = document.GetLine(line + 1); IDocumentLine currentDocumentLine = document.GetLine(line);
if (line == region.BeginLine) { if (line == region.BeginLine) {
length += currentDocumentLine.TotalLength - region.BeginColumn; length += currentDocumentLine.TotalLength - region.BeginColumn;
startOffset = currentDocumentLine.Offset + region.BeginColumn; startOffset = currentDocumentLine.Offset + region.BeginColumn - 1;
} else if (line < region.EndLine) { } else if (line < region.EndLine) {
length += currentDocumentLine.TotalLength; length += currentDocumentLine.TotalLength;
} else { } else {

38
src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocumentReader.cs

@ -43,6 +43,11 @@ namespace ICSharpCode.WixBinding
} }
} }
public WixDocumentReader(string document)
: this(new StringReader(document))
{
}
public WixDocumentReader(TextReader textReader) public WixDocumentReader(TextReader textReader)
{ {
reader = new XmlTextReader(textReader); reader = new XmlTextReader(textReader);
@ -127,8 +132,8 @@ namespace ICSharpCode.WixBinding
{ {
// Store the column and line position since the call to GetIdFromCurrentNode will // Store the column and line position since the call to GetIdFromCurrentNode will
// move to the <Dialog> Id attribute. // move to the <Dialog> Id attribute.
int line = reader.LineNumber - 1; int line = reader.LineNumber;
int column = reader.LinePosition - 2; // Take off 2 to so the '<' is located. int column = reader.LinePosition - 1; // Take off 1 to so the '<' is located.
if (idAttributeValue == GetIdAttributeValueFromCurrentNode()) { if (idAttributeValue == GetIdAttributeValueFromCurrentNode()) {
return new Location(column, line); return new Location(column, line);
@ -136,9 +141,12 @@ namespace ICSharpCode.WixBinding
return Location.Empty; return Location.Empty;
} }
/// <summary>
/// Location line numbers are one based.
/// </summary>
public Location GetEndElementLocation(string name, string id) public Location GetEndElementLocation(string name, string id)
{ {
using (reader) { using (reader) {
bool startElementFound = false; bool startElementFound = false;
object elementName = reader.NameTable.Add(name); object elementName = reader.NameTable.Add(name);
while (reader.Read()) { while (reader.Read()) {
@ -154,7 +162,7 @@ namespace ICSharpCode.WixBinding
if (IsElementMatch(elementName, reader.LocalName)) { if (IsElementMatch(elementName, reader.LocalName)) {
// Take off an extra 2 from the line position so we get the // Take off an extra 2 from the line position so we get the
// correct column for the < tag rather than the element name. // correct column for the < tag rather than the element name.
return new Location(reader.LinePosition - 3, reader.LineNumber - 1); return new Location(reader.LinePosition - 2, reader.LineNumber);
} }
} }
break; break;
@ -167,15 +175,12 @@ namespace ICSharpCode.WixBinding
/// <summary> /// <summary>
/// Gets the dialog id at the specified line. /// Gets the dialog id at the specified line.
/// </summary> /// </summary>
/// <param name="index">Line numbers start from zero.</param> /// <param name="index">Line numbers start from one.</param>
public string GetDialogId(int line) public string GetDialogId(int line)
{ {
// Add one to line since XmlTextReader line numbers start from one.
++line;
DialogStartElement dialogStartElement = null; DialogStartElement dialogStartElement = null;
using (reader) { using (reader) {
object dialogElementName = reader.NameTable.Add("Dialog"); object dialogElementName = reader.NameTable.Add("Dialog");
while (reader.Read()) { while (reader.Read()) {
switch (reader.NodeType) { switch (reader.NodeType) {
@ -209,6 +214,9 @@ namespace ICSharpCode.WixBinding
/// containing the start tag and the end column is the column containing the final /// containing the start tag and the end column is the column containing the final
/// end tag marker. /// end tag marker.
/// </summary> /// </summary>
/// <remarks>
/// The lines and columns in the region are one based.
/// </remarks>
/// <param name="name">The name of the element.</param> /// <param name="name">The name of the element.</param>
/// <param name="id">The id attribute value of the element.</param> /// <param name="id">The id attribute value of the element.</param>
public DomRegion GetElementRegion(string name, string id) public DomRegion GetElementRegion(string name, string id)
@ -260,11 +268,11 @@ namespace ICSharpCode.WixBinding
Location GetEmptyElementEnd() Location GetEmptyElementEnd()
{ {
reader.ReadStartElement(); reader.ReadStartElement();
int line = reader.LineNumber - 1; int line = reader.LineNumber;
// Take off two as we have moved passed the end tag // Take off one as we have moved passed the end tag
// column. // column.
int column = reader.LinePosition - 2; int column = reader.LinePosition - 1;
return new Location(column, line); return new Location(column, line);
} }
@ -276,10 +284,10 @@ namespace ICSharpCode.WixBinding
Location GetEndElementEnd() Location GetEndElementEnd()
{ {
reader.ReadEndElement(); reader.ReadEndElement();
int line = reader.LineNumber - 1; int line = reader.LineNumber;
// Take off two as we have moved passed the end tag column. // Take off one as we have moved passed the end tag column.
int column = reader.LinePosition - 2; int column = reader.LinePosition - 1;
// If ReadEndElement has moved to the start of another element // If ReadEndElement has moved to the start of another element
// take off one from the column value otherwise the column // take off one from the column value otherwise the column

16
src/AddIns/BackendBindings/WixBinding/Project/WixBinding.addin

@ -72,7 +72,7 @@
</Path> </Path>
<Path name = "/SharpDevelop/Workbench/ProjectBindings"> <Path name = "/SharpDevelop/Workbench/ProjectBindings">
<ProjectBinding id = "Wix" <ProjectBinding id = "Wix"
guid = "{CFEE4113-1246-4D54-95CB-156813CB8593}" guid = "{CFEE4113-1246-4D54-95CB-156813CB8593}"
supportedextensions = ".wxs" supportedextensions = ".wxs"
projectfileextension = ".wixproj" projectfileextension = ".wixproj"
@ -158,11 +158,11 @@
</Path> </Path>
<Path name = "/SharpDevelop/Workbench/Pads"> <Path name = "/SharpDevelop/Workbench/Pads">
<Pad id = "WixSetupDialogListPad" <Pad id = "WixSetupDialogListPad"
category = "Setup" category = "Setup"
title = "${res:ICSharpCode.WixBinding.SetupDialogListPad.Title}" title = "${res:ICSharpCode.WixBinding.SetupDialogListPad.Title}"
icon = "Setup.Icons.16x16.SetupDialogsPad" icon = "Setup.Icons.16x16.SetupDialogsPad"
class = "ICSharpCode.WixBinding.SetupDialogListPad" class = "ICSharpCode.WixBinding.SetupDialogListPad"
defaultPosition = "Bottom, Hidden" /> defaultPosition = "Bottom, Hidden" />
</Path> </Path>
@ -171,7 +171,7 @@
<MenuItem id = "OpenDialog" <MenuItem id = "OpenDialog"
icon = "Icons.16x16.OpenFileIcon" icon = "Icons.16x16.OpenFileIcon"
label = "${res:ProjectComponent.ContextMenu.Open}" label = "${res:ProjectComponent.ContextMenu.Open}"
class = "ICSharpCode.WixBinding.OpenDialogCommand"/> class = "ICSharpCode.WixBinding.OpenDialogCommand"/>
<MenuItem id = "ViewCode" <MenuItem id = "ViewCode"
label = "${res:SharpDevelop.FormsDesigner.ContextMenus.ViewCodeCommand}" label = "${res:SharpDevelop.FormsDesigner.ContextMenus.ViewCodeCommand}"
icon = "Icons.16x16.FormsDesigner.ViewCode" icon = "Icons.16x16.FormsDesigner.ViewCode"
@ -182,7 +182,7 @@
<Path name = "/SharpDevelop/Workbench/DisplayBindings"> <Path name = "/SharpDevelop/Workbench/DisplayBindings">
<DisplayBinding id = "WixDialogDesigner" <DisplayBinding id = "WixDialogDesigner"
type = "Secondary" type = "Secondary"
class = "ICSharpCode.WixBinding.WixDialogDesignerDisplayBinding" class = "ICSharpCode.WixBinding.WixDialogDesignerDisplayBinding"
fileNamePattern = "\.(wxs|wxi)$"/> fileNamePattern = "\.(wxs|wxi)$"/>
</Path> </Path>

25
src/AddIns/BackendBindings/WixBinding/Test/Document/GetDialogElementRegionTests.cs

@ -33,10 +33,10 @@ namespace WixBinding.Tests.Document
"\t\t</UI>\r\n" + "\t\t</UI>\r\n" +
"\t</Fragment>\r\n" + "\t</Fragment>\r\n" +
"</Wix>"; "</Wix>";
StringReader reader = new StringReader(xml);
WixDocumentReader wixReader = new WixDocumentReader(reader); WixDocumentReader wixReader = new WixDocumentReader(xml);
DomRegion region = wixReader.GetElementRegion("Dialog", "WelcomeDialog"); DomRegion region = wixReader.GetElementRegion("Dialog", "WelcomeDialog");
DomRegion expectedRegion = new DomRegion(3, 3, 4, 11); DomRegion expectedRegion = new DomRegion(4, 4, 5, 12);
Assert.AreEqual(expectedRegion, region); Assert.AreEqual(expectedRegion, region);
} }
@ -50,9 +50,10 @@ namespace WixBinding.Tests.Document
"\t\t</UI>\r\n" + "\t\t</UI>\r\n" +
"\t</Fragment>\r\n" + "\t</Fragment>\r\n" +
"</Wix>"; "</Wix>";
WixDocumentReader wixReader = new WixDocumentReader(new StringReader(xml));
WixDocumentReader wixReader = new WixDocumentReader(xml);
DomRegion region = wixReader.GetElementRegion("Dialog", "WelcomeDialog"); DomRegion region = wixReader.GetElementRegion("Dialog", "WelcomeDialog");
DomRegion expectedRegion = new DomRegion(3, 0, 3, 35); DomRegion expectedRegion = new DomRegion(4, 1, 4, 36);
Assert.AreEqual(expectedRegion, region); Assert.AreEqual(expectedRegion, region);
} }
@ -66,9 +67,10 @@ namespace WixBinding.Tests.Document
"\t\t</UI>\r\n" + "\t\t</UI>\r\n" +
"\t</Fragment>\r\n" + "\t</Fragment>\r\n" +
"</Wix>"; "</Wix>";
WixDocumentReader wixReader = new WixDocumentReader(new StringReader(xml));
WixDocumentReader wixReader = new WixDocumentReader(xml);
DomRegion region = wixReader.GetElementRegion("Dialog", "WelcomeDialog"); DomRegion region = wixReader.GetElementRegion("Dialog", "WelcomeDialog");
DomRegion expectedRegion = new DomRegion(3, 0, 3, 27); DomRegion expectedRegion = new DomRegion(4, 1, 4, 28);
Assert.AreEqual(expectedRegion, region); Assert.AreEqual(expectedRegion, region);
} }
@ -82,9 +84,10 @@ namespace WixBinding.Tests.Document
"\t\t</UI>\r\n" + "\t\t</UI>\r\n" +
"\t</Fragment>\r\n" + "\t</Fragment>\r\n" +
"</Wix>"; "</Wix>";
WixDocumentReader wixReader = new WixDocumentReader(new StringReader(xml));
WixDocumentReader wixReader = new WixDocumentReader(xml);
DomRegion region = wixReader.GetElementRegion("Dialog", "WelcomeDialog"); DomRegion region = wixReader.GetElementRegion("Dialog", "WelcomeDialog");
DomRegion expectedRegion = new DomRegion(3, 0, 3, 35); DomRegion expectedRegion = new DomRegion(4, 1, 4, 36);
Assert.AreEqual(expectedRegion, region); Assert.AreEqual(expectedRegion, region);
} }
@ -101,9 +104,9 @@ namespace WixBinding.Tests.Document
"\t\t</UI>\r\n" + "\t\t</UI>\r\n" +
"\t</Fragment>\r\n" + "\t</Fragment>\r\n" +
"</Wix>"; "</Wix>";
WixDocumentReader wixReader = new WixDocumentReader(new StringReader(xml)); WixDocumentReader wixReader = new WixDocumentReader(xml);
DomRegion region = wixReader.GetElementRegion("Dialog", "WelcomeDialog"); DomRegion region = wixReader.GetElementRegion("Dialog", "WelcomeDialog");
DomRegion expectedRegion = new DomRegion(5, 3, 6, 11); DomRegion expectedRegion = new DomRegion(6, 4, 7, 12);
Assert.AreEqual(expectedRegion, region); Assert.AreEqual(expectedRegion, region);
} }
} }

16
src/AddIns/BackendBindings/WixBinding/Test/Document/GetDialogIdAtLineTestFixture.cs

@ -21,51 +21,49 @@ namespace WixBinding.Tests.Document
[TestFixture] [TestFixture]
public class GetDialogIdAtLineTestFixture public class GetDialogIdAtLineTestFixture
{ {
StringReader reader;
string expectedDialogId = "WelcomeDialog"; string expectedDialogId = "WelcomeDialog";
WixDocumentReader wixReader; WixDocumentReader wixReader;
[SetUp] [SetUp]
public void SetUpFixture() public void SetUpFixture()
{ {
reader = new StringReader(GetWixXml()); wixReader = new WixDocumentReader(GetWixXml());
wixReader = new WixDocumentReader(reader);
} }
[Test] [Test]
public void OnDialogStartTagLine() public void OnDialogStartTagLine()
{ {
Assert.AreEqual(expectedDialogId, wixReader.GetDialogId(8)); Assert.AreEqual(expectedDialogId, wixReader.GetDialogId(9));
} }
[Test] [Test]
public void StartOfDocument() public void StartOfDocument()
{ {
Assert.IsNull(wixReader.GetDialogId(0)); Assert.IsNull(wixReader.GetDialogId(1));
} }
[Test] [Test]
public void LineBeforeDialogStartTag() public void LineBeforeDialogStartTag()
{ {
Assert.IsNull(wixReader.GetDialogId(7)); Assert.IsNull(wixReader.GetDialogId(8));
} }
[Test] [Test]
public void FirstLineAfterDialogStartTag() public void FirstLineAfterDialogStartTag()
{ {
Assert.AreEqual(expectedDialogId, wixReader.GetDialogId(9)); Assert.AreEqual(expectedDialogId, wixReader.GetDialogId(10));
} }
[Test] [Test]
public void DialogEndTagLine() public void DialogEndTagLine()
{ {
Assert.AreEqual(expectedDialogId, wixReader.GetDialogId(15)); Assert.AreEqual(expectedDialogId, wixReader.GetDialogId(16));
} }
[Test] [Test]
public void FirstLineAfterDialogEndTag() public void FirstLineAfterDialogEndTag()
{ {
Assert.IsNull(wixReader.GetDialogId(16)); Assert.IsNull(wixReader.GetDialogId(17));
} }
string GetWixXml() string GetWixXml()

12
src/AddIns/BackendBindings/WixBinding/Test/Document/GetDirectoryElementRegionTests.cs

@ -31,9 +31,9 @@ namespace WixBinding.Tests.Document
"\t\t</Directory>\r\n" + "\t\t</Directory>\r\n" +
"\t</Fragment>\r\n" + "\t</Fragment>\r\n" +
"</Wix>"; "</Wix>";
WixDocumentReader wixReader = new WixDocumentReader(new StringReader(xml)); WixDocumentReader wixReader = new WixDocumentReader(xml);
DomRegion region = wixReader.GetElementRegion("Directory", "TARGETDIR"); DomRegion region = wixReader.GetElementRegion("Directory", "TARGETDIR");
DomRegion expectedRegion = new DomRegion(2, 2, 3, 13); DomRegion expectedRegion = new DomRegion(3, 3, 4, 14);
Assert.AreEqual(expectedRegion, region); Assert.AreEqual(expectedRegion, region);
} }
@ -48,9 +48,9 @@ namespace WixBinding.Tests.Document
"\t\t</Directory>\r\n" + "\t\t</Directory>\r\n" +
"\t</Fragment>\r\n" + "\t</Fragment>\r\n" +
"</Wix>"; "</Wix>";
WixDocumentReader wixReader = new WixDocumentReader(new StringReader(xml)); WixDocumentReader wixReader = new WixDocumentReader(xml);
DomRegion region = wixReader.GetElementRegion("Directory", "TARGETDIR"); DomRegion region = wixReader.GetElementRegion("Directory", "TARGETDIR");
DomRegion expectedRegion = new DomRegion(2, 2, 5, 13); DomRegion expectedRegion = new DomRegion(3, 3, 6, 14);
Assert.AreEqual(expectedRegion, region); Assert.AreEqual(expectedRegion, region);
} }
@ -64,9 +64,9 @@ namespace WixBinding.Tests.Document
"\t\t</Directory>\r\n" + "\t\t</Directory>\r\n" +
"\t</Fragment>\r\n" + "\t</Fragment>\r\n" +
"</Wix>"; "</Wix>";
WixDocumentReader wixReader = new WixDocumentReader(new StringReader(xml)); WixDocumentReader wixReader = new WixDocumentReader(xml);
DomRegion region = wixReader.GetElementRegion("Directory", "TARGETDIR"); DomRegion region = wixReader.GetElementRegion("Directory", "TARGETDIR");
DomRegion expectedRegion = new DomRegion(2, 2, 4, 13); DomRegion expectedRegion = new DomRegion(3, 3, 5, 14);
Assert.AreEqual(expectedRegion, region); Assert.AreEqual(expectedRegion, region);
} }
} }

12
src/AddIns/BackendBindings/WixBinding/Test/Document/GetEmptyElementDialogIdAtLineTestFixture.cs

@ -21,39 +21,37 @@ namespace WixBinding.Tests.Document
[TestFixture] [TestFixture]
public class GetEmptyElementDialogIdAtLineTestFixture public class GetEmptyElementDialogIdAtLineTestFixture
{ {
StringReader reader;
string expectedDialogId = "WelcomeDialog"; string expectedDialogId = "WelcomeDialog";
WixDocumentReader wixReader; WixDocumentReader wixReader;
[SetUp] [SetUp]
public void SetUpFixture() public void SetUpFixture()
{ {
reader = new StringReader(GetWixXml()); wixReader = new WixDocumentReader(GetWixXml());
wixReader = new WixDocumentReader(reader);
} }
[Test] [Test]
public void OnDialogStartTagLine() public void OnDialogStartTagLine()
{ {
Assert.AreEqual(expectedDialogId, wixReader.GetDialogId(8)); Assert.AreEqual(expectedDialogId, wixReader.GetDialogId(9));
} }
[Test] [Test]
public void StartOfDocument() public void StartOfDocument()
{ {
Assert.IsNull(wixReader.GetDialogId(0)); Assert.IsNull(wixReader.GetDialogId(1));
} }
[Test] [Test]
public void LineBeforeDialogStartTag() public void LineBeforeDialogStartTag()
{ {
Assert.IsNull(wixReader.GetDialogId(7)); Assert.IsNull(wixReader.GetDialogId(8));
} }
[Test] [Test]
public void LineAfterDialogStartTag() public void LineAfterDialogStartTag()
{ {
Assert.IsNull(wixReader.GetDialogId(9)); Assert.IsNull(wixReader.GetDialogId(10));
} }
string GetWixXml() string GetWixXml()

6
src/AddIns/BackendBindings/WixBinding/Test/Document/GetProductEndElementLocationTests.cs

@ -33,9 +33,9 @@ namespace WixBinding.Tests.Document
"\t Id='????????-????-????-????-????????????'>\r\n" + "\t Id='????????-????-????-????-????????????'>\r\n" +
"\t</Product>\r\n" + "\t</Product>\r\n" +
"</Wix>"; "</Wix>";
WixDocumentReader wixReader = new WixDocumentReader(new StringReader(xml)); WixDocumentReader wixReader = new WixDocumentReader(xml);
Location location = wixReader.GetEndElementLocation("Product", "????????-????-????-????-????????????"); Location location = wixReader.GetEndElementLocation("Product", "????????-????-????-????-????????????");
Location expectedLocation = new Location(1, 6); Location expectedLocation = new Location(2, 7);
Assert.AreEqual(expectedLocation, location); Assert.AreEqual(expectedLocation, location);
} }
@ -52,7 +52,7 @@ namespace WixBinding.Tests.Document
"\t Manufacturer='#develop' \r\n" + "\t Manufacturer='#develop' \r\n" +
"\t Id='????????-????-????-????-????????????'/>\r\n" + "\t Id='????????-????-????-????-????????????'/>\r\n" +
"</Wix>"; "</Wix>";
WixDocumentReader wixReader = new WixDocumentReader(new StringReader(xml)); WixDocumentReader wixReader = new WixDocumentReader(xml);
Location location = wixReader.GetEndElementLocation("Product", "????????-????-????-????-????????????"); Location location = wixReader.GetEndElementLocation("Product", "????????-????-????-????-????????????");
Location expectedLocation = Location.Empty; Location expectedLocation = Location.Empty;
Assert.AreEqual(expectedLocation, location); Assert.AreEqual(expectedLocation, location);

13
src/AddIns/BackendBindings/WixBinding/Test/Document/GetTwoDialogIdsFromWixDocumentTestFixture.cs

@ -34,18 +34,15 @@ namespace WixBinding.Tests.Document
[TestFixtureSetUpAttribute] [TestFixtureSetUpAttribute]
public void SetUpFixture() public void SetUpFixture()
{ {
StringReader reader = new StringReader(GetWixXml()); WixDocumentReader wixReader = new WixDocumentReader(GetWixXml());
WixDocumentReader wixReader = new WixDocumentReader(reader);
dialogIds = wixReader.GetDialogIds(); dialogIds = wixReader.GetDialogIds();
welcomeDialogId = dialogIds[0]; welcomeDialogId = dialogIds[0];
progressDialogId = dialogIds[1]; progressDialogId = dialogIds[1];
reader = new StringReader(GetWixXml()); wixReader = new WixDocumentReader(GetWixXml());
wixReader = new WixDocumentReader(reader);
welcomeDialogLocation = wixReader.GetStartElementLocation("Dialog", welcomeDialogId); welcomeDialogLocation = wixReader.GetStartElementLocation("Dialog", welcomeDialogId);
reader = new StringReader(GetWixXml()); wixReader = new WixDocumentReader(GetWixXml());
wixReader = new WixDocumentReader(reader);
missingDialogLocation = wixReader.GetStartElementLocation("Dialog", "missingDialogId"); missingDialogLocation = wixReader.GetStartElementLocation("Dialog", "missingDialogId");
} }
@ -70,13 +67,13 @@ namespace WixBinding.Tests.Document
[Test] [Test]
public void WelcomeDialogElementLine() public void WelcomeDialogElementLine()
{ {
Assert.AreEqual(8, welcomeDialogLocation.Y); Assert.AreEqual(9, welcomeDialogLocation.Y);
} }
[Test] [Test]
public void WelcomeDialogElementColumn() public void WelcomeDialogElementColumn()
{ {
Assert.AreEqual(3, welcomeDialogLocation.X); Assert.AreEqual(4, welcomeDialogLocation.X);
} }
[Test] [Test]

10
src/AddIns/BackendBindings/WixBinding/Test/Document/RegionToOffsetTests.cs

@ -29,7 +29,7 @@ namespace WixBinding.Tests.Document
[Test] [Test]
public void SingleLineRegionConvertedToSegment() public void SingleLineRegionConvertedToSegment()
{ {
DomRegion region = new DomRegion(0, 0, 0, 5); DomRegion region = new DomRegion(1, 1, 1, 6);
document.Text = "1234567890"; document.Text = "1234567890";
WixDocumentLineSegment segment = WixDocumentLineSegment.ConvertRegionToSegment(document, region); WixDocumentLineSegment segment = WixDocumentLineSegment.ConvertRegionToSegment(document, region);
@ -41,7 +41,7 @@ namespace WixBinding.Tests.Document
[Test] [Test]
public void TwoLineRegionConvertedToSegment() public void TwoLineRegionConvertedToSegment()
{ {
DomRegion region = new DomRegion(0, 1, 1, 0); DomRegion region = new DomRegion(1, 2, 2, 1);
document.Text = "1234567890\r\n1234567890"; document.Text = "1234567890\r\n1234567890";
WixDocumentLineSegment segment = WixDocumentLineSegment.ConvertRegionToSegment(document, region); WixDocumentLineSegment segment = WixDocumentLineSegment.ConvertRegionToSegment(document, region);
@ -53,7 +53,7 @@ namespace WixBinding.Tests.Document
[Test] [Test]
public void ThreeLineRegionConvertedToSegment() public void ThreeLineRegionConvertedToSegment()
{ {
DomRegion region = new DomRegion(0, 2, 2, 1); DomRegion region = new DomRegion(1, 3, 3, 2);
document.Text = "1234567890\r\n1234567890\r\n1234567890"; document.Text = "1234567890\r\n1234567890\r\n1234567890";
WixDocumentLineSegment segment = WixDocumentLineSegment.ConvertRegionToSegment(document, region); WixDocumentLineSegment segment = WixDocumentLineSegment.ConvertRegionToSegment(document, region);
@ -65,7 +65,7 @@ namespace WixBinding.Tests.Document
[Test] [Test]
public void ThreeLineRegionWithoutCarriageReturnConvertedToSegment() public void ThreeLineRegionWithoutCarriageReturnConvertedToSegment()
{ {
DomRegion region = new DomRegion(0, 2, 2, 1); DomRegion region = new DomRegion(1, 3, 3, 2);
document.Text = "1234567890\n1234567890\n1234567890"; document.Text = "1234567890\n1234567890\n1234567890";
WixDocumentLineSegment segment = WixDocumentLineSegment.ConvertRegionToSegment(document, region); WixDocumentLineSegment segment = WixDocumentLineSegment.ConvertRegionToSegment(document, region);
@ -77,7 +77,7 @@ namespace WixBinding.Tests.Document
[Test] [Test]
public void RegionWithBeginLineOnSecondLineConvertedToSegment() public void RegionWithBeginLineOnSecondLineConvertedToSegment()
{ {
DomRegion region = new DomRegion(1, 0, 2, 0); DomRegion region = new DomRegion(2, 1, 3, 1);
document.Text = "1234567890\r\n1234567890\r\n1234567890"; document.Text = "1234567890\r\n1234567890\r\n1234567890";
WixDocumentLineSegment segment = WixDocumentLineSegment.ConvertRegionToSegment(document, region); WixDocumentLineSegment segment = WixDocumentLineSegment.ConvertRegionToSegment(document, region);

4
src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorInsertTextTestFixture.cs

@ -45,8 +45,8 @@ namespace WixBinding.Tests.Gui
"<new-child>\r\n" + "<new-child>\r\n" +
"</new-child>\r\n"; "</new-child>\r\n";
int line = 2; int line = 3;
int column = 1; int column = 2;
editor.InsertIndented(line, column, xmlToInsert); editor.InsertIndented(line, column, xmlToInsert);
document = textEditor.Document; document = textEditor.Document;

4
src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorInsertUsesTextEditorPropertiesTestFixture.cs

@ -45,8 +45,8 @@ namespace WixBinding.Tests.Gui
"<new-child>\r\n" + "<new-child>\r\n" +
"</new-child>\r\n"; "</new-child>\r\n";
int line = 2; int line = 3;
int column = 4; int column = 5;
editor.InsertIndented(line, column, xmlToInsert); editor.InsertIndented(line, column, xmlToInsert);
document = textEditor.Document; document = textEditor.Document;

8
src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorReplaceTextTestFixture.cs

@ -48,12 +48,12 @@ namespace WixBinding.Tests.Gui
"<new-child>\r\n" + "<new-child>\r\n" +
"</new-child>"; "</new-child>";
int line = 1; int line = 2;
int column = 1; int column = 2;
int endLine = 2; int endLine = 3;
// End column is the column containing the '>' of the </child> element. // End column is the column containing the '>' of the </child> element.
int endColumn = 8; int endColumn = 9;
DomRegion region = new DomRegion(line, column, endLine, endColumn); DomRegion region = new DomRegion(line, column, endLine, endColumn);

Loading…
Cancel
Save