diff options
author | Szymon Brandys | 2010-11-03 10:16:48 +0000 |
---|---|---|
committer | Szymon Brandys | 2010-11-03 10:16:48 +0000 |
commit | 31db9f9d60b29827aca6d924a59f314b4f9ee639 (patch) | |
tree | 133956499e6bd783f562f7ba9bd220ee18ff7d2f | |
parent | 0c8e9f0fd4b5acd161c5ce6fb66bf0556a1b2a62 (diff) | |
download | eclipse.platform.team-31db9f9d60b29827aca6d924a59f314b4f9ee639.tar.gz eclipse.platform.team-31db9f9d60b29827aca6d924a59f314b4f9ee639.tar.xz eclipse.platform.team-31db9f9d60b29827aca6d924a59f314b4f9ee639.zip |
Bug 326395 - [Backport] Cannot compare word documentsR36x_v20101103-0618
3 files changed, 65 insertions, 12 deletions
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare.win32/META-INF/MANIFEST.MF b/bundles/org.eclipse.compare/plugins/org.eclipse.compare.win32/META-INF/MANIFEST.MF index 49f71c207..ddc1d406e 100644 --- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare.win32/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare.win32/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.compare.win32;singleton:=true -Bundle-Version: 1.0.100.qualifier +Bundle-Version: 1.0.101.qualifier Bundle-Vendor: %providerName Bundle-RequiredExecutionEnvironment: J2SE-1.4 Eclipse-PlatformFilter: (osgi.os=win32) diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare.win32/src/org/eclipse/compare/internal/win32/WordComparison.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare.win32/src/org/eclipse/compare/internal/win32/WordComparison.java index 06c4b05a4..fc63c2845 100644 --- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare.win32/src/org/eclipse/compare/internal/win32/WordComparison.java +++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare.win32/src/org/eclipse/compare/internal/win32/WordComparison.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 IBM Corporation and others. + * Copyright (c) 2008, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -48,6 +48,14 @@ public class WordComparison { return auto.invoke(property(auto, command), new Variant[0]); } + private static Variant invoke(OleAutomation auto, OleAutomation reference, String command) { + return auto.invoke(property(auto, reference, command), new Variant[0]); + } + + private static Variant invoke(OleAutomation auto, OleAutomation reference, String command, String value) { + return auto.invoke(property(auto, reference, command), new Variant[] { new Variant(value) }); + } + private static Variant invoke(OleAutomation auto, String command, int value) { return auto.invoke(property(auto, command), new Variant[] { new Variant(value) }); } @@ -104,6 +112,36 @@ public class WordComparison { throw new SWTException(NLS.bind(CompareWin32Messages.WordComparison_3, command, value)); } + + /** + * <p>This methods workarounds the feature in doc documents. Some properties are not accessible + * using names when a diff document is created. The workaround is to obtain the id of the + * method from an original document and use it in the newly created one.</p> + * + * <p>An exception is thrown if the id cannot be retrieved</p> + * + * Reference information for id assignment: <a href=" + * http://msdn.microsoft.com/en-us/library/w7a36sdf%28VS.80%29.aspx">http://msdn.microsoft.com/en-us/library/w7a36sdf%28VS.80%29.aspx</a> + * + * @param auto - object from which we want to get the property, must not be <code>null</code> + * @param reference - an reference object from which the property will be obtained. + * @param name - the name of the property, must not be <code>null</code> + */ + private static int property(OleAutomation auto, OleAutomation reference, String name) { + int[] ids = auto.getIDsOfNames(new String[] { name }); + if (ids != null) { + return ids[0]; + } + if(reference == null) throw new SWTException(NLS.bind(CompareWin32Messages.WordComparison_4, name)) ; + + // the property was not retrieved at that point, try to get it from the reference object + ids = reference.getIDsOfNames(new String[] { name }); + if (ids == null) { + throw new SWTException(NLS.bind(CompareWin32Messages.WordComparison_4, name)); + } + return ids[0]; + } + private static int property(OleAutomation auto, String name) { int[] ids = auto.getIDsOfNames(new String[] { name }); if (ids == null) throw new SWTException(NLS.bind(CompareWin32Messages.WordComparison_4, name)); @@ -154,13 +192,13 @@ public class WordComparison { compareDocument(document, baseDocument, revisedDocument); OleAutomation activeDocument = getActiveDocument(application); try { - Variant varResult = invoke(activeDocument, "SaveAs", workingCopy); //$NON-NLS-1$ + Variant varResult = invoke(activeDocument, document, "SaveAs", workingCopy); //$NON-NLS-1$ if (varResult == null) throw new SWTException(NLS.bind(CompareWin32Messages.WordComparison_6, workingCopy)); varResult.dispose(); } finally { try { - closeDocument(activeDocument); + closeDocument(activeDocument, document); } catch (SWTException e) { // We don't want to throw the exception as we may mask another exception Activator.log(e); @@ -170,7 +208,7 @@ public class WordComparison { } } finally { try { - closeDocument(document); + closeDocument(document, null); } catch (SWTException e) { // We don't want to throw the exception as we may mask another exception Activator.log(e); @@ -183,9 +221,9 @@ public class WordComparison { } } - private void closeDocument(OleAutomation document) { + private void closeDocument(OleAutomation document, OleAutomation reference) { // Close the first document: destination.Close() - Variant varResult = invoke(document, "Close"); //$NON-NLS-1$ + Variant varResult = invoke(document, reference, "Close"); //$NON-NLS-1$ if (varResult != null) { varResult.dispose(); } @@ -273,7 +311,7 @@ public class WordComparison { private void disposeSite() { if (document != null) { try { - closeDocument(document); + closeDocument(document, null); } catch (SWTException e) { Activator.log(e); } diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare.win32/src/org/eclipse/compare/internal/win32/WordMergeViewer.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare.win32/src/org/eclipse/compare/internal/win32/WordMergeViewer.java index f03eeaa84..ac17d303f 100644 --- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare.win32/src/org/eclipse/compare/internal/win32/WordMergeViewer.java +++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare.win32/src/org/eclipse/compare/internal/win32/WordMergeViewer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 IBM Corporation and others. + * Copyright (c) 2008, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -305,8 +305,16 @@ public class WordMergeViewer extends AbstractMergeViewer implements IFlushable, try { if (isOneSided()) { File file = getFileForSingleSide(); - if (file != null) - wordArea.openDocument(file.getAbsolutePath(), inplace); + if (file != null) { + try { + wordArea.openDocument(file.getAbsolutePath(), inplace); + } catch (SWTException e) { + throw new CoreException(new Status(IStatus.ERROR, + Activator.PLUGIN_ID, NLS.bind( + CompareWin32Messages.WordComparison_16, + file.getAbsolutePath()), e)); + } + } } else { File left = getFileForLeft(); File right = getFileForRight(); @@ -327,7 +335,14 @@ public class WordMergeViewer extends AbstractMergeViewer implements IFlushable, resultFileTimestamp = result.lastModified(); description.setText(getTextDescription()); } - wordArea.openDocument(result.getAbsolutePath(), inplace); + try { + wordArea.openDocument(result.getAbsolutePath(), inplace); + } catch (SWTException e) { + throw new CoreException(new Status(IStatus.ERROR, + Activator.PLUGIN_ID, NLS.bind( + CompareWin32Messages.WordComparison_16, + result.getAbsolutePath()), e)); + } } } } |