### Eclipse Workspace Patch 1.0 #P org.eclipse.compare Index: compare/org/eclipse/compare/contentmergeviewer/TextMergeViewerResources.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewerResources.properties,v retrieving revision 1.31 diff -u -r1.31 TextMergeViewerResources.properties --- compare/org/eclipse/compare/contentmergeviewer/TextMergeViewerResources.properties 20 Apr 2007 18:33:08 -0000 1.31 +++ compare/org/eclipse/compare/contentmergeviewer/TextMergeViewerResources.properties 14 Jan 2009 09:57:44 -0000 @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2007 IBM Corporation and others. +# Copyright (c) 2000, 2009 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 @@ -18,6 +18,9 @@ saveDialog.title= Save Resource saveDialog.message= Resource has been modified. Save changes? +redoDiffDialog.title=Resource Changed +redoDiffDialog.message= Resource has been modified. Recalculate differences? + compareProgressTask.title= Computing Differences... tooComplexError.title= Error Index: compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java,v retrieving revision 1.241 diff -u -r1.241 TextMergeViewer.java --- compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java 12 Jan 2009 12:33:00 -0000 1.241 +++ compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java 14 Jan 2009 09:57:44 -0000 @@ -79,6 +79,7 @@ import org.eclipse.jface.action.Separator; import org.eclipse.jface.action.ToolBarManager; import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferenceConverter; @@ -430,7 +431,7 @@ private List fSourceViewerDecorationSupport = new ArrayList(3); // whether enhanced viewer configuration has been done private boolean isConfigured = false; - // maps containing actions contributed by client + private boolean fRedoDiff = false; private final class InternalOutlineViewerCreator extends OutlineViewerCreator implements ISelectionChangedListener { public Viewer findStructureViewer(Viewer oldViewer, @@ -1003,14 +1004,7 @@ IEditorInput input = getDocumentKey(); if (input != null && input.equals(element)) { this.fViewer.updateDirtyState(input, getDocumentProvider(), fLeg); - - // recalculate diffs and update controls - new UIJob(CompareMessages.DocumentMerger_0) { - public IStatus runInUIThread(IProgressMonitor monitor) { - update(true); - return Status.OK_STATUS; - } - }.schedule(); + updateInUIThread(true); } } public void elementContentAboutToBeReplaced(Object element) { @@ -2207,6 +2201,7 @@ * @since 3.3 */ protected boolean handleSetFocus() { + promptToRedoDiff(); if (fFocusPart == null) { if (fLeft != null && fLeft.getEnabled()) { fFocusPart= fLeft; @@ -2224,6 +2219,25 @@ return false; // could not set focus } + private void promptToRedoDiff() { + if (fRedoDiff) { + Shell shell = fComposite.getShell(); + MessageDialog dialog = new MessageDialog(shell, Utilities + .getString(getResourceBundle(), "redoDiffDialog.title"), //$NON-NLS-1$ + null, // accept the default window icon + Utilities.getString(getResourceBundle(), + "redoDiffDialog.message"), //$NON-NLS-1$ + MessageDialog.QUESTION, new String[] { + IDialogConstants.YES_LABEL, + IDialogConstants.NO_LABEL, }, 0 /* default is "yes" */); + switch (dialog.open()) { + case 0: + updateInUIThread(true); + case 1: + fRedoDiff = false; + } + } + } class HoverResizer extends Resizer { Canvas fCanvas; @@ -2886,6 +2900,10 @@ setRightDirty(dirty); } + // the change has been undone + if (!isLeftDirty() && !isRightDirty()) + fRedoDiff = false; + updateLines(doc); } @@ -2964,10 +2982,27 @@ private void updateDirtyState(IEditorInput key, IDocumentProvider documentProvider, char type) { boolean dirty = documentProvider.canSaveDocument(key); + boolean oldLeftDirty = isLeftDirty(); + boolean oldRightDirty = isRightDirty(); if (type == LEFT_CONTRIBUTOR) setLeftDirty(dirty); else if (type == RIGHT_CONTRIBUTOR) setRightDirty(dirty); + if ((oldLeftDirty != isLeftDirty() && !isLeftDirty() && !isRightDirty()) + || (oldRightDirty != isRightDirty() && !isRightDirty() && !isLeftDirty())) { + /* + * Dirty state has changed from true to false, combined dirty state + * is false. _In most cases_ this means that save has taken place + * outside compare editor. Ask to redo diff calculation when the + * editor gets focus. + * + * However, undoing all the changes made in another editor would + * result in asking for redo diff as well. In this case, we set the + * flag back to false, see + * TextMergeViewer.documentChanged(DocumentEvent, boolean) + */ + fRedoDiff = true; + } } private Position getNewRange(char type, Object input) { @@ -4876,6 +4911,16 @@ return Utilities.getBoolean(getCompareConfiguration(), ICompareUIConstants.PROP_IGNORE_ANCESTOR, false); } + private void updateInUIThread(final boolean includeControls) { + // recalculate diffs and update controls + new UIJob(CompareMessages.DocumentMerger_0) { + public IStatus runInUIThread(IProgressMonitor monitor) { + update(includeControls); + return Status.OK_STATUS; + } + }.schedule(); + } + /* package */ void update(boolean includeControls) { if (getControl().isDisposed()) return;