fe857b6cb4b18025919df39e846ced8a6906d0a6
[TortoiseGit.git] / contrib / diff-scripts / diff-nb.vbs
blobfe857b6cb4b18025919df39e846ced8a6906d0a6
2 ' TortoiseSVN Diff script for Mathematica notebooks
4 ' Last commit by:
5 ' $Author$
6 ' $Date$
7 ' $Rev$
9 ' Authors:
10 ' Szabolcs Horvát, 2008
11 ' Chris Rodgers http://rodgers.org.uk/, 2008
12 ' (Based on diff-xlsx.vbs)
15 dim objArgs, objScript, objDiffNotebook
17 Set objArgs = WScript.Arguments
18 num = objArgs.Count
19 if num < 2 then
20 MsgBox "Usage: [CScript | WScript] compare.vbs base.nb new.nb", vbExclamation, "Invalid arguments"
21 WScript.Quit 1
22 end if
24 sBaseDoc = objArgs(0)
25 sNewDoc = objArgs(1)
27 Set objScript = CreateObject("Scripting.FileSystemObject")
29 If objScript.FileExists(sBaseDoc) = False Then
30 MsgBox "File " + sBaseDoc +" does not exist. Cannot compare the notebooks.", vbExclamation, "File not found"
31 Wscript.Quit 1
32 Else
33 sBaseDoc = objScript.GetAbsolutePathName(sBaseDoc)
34 End If
36 If objScript.FileExists(sNewDoc) = False Then
37 MsgBox "File " + sNewDoc +" does not exist. Cannot compare the notebooks.", vbExclamation, "File not found"
38 Wscript.Quit 1
39 Else
40 sNewDoc = objScript.GetAbsolutePathName(sNewDoc)
41 End If
43 On Error Resume Next
44 Dim tfolder, tname, tfile
45 Const TemporaryFolder = 2
47 Set tfolder = objScript.GetSpecialFolder(TemporaryFolder)
49 tname = objScript.GetTempName + ".nb"
50 Set objDiffNotebook = tfolder.CreateTextFile(tname)
52 'Output a Mathematica notebook that will do the diff for us
53 objDiffNotebook.WriteLine "Notebook[{" + vbCrLf + _
54 "Cell[BoxData[ButtonBox[""\<\""Compare Notebooks\""\>""," + vbCrLf + _
55 "ButtonFrame->""DialogBox"", Active->True, ButtonEvaluator->Automatic," + vbCrLf + _
56 "ButtonFunction:>(Needs[""AuthorTools`""];" + vbCrLf + _
57 "NotebookPut[Symbol[""NotebookDiff""][" + vbCrLf + _
58 """" + Replace(sBaseDoc,"\","\\") + """," + vbCrLf + _
59 """" + Replace(sNewDoc,"\","\\") + """" + vbCrLf + _
60 "]])]], NotebookDefault]" + vbCrLf + _
61 "}, Saveable->False, Editable->False, Selectable->False, WindowToolbars->{}, WindowFrame->ModelessDialog, WindowElements->{}, WindowFrameElements->CloseBox, WindowTitle->""Diff"", ShowCellBracket->False, WindowSize->{Fit,Fit}]"
64 objDiffNotebook.Close
66 Set objShell = CreateObject("WScript.Shell")
67 objShell.Run tfolder + "\" + tname