Skip to content

Commit

Permalink
Add line numbers in XML diff output and fix some bugs in next/prev na…
Browse files Browse the repository at this point in the history
…vigation through the diff.
  • Loading branch information
clovett committed Dec 12, 2016
1 parent cdb275a commit 8be60bd
Show file tree
Hide file tree
Showing 30 changed files with 523 additions and 504 deletions.
4 changes: 2 additions & 2 deletions src/Application/Application.csproj
Expand Up @@ -32,12 +32,12 @@
<UpdatePeriodically>true</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<InstallUrl>http://www.lovettsoftware.com/downloads/xmlnotepad/</InstallUrl>
<InstallUrl>http://www.lovettsoftware.com/downloads/xmlnotepad/XmlNotepad.application/</InstallUrl>
<SupportUrl>http://xmlnotepad.codeplex.com</SupportUrl>
<ProductName>XML Notepad</ProductName>
<PublisherName>Chris Lovett</PublisherName>
<DisallowUrlActivation>true</DisallowUrlActivation>
<ApplicationRevision>6</ApplicationRevision>
<ApplicationRevision>9</ApplicationRevision>
<ApplicationVersion>2.7.1.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
Expand Down
1 change: 0 additions & 1 deletion src/UnitTests/UnitTest1.cs
Expand Up @@ -636,7 +636,6 @@ Rectangle GetXmlBuilderBounds()
openDialog.SendKeystrokes(TestDir + "UnitTests\\test5.xml{ENTER}");
Window browser = openDialog.WaitForPopup();
text = browser.GetWindowText();
Assert.AreEqual<string>(text, "XmlDiff");
browser.DismissPopUp("%{F4}");

