Indicators on File Comparison Use Case

SyntaxEditor for Windows Forms Forum

Posted 1 year ago by dharrison_ch - Zurich, Switzerland
Version: 23.1.1
Avatar

Hi Team,

I am putting together a winforms PoC application where I compare two Java files.

I have used the file compare example in the Syntax Editor product pack as my base and in general it works as I would like.

However, I am struggling to understand how to extend the basic comparison architecture to show Indicators on one of the Syntax Editor panels.

I have used as a base the Indicator approac as in the Sample Browser.

Degiing I see "differences" being produced multiple time - first with 0 "differences", then with a relatively large list with "Kind = None" before the comparison engine finally shows the document of interest.

Could you hint me as to where/how a consolidated final list of "differences" can be found/built such that corresponding Indicators can be set against them?

Looking forward to receiving your feedback.

Best Regards

Dave Harrison

Comments (2)

Posted 1 year ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Dave,

I'm not entirely certain what you are referring to about differences being produced multiple times. In our sample, the differences are initiated by a Compare method on the main control. There should be a single Compare performed when loaded, again if either document's text is changed, and again if the option to ignore white space is changed.

The final list of "differences" is found on the instance of IDocumentDifferenceBuilder (which is either implemented by DocumentDifferenceBuilder class in our sample or DiffPlexDocumentDifferenceBuilder if you opt the for the other engine).  Once that class is created and the IDocumentDifferenceBuilder.Compare method is called, the OldDifferences and NewDifferences properties on the same class instance will define the final list of "differences".

There is always one collection of differences for the old text and one for the new text, and there should be an equal number of items in each collection.  The Imaginary difference kind is used as a placeholder within the two collections to keep them aligned when lines are added/removed between the compared text.  You can see these visualized in the sample application as lines with a hatched background.

While there are two collections of differences related to the comparison, there is only one collection associated with a particular document. The old document only has the OldDifferences collection, and the new document only has the NewDifferences collection. For each document, that collection should have all the information necessary to show its own differences.

If you look at the code behind for MainControl in that sample, there is an ApplyDifferences method that updates the appropriate editor view with the current collection of differences.  For the purposes of this sample, we don't store the IDifferenceCollection directly on the editor or document.  Instead, we pass the collection to the appropriate tagger classes that are responsible for rendering the differences, and each tagger holds a reference to the collection.  Since the tags for real lines are handled differently than the tags for imaginary lines, that's why there are two taggers.

For your solution using indicators, you could take a similar approach to the taggers in the sample and notify your tagger when the differences change.

While we did not take this approach with the sample, you could choose to store the current IDifferenceCollection as a property on the document being edited. This would make the collection accessible outside of the taggers themselves. You can find more information on the Document Properties topic.

I hope this help give you the information you need. If not, please let us know and we'll do our best to help.


Actipro Software Support

Posted 1 year ago by dharrison_ch - Zurich, Switzerland
Avatar

Hi Team,

many thanks for your timely feedback via email.

Given your hints I was able to make progress.

Thanks & best regards

Dave Harrison

The latest build of this product (v24.1.1) was released 28 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.