### Eclipse Workspace Patch 1.0 #P org.eclipse.compare Index: compare/org/eclipse/compare/internal/CompareAction.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareAction.java,v retrieving revision 1.20 diff -u -r1.20 CompareAction.java --- compare/org/eclipse/compare/internal/CompareAction.java 16 Mar 2007 19:53:09 -0000 1.20 +++ compare/org/eclipse/compare/internal/CompareAction.java 8 Jul 2008 12:07:55 -0000 @@ -19,6 +19,7 @@ import org.eclipse.ui.IWorkbenchPart; import org.eclipse.compare.CompareConfiguration; import org.eclipse.compare.CompareUI; +import org.eclipse.core.resources.IResource; /* @@ -26,17 +27,31 @@ */ public class CompareAction extends BaseCompareAction implements IObjectActionDelegate { - private ResourceCompareInput fInput; - private IWorkbenchPage fWorkbenchPage; - + private static ResourceCompareInput fInput; + private static IWorkbenchPage fWorkbenchPage; public void run(ISelection selection) { if (fInput != null) { // Pass the shell so setSelection can prompt the user for which // resource should be the ancestor - boolean ok = fInput.setSelection(selection, - fWorkbenchPage.getWorkbenchWindow().getShell()); - if (!ok) return; + boolean ok = fInput.setSelection(selection, fWorkbenchPage + .getWorkbenchWindow().getShell()); + if (!ok) + return; + fInput.initializeCompareConfiguration(); + CompareUI.openCompareEditorOnPage(fInput, fWorkbenchPage); + fInput = null; // don't reuse this input! + } + } + + public static void run(IResource[] resources) { + fWorkbenchPage = CompareUIPlugin.getActiveWorkbench() + .getActiveWorkbenchWindow().getActivePage(); + if (fInput != null) { + boolean ok = fInput.setSelection(resources, fWorkbenchPage + .getWorkbenchWindow().getShell()); + if (!ok) + return; fInput.initializeCompareConfiguration(); CompareUI.openCompareEditorOnPage(fInput, fWorkbenchPage); fInput= null; // don't reuse this input! @@ -58,6 +73,16 @@ return fInput.isEnabled(selection); } + public static boolean isEnabled(IResource[] resources) { + if (fInput == null) { + CompareConfiguration cc = new CompareConfiguration(); + cc.setProperty(CompareEditor.CONFIRM_SAVE_PROPERTY, new Boolean( + false)); + fInput = new ResourceCompareInput(cc); + } + return fInput.isEnabled(resources); + } + public void setActivePart(IAction action, IWorkbenchPart targetPart) { fWorkbenchPage= targetPart.getSite().getPage(); } Index: compare/org/eclipse/compare/internal/Messages.java =================================================================== RCS file: compare/org/eclipse/compare/internal/Messages.java diff -N compare/org/eclipse/compare/internal/Messages.java --- compare/org/eclipse/compare/internal/Messages.java 16 Mar 2007 19:53:09 -0000 1.3 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.internal; - -import com.ibm.icu.text.MessageFormat; - -/** - * Helper class to format message strings. - * - * @since 3.1 - */ -public class Messages { - - public static String format(String message, Object object) { - return MessageFormat.format(message, new Object[] { object}); - } - - public static String format(String message, Object[] objects) { - return MessageFormat.format(message, objects); - } - - private Messages() { - // Not for instantiation - } -} Index: compare/org/eclipse/compare/internal/ResourceCompareInput.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/compare/org/eclipse/compare/internal/ResourceCompareInput.java,v retrieving revision 1.38 diff -u -r1.38 ResourceCompareInput.java --- compare/org/eclipse/compare/internal/ResourceCompareInput.java 16 Mar 2007 19:53:09 -0000 1.38 +++ compare/org/eclipse/compare/internal/ResourceCompareInput.java 8 Jul 2008 12:07:56 -0000 @@ -201,11 +201,14 @@ // to use as the ancestor. Returns false if the user cancels the prompt, // true otherwise. boolean setSelection(ISelection s, Shell shell) { - - IResource[] selection= Utilities.getResources(s); + IResource[] selection = Utilities.getResources(s); + return setSelection(selection, shell); + } + + boolean setSelection(IResource[] selection, Shell shell) { + + fThreeWay = selection.length == 3; - fThreeWay= selection.length == 3; - if (fThreeWay) { SelectAncestorDialog dialog = new SelectAncestorDialog(shell, selection); @@ -233,21 +236,26 @@ * Returns true if compare can be executed for the given selection. */ public boolean isEnabled(ISelection s) { - - IResource[] selection= Utilities.getResources(s); - if (selection.length < 2 || selection.length > 3) + + IResource[] selection = Utilities.getResources(s); + return isEnabled(selection); + } + + public boolean isEnabled(IResource[] resources) { + if (resources.length < 2 || resources.length > 3) return false; - boolean threeWay= selection.length == 3; + boolean threeWay= resources.length == 3; - if (threeWay) + if (threeWay) { // It only makes sense if they're all mutually comparable. // If not, the user should compare two of them. - return comparable(selection[0], selection[1]) - && comparable(selection[0], selection[2]) - && comparable(selection[1], selection[2]); - - return comparable(selection[0], selection[1]); + return comparable(resources[0], resources[1]) + && comparable(resources[0], resources[2]) + && comparable(resources[1], resources[2]); + } + + return comparable(resources[0], resources[1]); } /** Index: plugin.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/plugin.properties,v retrieving revision 1.91 diff -u -r1.91 plugin.properties --- plugin.properties 22 Apr 2008 10:27:12 -0000 1.91 +++ plugin.properties 8 Jul 2008 12:07:55 -0000 @@ -83,6 +83,9 @@ CompareWithEachOtherAction.label= &Each Other CompareWithEachOtherAction.tooltip= Compare the Selected Resources +CompareWithOtherResource.label= &Other Resource +CompareWithOtherResource.tooltip= Open the 'Compare With' Dialog + CompareWithHistoryAction.label= &Local History... CompareWithHistoryAction.tooltip= Compare the Selected Resource with Local History Index: plugin.xml =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/plugin.xml,v retrieving revision 1.65 diff -u -r1.65 plugin.xml --- plugin.xml 11 Jul 2007 14:59:33 -0000 1.65 +++ plugin.xml 8 Jul 2008 12:07:55 -0000 @@ -201,6 +201,14 @@ enablesFor="2+" id="compareWithEachOther"> + +