Custom WinMerge plugin

In previous post about HTTP request comparison in Fiddler I showed how to integrate Fiddler and WinMerge to find differences easily. Given example shown a problem because when you get all parameters in one line then you are unable to locate which parameter is changed.

Fortunately WinMerge has ability to extend its functionality using plugins. Plugins are dll libraries or COM API scriplets (written in VBScript).

WinMerge plugins are put into MergePlugins directory inside installation path. The easiest way to create your own plugin is to copy and change an existing one. Lets copy “insert datetime.sct” file and call it “request param to new line.sct”. Now we can clear unnecessary code from the file.

<scriptlet>

<implements type="Automation" id="dispatcher">
 <property name="PluginEvent">
 <get/>
 </property>
 <property name="PluginDescription">
 <get/>
 </property>
 <method name=""/>
</implements>

<script language="VBS">
Option Explicit

Function get_PluginEvent()
 get_PluginEvent = "EDITOR_SCRIPT"
End Function

Function get_PluginDescription()
 get_PluginDescription = "Basic text functions for the context menu"
End Function

</script>
</scriptlet>

The code above shows an empty plugin. We have to implement our function now. It’s place is upon the ending </script> tag.

Function RequestParamToNewline(Text)
 RequestParamToNewline = Replace(Text, "&", VbCrLf & "&")
End Function

For those of you who don’t know VBScript I am giving an explanation. We take input parameter called Text and doing simple text replace on it. We replace ampersand sign (&) with newline and ampersand. We can use constant VBScriptValue for newrline – VbCrLf which represents newline and carriage return signs (\r\n).

Now we have to inform WinMerge which function we want to invoke when the script starts. Name of this function should be placed inside name attribute of method node at the XML on the top. Final version of our script should look like this:

<scriptlet>

<implements type="Automation" id="dispatcher">
 <property name="PluginEvent">
 <get/>
 </property>
 <property name="PluginDescription">
 <get/>
 </property>
 <method name="RequestParamToNewline"/>
</implements>

<script language="VBS">
Option Explicit

Function get_PluginEvent()
 get_PluginEvent = "EDITOR_SCRIPT"
End Function

Function get_PluginDescription()
 get_PluginDescription = "Basic text functions for the context menu"
End Function


Function RequestParamToNewline(Text)
 RequestParamToNewline = Replace(Text, "&", VbCrLf & "&")
End Function


</script>
</scriptlet>

After the file is saved we can run WinMerge and check if our script has been correctly recognized. It should be available under Edit->Script menu. If it isn’t there then something went wrong. You can select all the text in one of windows. WinMerge will try to detect available plugins then and should show an error message.

Custom WinMerge plugin

Custom WinMerge plugin

To invoke our script we need to select all the text in left window and use Edit->Scripts->RequestParamToNewline. We do the same for the right window. After that we need to click on “Refresh” button and all differences should be shown.

Animation - Custom WinMerge Plugin execution

Animation – Custom WinMerge Plugin execution

You can find script source code on my GitHub

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*
Website