1 // extensions: doc;docx;docm
\r
3 // TortoiseSVN Merge script for Word Doc files
\r
5 // Copyright (C) 2004-2008, 2011 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
19 var objArgs, num, sTheirDoc, sMyDoc, sBaseDoc, sMergedDoc,
\r
20 objScript, word, baseDoc, myDoc, theirDoc, WSHShell;
\r
22 // Microsoft Office versions for Microsoft Windows OS
\r
23 var vOffice2000 = 9;
\r
24 var vOffice2002 = 10;
\r
25 //var vOffice2003 = 11;
\r
26 var vOffice2007 = 12;
\r
27 var vOffice2010 = 14;
\r
29 var wdCompareTargetSelected = 0;
\r
30 //var wdCompareTargetCurrent = 1;
\r
31 var wdCompareTargetNew = 2;
\r
32 var wdMergeTargetCurrent = 1;
\r
34 objArgs = WScript.Arguments;
\r
35 num = objArgs.length;
\r
38 WScript.Echo("Usage: [CScript | WScript] merge-doc.js merged.doc theirs.doc mine.doc base.doc");
\r
42 sMergedDoc = objArgs(0);
\r
43 sTheirDoc = objArgs(1);
\r
44 sMyDoc = objArgs(2);
\r
45 sBaseDoc = objArgs(3);
\r
47 objScript = new ActiveXObject("Scripting.FileSystemObject");
\r
49 if (!objScript.FileExists(sTheirDoc))
\r
51 WScript.Echo("File " + sTheirDoc + " does not exist. Cannot compare the documents.", vbExclamation, "File not found");
\r
55 if (!objScript.FileExists(sMergedDoc))
\r
57 WScript.Echo("File " + sMergedDoc + " does not exist. Cannot compare the documents.", vbExclamation, "File not found");
\r
65 word = WScript.CreateObject("Word.Application");
\r
69 WScript.Echo("You must have Microsoft Word installed to perform this operation.");
\r
73 word.visible = true;
\r
75 // Open the base document
\r
76 baseDoc = word.Documents.Open(sTheirDoc);
\r
78 // Merge into the "My" document
\r
79 if (parseInt(word.Version, 10) < vOffice2000)
\r
81 baseDoc.Compare(sMergedDoc);
\r
83 else if (parseInt(word.Version, 10) < vOffice2007)
\r
85 baseDoc.Compare(sMergedDoc, "Comparison", wdCompareTargetNew, true, true);
\r
87 else if (parseInt(word.Version, 10) < vOffice2010)
\r
89 baseDoc.Merge(sMergedDoc);
\r
93 //2010 - handle slightly differently as the basic merge isn't that good
\r
94 //note this is designed specifically for svn 3 way merges, during the commit conflict resolution process
\r
96 baseDoc = word.Documents.Open(sBaseDoc);
\r
97 myDoc = word.Documents.Open(sMyDoc);
\r
99 baseDoc.Activate(); //required otherwise it compares the wrong docs !!!
\r
100 baseDoc.Compare(sTheirDoc, "theirs", wdCompareTargetSelected, true, true);
\r
102 baseDoc.Activate(); //required otherwise it compares the wrong docs !!!
\r
103 baseDoc.Compare(sMyDoc, "mine", wdCompareTargetSelected, true, true);
\r
107 myDoc.Activate(); //required? just in case
\r
108 myDoc.Merge(sTheirDoc, wdMergeTargetCurrent);
\r
111 // Show the merge result
\r
112 if (parseInt(word.Version, 10) < vOffice2007)
\r
114 word.ActiveDocument.Windows(1).Visible = 1;
\r
117 // Close the first document
\r
118 if ((parseInt(word.Version, 10) >= vOffice2002) && (parseInt(word.Version, 10) < vOffice2010))
\r
123 // Show usage hint message
\r
124 WSHShell = WScript.CreateObject("WScript.Shell");
\r
125 if (WSHShell.Popup("You have to accept or reject the changes before\nsaving the document to prevent future problems.\n\nWould you like to see a help page on how to do this?", 0, "TSVN Word Merge", 4 + 64) === 6)
\r
127 WSHShell.Run("http://office.microsoft.com/en-us/assistance/HP030823691033.aspx");
\r