1 // extensions: doc;docx;docm
\r
3 // TortoiseSVN Merge script for Word Doc files
\r
5 // Copyright (C) 2004-2008, 2011, 2019 the TortoiseSVN team
\r
6 // This file is distributed under the same license as TortoiseSVN
\r
14 // Dan Sheridan, 2008
\r
15 // Davide Orlandi and Hans-Emil Skogh, 2005
\r
16 // Richard Horton, 2011
\r
17 // Paolo Nesti Poggi, 2017
\r
20 var objArgs, num, sTheirDoc, sMyDoc, sBaseDoc, sMergedDoc,
\r
21 objScript, word, baseDoc, myDoc, theirDoc, WSHShell;
\r
23 // Microsoft Office versions for Microsoft Windows OS
\r
24 var vOffice2000 = 9;
\r
25 var vOffice2002 = 10;
\r
26 //var vOffice2003 = 11;
\r
27 var vOffice2007 = 12;
\r
28 var vOffice2010 = 14;
\r
30 var wdCompareTargetSelected = 0;
\r
31 //var wdCompareTargetCurrent = 1;
\r
32 var wdCompareTargetNew = 2;
\r
33 var wdMergeTargetCurrent = 1;
\r
35 objArgs = WScript.Arguments;
\r
36 num = objArgs.length;
\r
39 WScript.Echo("Usage: [CScript | WScript] merge-doc.js merged.doc theirs.doc mine.doc base.doc");
\r
43 sMergedDoc = objArgs(0);
\r
44 sTheirDoc = objArgs(1);
\r
45 sMyDoc = objArgs(2);
\r
46 sBaseDoc = objArgs(3);
\r
48 objScript = new ActiveXObject("Scripting.FileSystemObject");
\r
50 if (!objScript.FileExists(sTheirDoc))
\r
52 WScript.Echo("File " + sTheirDoc + " does not exist. Cannot compare the documents.", vbExclamation, "File not found");
\r
56 if (!objScript.FileExists(sMergedDoc))
\r
58 WScript.Echo("File " + sMergedDoc + " does not exist. Cannot compare the documents.", vbExclamation, "File not found");
\r
66 word = WScript.CreateObject("Word.Application");
\r
68 word.AutomationSecurity = 3; //msoAutomationSecurityForceDisable
\r
72 WScript.Echo("You must have Microsoft Word installed to perform this operation.");
\r
76 word.visible = true;
\r
78 // Anticipate creation of shell object
\r
79 WSHShell = WScript.CreateObject("WScript.Shell");
\r
81 // Show usage hint message
\r
82 WSHShell.Popup("After you click 'OK' we'll create a merge document. Please wait.\nThen reject or accept changes and save the document renaming it to the original conflicting filename.", 0, "TortoiseGit Word Merge", 64);
\r
84 // Open the base document
\r
85 baseDoc = word.Documents.Open(sTheirDoc);
\r
87 // Merge into the "My" document
\r
88 if (parseInt(word.Version, 10) < vOffice2000)
\r
90 baseDoc.Compare(sMergedDoc);
\r
92 else if (parseInt(word.Version, 10) < vOffice2007)
\r
94 baseDoc.Compare(sMergedDoc, "Comparison", wdCompareTargetNew, true, true);
\r
98 // this implements the three-way comparison for versions >= 2007
\r
100 baseDoc = word.Documents.Open(sBaseDoc);
\r
101 myDoc = word.Documents.Open(sMyDoc);
\r
103 baseDoc.Activate(); //required otherwise it compares the wrong docs !!!
\r
104 baseDoc.Compare(sTheirDoc, "theirs", wdCompareTargetSelected, true, true);
\r
106 baseDoc.Activate(); //required otherwise it compares the wrong docs !!!
\r
107 baseDoc.Compare(sMyDoc, "mine", wdCompareTargetSelected, true, true);
\r
109 myDoc.Activate(); //required? just in case
\r
110 myDoc.Merge(sTheirDoc, wdMergeTargetCurrent);
\r
113 // bring focus to the window, for accept/reject buttons to be active.
\r
114 WSHShell.AppActivate(word.windows.Item(1).caption);
\r
117 // Show the merge result
\r
118 if (parseInt(word.Version, 10) < vOffice2007)
\r
120 word.ActiveDocument.Windows(1).Visible = 1;
\r
123 // Close the first document
\r
124 if (parseInt(word.Version, 10) >= vOffice2002)
\r