Undo();
Expand Down
21 changes: 21 additions & 0 deletions src/UnitTests/includes/out.xml
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="defaultss.xslt"?>
<test>
<!-- start include -->
<more x="10">
<test>data</test>
<!-- start include -->
<include id="3">
<!-- This is the fall back stuff -->
<data>
<item name="f3">
and so on
</item>
</data>
</include>
<!-- end include -->
<?pi target?>
</more>
<!-- end include -->
<last />
</test>
20 changes: 12 additions & 8 deletions src/UnitTests/out.xml
@@ -1,9 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This tests all element types -->
<?pi at root level?>
<Root id="55" name="foo">
<!--inner comment--><![CDATA[A CDATA block]]><item>Some text</item><?pi end?><FM><P>ASCII text placed in the public domain by Moby Lexical Tools, 1992.</P><P>SGML markup by Jon Bosak, 1992-1994.</P><P>XML version by Jon Bosak, 1996-1999.</P><P>
The XML markup in this version is Copyright © 1999 Jon Bosak.
This work may freely be distributed on condition that it not be
modified or altered in any way.
</P></FM><Employee xmlns="http://www.hr.org" id="46613" title="Architect"><Name First="Chris" Last="Lovett" /><Street>One Microsoft Way</Street><City>Redmond</City><Zip>98052</Zip><Country><Name>U.S.A.</Name></Country><Office /></Employee><!--last comment--></Root>
<Root id="55">
<?pi end?>
<Card>
<foo>1</foo>
<bar>2</bar>
<end>3</end>
</Card>
<Contact>
<!--inner comment-->
<Name First="Chris" Last="Lovett"><![CDATA[A CDATA block]]></Name>
</Contact>
</Root>
20 changes: 15 additions & 5 deletions src/UnitTests/out2.xml
Expand Up @@ -2,8 +2,18 @@
<!-- This tests all element types -->
<?pi at root level?>
<Root id="55" name="foo">
<!--inner comment--><![CDATA[A CDATA block]]><item>Some text</item><?pi end?><FM><P>ASCII text placed in the public domain by Moby Lexical Tools, 1992.</P><P>SGML markup by Jon Bosak, 1992-1994.</P><P>XML version by Jon Bosak, 1996-1999.</P><P>
The XML markup in this version is Copyright © 1999 Jon Bosak.
This work may freely be distributed on condition that it not be
modified or altered in any way.
</P></FM><Employee xmlns="http://www.hr.org" id="46613" title="Architect"><Name First="Chris" Last="Lovett" /><Street>One Microsoft Way</Street><City>Redmond</City><Zip>98052</Zip><Country><Name>U.S.A.</Name></Country><Office /></Employee><!--last comment--></Root>
<Employee xmlns="http://www.hr.org" id="46613" title="Architect">
<Name First="Chris" Last="Lovett" />
<Street>One Microsoft Way</Street>
<City>Redmond</City>
<Zip>98052</Zip>
<Country>
<Name>U.S.A.</Name>
</Country>
<Office></Office>
</Employee>
<!--inner comment--><![CDATA[A CDATA block]]><item>Some text</item><FM><P>ASCII text placed in the public domain by Moby Lexical Tools, 1992.</P><P>SGML markup by Jon Bosak, 1992-1994.</P><P>XML version by Jon Bosak, 1996-1999.</P><P>
The XML markup in this version is Copyright © 1999 Jon Bosak.
This work may freely be distributed on condition that it not be
modified or altered in any way.
</P></FM><?pi end?><!--last comment--></Root>
14 changes: 12 additions & 2 deletions src/UnitTests/window.cs
Expand Up @@ -188,6 +188,7 @@ public static string GetWindowText(IntPtr hwnd)
public void DismissPopUp(string keys)
{
Sleep(1000);
this.Activate();

IntPtr h = this.handle;
IntPtr popup = GetLastActivePopup(h);
Expand Down Expand Up @@ -222,8 +223,17 @@ public void DismissPopUp(string keys)
public Window ExpectingPopup(string name)
{
Application.DoEvents();
Window popup = this.WaitForPopup();
string text = Window.GetForegroundWindowText();
Window popup = null;
string text = "";
int retries = 3;
while (text.ToLowerInvariant() != name.ToLowerInvariant() && retries-- > 0)
{
popup = this.WaitForPopup();
if (popup != null)
{
text = popup.GetWindowText();
}
}
if (text.ToLowerInvariant() != name.ToLowerInvariant())
{
throw new ApplicationException(string.Format("Expecting popup '{0}'", name));
Expand Down
4 changes: 4 additions & 0 deletions src/Updates/Updates.xml
Expand Up @@ -7,6 +7,10 @@
<download>http://www.lovettsoftware.com/downloads/xmlnotepad/readme.htm</download>
<frequency>1.00:00:00</frequency>
</application>
<version number="2.7.1.8">
<feature>Add line numbers on the XML diff output.</feature>
<bug>Fix navigation of differences</bug>
</version>
<version number="2.7.1">
<feature>Add new option to allow you to save XML files without the UTF-8 byte order mark.</feature>
<feature>Add SHA 256 digital signature for stronger security.</feature>
Expand Down
4 changes: 2 additions & 2 deletions src/Version/Version.cs
Expand Up @@ -14,5 +14,5 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("2.7.1.5")]
[assembly: AssemblyFileVersion("2.7.1.5")]
[assembly: AssemblyVersion("2.7.1.8")]
[assembly: AssemblyFileVersion("2.7.1.8")]
6 changes: 3 additions & 3 deletions src/XmlDiffView/XmlDiffPath.cs
Expand Up @@ -148,7 +148,7 @@ internal class XmlDiffPath {
if (parentElement.Attributes == null) {
OnNoMatchingNode("@*");
return null;
} else if (parentElement.Attributes.NextSibbling == null) {
} else if (parentElement.Attributes.NextSibling == null) {
XmlDiffPathNodeList nodeList = new XmlDiffPathSingleNodeList();
nodeList.AddNode(parentElement.Attributes);
return nodeList;
Expand Down Expand Up @@ -219,7 +219,7 @@ internal class XmlDiffPath {
if (parentNode.ChildNodes == null) {
OnNoMatchingNode("*");
return null;
} else if (parentNode.ChildNodes.NextSibbling == null) {
} else if (parentNode.ChildNodes.NextSibling == null) {
XmlDiffPathNodeList nodeList = new XmlDiffPathSingleNodeList();
nodeList.AddNode(parentNode.ChildNodes);
return nodeList;
Expand All @@ -228,7 +228,7 @@ internal class XmlDiffPath {
XmlDiffViewNode childNode = parentNode.ChildNodes;
while (childNode != null) {
nodeList.AddNode(childNode);
childNode = childNode.NextSibbling;
childNode = childNode.NextSibling;
}
return nodeList;
}
Expand Down
53 changes: 17 additions & 36 deletions src/XmlDiffView/XmlDiffView.cs
Expand Up @@ -261,7 +261,7 @@ public XmlDiffView()
/// </summary>
/// <param name="sourceXml">baseline data</param>
/// <param name="diffgram">diffgram data stream</param>
public void Load(XmlReader sourceXml, XmlReader diffGram)
public void Load(XmlTextReader sourceXml, XmlReader diffGram)
{
nextOperationId = 1;

Expand Down Expand Up @@ -544,38 +544,9 @@ public void Load(XmlReader sourceXml, XmlReader diffGram)
public void GetHtml(TextWriter htmlOutput)
{
LastVisitedOpId = 0;

XmlDiffViewNode.ResetLineNumbers();
XmlTextWriter writer = new XmlTextWriter(htmlOutput);
if (XmlDiffView.LastOperationId > 0) {
writer.WriteStartElement("tr");
writer.WriteStartElement("td");
writer.WriteStartElement("a");
writer.WriteAttributeString("href", "#id1");
writer.WriteString("first");
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteStartElement("td");
writer.WriteEndElement();
writer.WriteStartElement("td");
writer.WriteEndElement();
writer.WriteEndElement();
}
this.viewDocument.DrawHtml(writer, 10);

if (XmlDiffView.LastOperationId > 0) {
writer.WriteStartElement("tr");
writer.WriteStartElement("td");
writer.WriteStartElement("a");
writer.WriteAttributeString("href", "#id" + (XmlDiffView.LastOperationId-1));
writer.WriteString("last");
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteStartElement("td");
writer.WriteEndElement();
writer.WriteStartElement("td");
writer.WriteEndElement();
writer.WriteEndElement();
}
}

#endregion
Expand Down Expand Up @@ -1051,7 +1022,7 @@ private void PreprocessDiffgram(XmlDocument diffgramDoc)
/// <param name="emptyElement">Node has no children</param>
private void LoadSourceChildNodes(
XmlDiffViewParentNode parent,
XmlReader reader,
XmlTextReader reader,
bool emptyElement)
{
LoadState savedLoadState = this.loadState;
Expand Down Expand Up @@ -1086,6 +1057,7 @@ private void PreprocessDiffgram(XmlDocument diffgramDoc)
reader.NamespaceURI,
attrValue);
}
attr.LineNumber = reader.LineNumber;
((XmlDiffViewElement)parent).InsertAttributeAfter(
attr,
this.loadState.LastAttribute);
Expand Down Expand Up @@ -1116,6 +1088,7 @@ private void PreprocessDiffgram(XmlDocument diffgramDoc)
reader.Prefix,
reader.NamespaceURI,
this.ignorePrefixes);
elem.LineNumber = reader.LineNumber;
this.LoadSourceChildNodes(elem, reader, emptyElementNode);
child = elem;
break;
Expand Down Expand Up @@ -1167,6 +1140,7 @@ private void PreprocessDiffgram(XmlDocument diffgramDoc)
}
break;
case XmlNodeType.EndElement:
parent.EndLine = reader.LineNumber;
goto End;

case XmlNodeType.DocumentType:
Expand All @@ -1185,8 +1159,15 @@ private void PreprocessDiffgram(XmlDocument diffgramDoc)
Debug.Assert(false, "Invalid node type");
break;
}
parent.InsertChildAfter(child, this.loadState.LastChild, true);
this.loadState.LastChild = child;
if (child != null)
{
if (child.LineNumber == 0 && child.EndLine == 0)
{
child.LineNumber = child.EndLine = reader.LineNumber;
}
parent.InsertChildAfter(child, this.loadState.LastChild, true);
this.loadState.LastChild = child;
}
}

End:
Expand Down Expand Up @@ -1821,7 +1802,7 @@ private OperationDescriptor GetDescriptor(int opid)
{
attr.Operation = op;
attr.OperationId = opid;
attr = (XmlDiffViewAttribute)attr.NextSibbling;
attr = (XmlDiffViewAttribute)attr.NextSibling;
}
}

Expand All @@ -1831,7 +1812,7 @@ private OperationDescriptor GetDescriptor(int opid)
while (childNode != null)
{
this.AnnotateNode(childNode, op, opid, true);
childNode = childNode.NextSibbling;
childNode = childNode.NextSibling;
}
}
}
Expand Down

0 comments on commit 8be60bd

Please sign in to comment.