Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 273450 | Differences between
and this patch

Collapse All | Expand All

(-)compare/org/eclipse/compare/CompareEditorInput.java (-32 / +117 lines)
Lines 11-20 Link Here
11
package org.eclipse.compare; 
11
package org.eclipse.compare; 
12
12
13
import java.lang.reflect.InvocationTargetException;
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.ArrayList;
15
import java.util.ResourceBundle;
14
import java.util.ResourceBundle;
16
15
16
import org.eclipse.compare.contentmergeviewer.ContentMergeViewer;
17
import org.eclipse.compare.contentmergeviewer.IFlushable;
17
import org.eclipse.compare.contentmergeviewer.IFlushable;
18
import org.eclipse.compare.contentmergeviewer.IFlushable2;
18
import org.eclipse.compare.internal.BinaryCompareViewer;
19
import org.eclipse.compare.internal.BinaryCompareViewer;
19
import org.eclipse.compare.internal.ChangePropertyAction;
20
import org.eclipse.compare.internal.ChangePropertyAction;
20
import org.eclipse.compare.internal.CompareContentViewerSwitchingPane;
21
import org.eclipse.compare.internal.CompareContentViewerSwitchingPane;
Lines 177-183 Link Here
177
	 * @since 3.3
178
	 * @since 3.3
178
	 */
179
	 */
179
	public static final String PROP_SELECTED_EDITION= ICompareUIConstants.PROP_SELECTED_EDITION;
180
	public static final String PROP_SELECTED_EDITION= ICompareUIConstants.PROP_SELECTED_EDITION;
180
		
181
182
	public static final int LEFT_SIDE = 1;
183
	public static final int RIGHT_SIDE = 2;
184
181
	private static final String COMPARE_EDITOR_IMAGE_NAME= "eview16/compare_view.gif"; //$NON-NLS-1$
185
	private static final String COMPARE_EDITOR_IMAGE_NAME= "eview16/compare_view.gif"; //$NON-NLS-1$
182
	private static Image fgTitleImage;
186
	private static Image fgTitleImage;
183
	
187
	
Lines 193-200 Link Here
193
	private String fTitle;
197
	private String fTitle;
194
	private ListenerList fListenerList= new ListenerList();
198
	private ListenerList fListenerList= new ListenerList();
195
	private CompareNavigator fNavigator;
199
	private CompareNavigator fNavigator;
196
	private boolean fDirty= false;
200
	private ContentMergeViewer fLeftDirtyViewer = null;
197
	private ArrayList fDirtyViewers= new ArrayList();
201
	private ContentMergeViewer fRightDirtyViewer = null;
198
	private IPropertyChangeListener fDirtyStateListener;
202
	private IPropertyChangeListener fDirtyStateListener;
199
	
203
	
200
	boolean fStructureCompareOnSingleClick= true;
204
	boolean fStructureCompareOnSingleClick= true;
Lines 1016-1033 Link Here
1016
	}
1020
	}
1017
	
1021
	
1018
	/**
1022
	/**
1019
	 * Returns <code>true</code> if there are unsaved changes.
1023
	 * Returns <code>true</code> if there are unsaved changes in either left or
1020
	 * The value returned is the value of the <code>DIRTY_STATE</code> property of this input object.
1024
	 * right side. The value returned is the value of the
1021
	 
1025
	 * <code>DIRTY_STATE</code> property of this input object.
1022
	 * Returns <code>true</code> if this input has unsaved changes,
1026
	 * 
1023
	 * that is if <code>setDirty(true)</code> has been called.
1027
	 * Returns <code>true</code> if left or right side has unsaved changes
1024
	 * Subclasses don't have to override if the functionality provided by <code>setDirty</code>
1028
	 * Subclasses don't have to override if the functionality provided by
1025
	 * is sufficient.
1029
	 * <code>setDirty</code> is sufficient.
1026
	 *
1030
	 * 
1027
	 * @return <code>true</code> if there are changes that need to be saved
1031
	 * @return <code>true</code> if there are changes that need to be saved
1028
	 */
1032
	 */
1029
	public boolean isSaveNeeded() {
1033
	public boolean isSaveNeeded() {
1030
		return fDirty || fDirtyViewers.size() > 0;
1034
		return isLeftSaveNeeded() || isRightSaveNeeded();
1035
	}
1036
1037
	/**
1038
	 * Returns <code>true</code> if there are unsaved changes for left side.
1039
	 * 
1040
	 * @return <code>true</code> if there are changes that need to be saved
1041
	 */
1042
	protected boolean isLeftSaveNeeded() {
1043
		return fLeftDirtyViewer != null;
1044
	}
1045
1046
	/**
1047
	 * Returns <code>true</code> if there are unsaved changes for right side.
1048
	 * 
1049
	 * @return <code>true</code> if there are changes that need to be saved
1050
	 */
1051
	protected boolean isRightSaveNeeded() {
1052
		return fRightDirtyViewer != null;
1031
	}
1053
	}
1032
	
1054
	
1033
	/**
1055
	/**
Lines 1044-1074 Link Here
1044
	}
1066
	}
1045
		
1067
		
1046
	/**
1068
	/**
1047
	 * Sets the dirty state of this input to the given
1069
	 * Sets the dirty state of this input to the given value and sends out a
1048
	 * value and sends out a <code>PropertyChangeEvent</code> if the new value differs from the old value.
1070
	 * <code>PropertyChangeEvent</code> if the new value differs from the old
1049
	 *
1071
	 * value. Direct calling this method with parameter dirty equal to
1050
	 * @param dirty the dirty state for this compare input
1072
	 * <code>false</code> when there are unsaved changes in viewers, results in
1073
	 * inconsistent state. The dirty state of compare input should be based only
1074
	 * on the information if there are changes in viewers for left or right
1075
	 * side.
1076
	 * 
1077
	 * @param dirty
1078
	 *            the dirty state for this compare input
1051
	 */
1079
	 */
1052
	public void setDirty(boolean dirty) {
1080
	public void setDirty(boolean dirty) {
1053
		boolean oldDirty = fDirty || fDirtyViewers.size() > 0;
1081
		boolean oldDirty = isSaveNeeded();
1054
		fDirty= dirty;
1082
		boolean newDirty = dirty || isSaveNeeded();
1055
		if (!fDirty)
1083
		if (!newDirty) {
1056
			fDirtyViewers.clear();
1084
			fLeftDirtyViewer = null;
1057
		if (oldDirty != dirty)
1085
			fRightDirtyViewer = null;
1058
			Utilities.firePropertyChange(fListenerList, this, DIRTY_STATE, Boolean.valueOf(oldDirty), Boolean.valueOf(dirty));
1086
		}
1087
		if (oldDirty != isSaveNeeded()) {
1088
			Utilities.firePropertyChange(fListenerList, this, DIRTY_STATE, Boolean.valueOf(oldDirty), Boolean.valueOf(isSaveNeeded()));
1089
		}
1059
	}
1090
	}
1060
	
1091
	
1092
	/**
1093
	 * Method adds or removes viewers that changed left or right side of this
1094
	 * compare input. Any modification of any of the list of viewers may result
1095
	 * in dirty state change.
1096
	 * 
1097
	 * @param source
1098
	 *            the object that fired <code>PropertyChangeEvent</code>
1099
	 *            modifying the dirty state
1100
	 * @param dirty
1101
	 *            value that describes if the changes were added or removed
1102
	 */
1061
	private void setDirty(Object source, boolean dirty) {
1103
	private void setDirty(Object source, boolean dirty) {
1062
		Assert.isNotNull(source);
1104
		Assert.isNotNull(source);
1063
		boolean oldDirty= fDirty || fDirtyViewers.size() > 0;
1105
		boolean oldDirty = isSaveNeeded();
1064
		if (dirty)
1106
		ContentMergeViewer cmv = (ContentMergeViewer) source;
1065
			fDirtyViewers.add(source);
1107
		if (dirty) {
1066
		else
1108
			if (cmv.isLeftDirty()) {
1067
			fDirtyViewers.remove(source);
1109
				if (fLeftDirtyViewer == null) {
1068
		boolean newDirty= fDirty || fDirtyViewers.size() > 0;
1110
					fLeftDirtyViewer = cmv;
1069
		if (DEBUG) System.out.println("setDirty("+source+", "+dirty+"): " + newDirty); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1111
				}
1070
		if (oldDirty != newDirty)
1112
			}
1113
			if (cmv.isRightDirty()) {
1114
				if (fRightDirtyViewer == null) {
1115
					fRightDirtyViewer = cmv;
1116
				}
1117
			}
1118
		} else {
1119
			if (!cmv.isLeftDirty()) {
1120
				fLeftDirtyViewer = null;
1121
			}
1122
			if (!cmv.isRightDirty()) {
1123
				fRightDirtyViewer = null;
1124
			}
1125
		}
1126
		boolean newDirty = isSaveNeeded();
1127
		if (DEBUG) {
1128
			System.out.println("setDirty(" + source + ", " + dirty + "): " + newDirty); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1129
		}
1130
		if (oldDirty != newDirty) {
1071
			Utilities.firePropertyChange(fListenerList, this, DIRTY_STATE, Boolean.valueOf(oldDirty), Boolean.valueOf(newDirty));
1131
			Utilities.firePropertyChange(fListenerList, this, DIRTY_STATE, Boolean.valueOf(oldDirty), Boolean.valueOf(newDirty));
1132
		}
1072
	}
1133
	}
1073
	
1134
	
1074
	/* (non Javadoc)
1135
	/* (non Javadoc)
Lines 1129-1135 Link Here
1129
		flushViewer(fStructurePane2, monitor);
1190
		flushViewer(fStructurePane2, monitor);
1130
		flushViewer(fContentInputPane, monitor);
1191
		flushViewer(fContentInputPane, monitor);
1131
	}
1192
	}
1132
		
1193
	
1194
	protected void flushLeftViewers(IProgressMonitor monitor) {
1195
		// flush changes in left dirty viewer
1196
		flushViewer(fStructureInputPane, monitor, LEFT_SIDE);
1197
		flushViewer(fStructurePane1, monitor, LEFT_SIDE);
1198
		flushViewer(fStructurePane2, monitor, LEFT_SIDE);
1199
		flushViewer(fContentInputPane, monitor, LEFT_SIDE);
1200
	}
1201
1202
	protected void flushRightViewers(IProgressMonitor monitor) {
1203
		// flush changes in right dirty viewer
1204
		flushViewer(fStructureInputPane, monitor, RIGHT_SIDE);
1205
		flushViewer(fStructurePane1, monitor, RIGHT_SIDE);
1206
		flushViewer(fStructurePane2, monitor, RIGHT_SIDE);
1207
		flushViewer(fContentInputPane, monitor, RIGHT_SIDE);
1208
	}
1209
	
1133
	private static void flushViewer(CompareViewerPane pane, IProgressMonitor pm) {
1210
	private static void flushViewer(CompareViewerPane pane, IProgressMonitor pm) {
1134
		if (pane != null) {
1211
		if (pane != null) {
1135
			IFlushable flushable = (IFlushable)Utilities.getAdapter(pane, IFlushable.class);
1212
			IFlushable flushable = (IFlushable)Utilities.getAdapter(pane, IFlushable.class);
Lines 1138-1143 Link Here
1138
		}
1215
		}
1139
	}
1216
	}
1140
	
1217
	
1218
	private static void flushViewer(CompareViewerPane pane, IProgressMonitor pm, int side) {
1219
		if (pane != null) {
1220
			IFlushable2 flushable = (IFlushable2)Utilities.getAdapter(pane, IFlushable2.class);
1221
			if (flushable != null)
1222
				flushable.flush(side, pm);
1223
		}
1224
	}
1225
	
1141
	/* (non-Javadoc)
1226
	/* (non-Javadoc)
1142
	 * @see org.eclipse.compare.ICompareContainer#addCompareInputChangeListener(org.eclipse.compare.structuremergeviewer.ICompareInput, org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener)
1227
	 * @see org.eclipse.compare.ICompareContainer#addCompareInputChangeListener(org.eclipse.compare.structuremergeviewer.ICompareInput, org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener)
1143
	 */
1228
	 */
(-)compare/org/eclipse/compare/CompareViewerSwitchingPane.java (+9 lines)
Lines 11-16 Link Here
11
package org.eclipse.compare;
11
package org.eclipse.compare;
12
12
13
import org.eclipse.compare.contentmergeviewer.IFlushable;
13
import org.eclipse.compare.contentmergeviewer.IFlushable;
14
import org.eclipse.compare.contentmergeviewer.IFlushable2;
14
import org.eclipse.compare.internal.CompareMessages;
15
import org.eclipse.compare.internal.CompareMessages;
15
import org.eclipse.compare.internal.NullViewer;
16
import org.eclipse.compare.internal.NullViewer;
16
import org.eclipse.compare.internal.Utilities;
17
import org.eclipse.compare.internal.Utilities;
Lines 354-359 Link Here
354
					return flushable;
355
					return flushable;
355
			}
356
			}
356
		}
357
		}
358
		if (adapter == IFlushable2.class) {
359
			Viewer v= getViewer();
360
			if (v != null) {
361
				IFlushable2 flushable = (IFlushable2)Utilities.getAdapter(v, IFlushable2.class);
362
				if (flushable != null)
363
					return flushable;
364
			}
365
		}
357
		return super.getAdapter(adapter);
366
		return super.getAdapter(adapter);
358
	}
367
	}
359
	
368
	
(-)compare/org/eclipse/compare/contentmergeviewer/ContentMergeViewer.java (-31 / +45 lines)
Lines 102-108 Link Here
102
 * @see TextMergeViewer
102
 * @see TextMergeViewer
103
 */
103
 */
104
public abstract class ContentMergeViewer extends ContentViewer
104
public abstract class ContentMergeViewer extends ContentViewer
105
					implements IPropertyChangeNotifier, IFlushable {
105
					implements IPropertyChangeNotifier, IFlushable, IFlushable2 {
106
	
106
	
107
	/* package */ static final int HORIZONTAL= 1;
107
	/* package */ static final int HORIZONTAL= 1;
108
	/* package */ static final int VERTICAL= 2;
108
	/* package */ static final int VERTICAL= 2;
Lines 1168-1176 Link Here
1168
	protected void setLeftDirty(boolean dirty) {
1168
	protected void setLeftDirty(boolean dirty) {
1169
		if (isLeftDirty() != dirty) {
1169
		if (isLeftDirty() != dirty) {
1170
			fIsLeftDirty = dirty;
1170
			fIsLeftDirty = dirty;
1171
			// Only fire the event if the combined dirty state has changed
1171
			// Always fire the event if the dirty state has changed
1172
			if (!isRightDirty())
1172
			fireDirtyState(dirty);
1173
				fireDirtyState(dirty);
1174
		}
1173
		}
1175
	}
1174
	}
1176
	
1175
	
Lines 1186-1194 Link Here
1186
	protected void setRightDirty(boolean dirty) {
1185
	protected void setRightDirty(boolean dirty) {
1187
		if (isRightDirty() != dirty) {
1186
		if (isRightDirty() != dirty) {
1188
			fIsRightDirty = dirty;
1187
			fIsRightDirty = dirty;
1189
			// Only fire the event if the combined dirty state has changed
1188
			// Always fire the event if the dirty state has changed
1190
			if (!isLeftDirty())
1189
			fireDirtyState(dirty);
1191
				fireDirtyState(dirty);
1192
		}
1190
		}
1193
	}
1191
	}
1194
	
1192
	
Lines 1216-1262 Link Here
1216
		flushContent(getInput(), monitor);
1214
		flushContent(getInput(), monitor);
1217
	}
1215
	}
1218
	
1216
	
1219
	/**
1217
	public final void flush(int side, IProgressMonitor monitor) {
1220
	 * Flush the modified content back to input elements via the content provider.
1218
		if (side == CompareEditorInput.LEFT_SIDE) {
1221
	 * The provided input may be the current input of the viewer or it may be
1219
			flushLeftSide(getInput(), monitor);
1222
	 * the previous input (i.e. this method may be called to flush modified content
1220
		} else if (side == CompareEditorInput.RIGHT_SIDE) {
1223
	 * during an input change).
1221
			flushRightSide(getInput(), monitor);
1224
	 * @param input the compare input
1222
		}
1225
	 * @param monitor a progress monitor or <code>null</code> if the method
1223
	}
1226
	 * was call from a place where a progress monitor was not available.
1224
1227
	 * @since 3.3
1225
	protected void flushLeftSide(Object input, IProgressMonitor monitor) {
1228
	 */
1226
		IMergeViewerContentProvider content = (IMergeViewerContentProvider) getContentProvider();
1229
	protected void flushContent(Object input, IProgressMonitor monitor) {
1227
1230
				
1228
		boolean rightEmpty = content.getRightContent(input) == null;
1231
		// write back modified contents
1232
		IMergeViewerContentProvider content= (IMergeViewerContentProvider) getContentProvider();
1233
		
1234
		boolean leftEmpty= content.getLeftContent(input) == null;
1235
		boolean rightEmpty= content.getRightContent(input) == null;
1236
1229
1237
		if (getCompareConfiguration().isLeftEditable() && isLeftDirty()) {
1230
		if (getCompareConfiguration().isLeftEditable() && isLeftDirty()) {
1238
			byte[] bytes= getContents(true);
1231
			byte[] bytes = getContents(true);
1239
			if (rightEmpty && bytes != null && bytes.length == 0)
1232
			if (rightEmpty && bytes != null && bytes.length == 0)
1240
				bytes= null;
1233
				bytes = null;
1241
			setLeftDirty(false);
1234
			setLeftDirty(false);
1242
			content.saveLeftContent(input, bytes);
1235
			content.saveLeftContent(input, bytes);
1243
		}
1236
		}
1244
		
1237
	}
1238
1239
	protected void flushRightSide(Object input, IProgressMonitor monitor) {
1240
		IMergeViewerContentProvider content = (IMergeViewerContentProvider) getContentProvider();
1241
1242
		boolean leftEmpty = content.getLeftContent(input) == null;
1243
1245
		if (getCompareConfiguration().isRightEditable() && isRightDirty()) {
1244
		if (getCompareConfiguration().isRightEditable() && isRightDirty()) {
1246
			byte[] bytes= getContents(false);
1245
			byte[] bytes = getContents(false);
1247
			if (leftEmpty && bytes != null && bytes.length == 0)
1246
			if (leftEmpty && bytes != null && bytes.length == 0)
1248
				bytes= null;
1247
				bytes = null;
1249
			setRightDirty(false);
1248
			setRightDirty(false);
1250
			content.saveRightContent(input, bytes);
1249
			content.saveRightContent(input, bytes);
1251
		}
1250
		}
1252
	}
1251
	}
1253
1252
1254
	/**
1253
	/**
1254
	 * Flush the modified content back to input elements via the content provider.
1255
	 * The provided input may be the current input of the viewer or it may be
1256
	 * the previous input (i.e. this method may be called to flush modified content
1257
	 * during an input change).
1258
	 * @param input the compare input
1259
	 * @param monitor a progress monitor or <code>null</code> if the method
1260
	 * was call from a place where a progress monitor was not available.
1261
	 * @since 3.3
1262
	 */
1263
	protected void flushContent(Object input, IProgressMonitor monitor) {
1264
		flushLeftSide(input, monitor);
1265
		flushRightSide(input, monitor);
1266
	}
1267
1268
	/**
1255
	 * Return the dirty state of the right side of this viewer.
1269
	 * Return the dirty state of the right side of this viewer.
1256
	 * @return the dirty state of the right side of this viewer
1270
	 * @return the dirty state of the right side of this viewer
1257
	 * @since 3.3
1271
	 * @since 3.3
1258
	 */
1272
	 */
1259
	protected boolean isRightDirty() {
1273
	public boolean isRightDirty() {
1260
		return fIsRightDirty;
1274
		return fIsRightDirty;
1261
	}
1275
	}
1262
1276
Lines 1265-1271 Link Here
1265
	 * @return the dirty state of the left side of this viewer
1279
	 * @return the dirty state of the left side of this viewer
1266
	 * @since 3.3
1280
	 * @since 3.3
1267
	 */
1281
	 */
1268
	protected boolean isLeftDirty() {
1282
	public boolean isLeftDirty() {
1269
		return fIsLeftDirty;
1283
		return fIsLeftDirty;
1270
	}
1284
	}
1271
1285
(-)compare/org/eclipse/compare/contentmergeviewer/IFlushable2.java (+7 lines)
Added Link Here
1
package org.eclipse.compare.contentmergeviewer;
2
3
import org.eclipse.core.runtime.IProgressMonitor;
4
5
public interface IFlushable2 {
6
	void flush(int side, IProgressMonitor monitor);
7
}
(-)compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java (-8 / +17 lines)
Lines 4838-4852 Link Here
4838
		return fMerger.virtualToRealPosition(contributor, v);
4838
		return fMerger.virtualToRealPosition(contributor, v);
4839
	}
4839
	}
4840
	
4840
	
4841
	/* (non-Javadoc)
4841
	protected void flushLeftSide(Object oldInput, IProgressMonitor monitor){
4842
	 * @see org.eclipse.compare.contentmergeviewer.ContentMergeViewer#flushContent(java.lang.Object, org.eclipse.core.runtime.IProgressMonitor)
4843
	 */
4844
	protected void flushContent(Object oldInput, IProgressMonitor monitor) {
4845
				
4846
		// check and handle any shared buffers
4847
		IMergeViewerContentProvider content= getMergeContentProvider();
4842
		IMergeViewerContentProvider content= getMergeContentProvider();
4848
		Object leftContent = content.getLeftContent(oldInput);
4843
		Object leftContent = content.getLeftContent(oldInput);
4849
		Object rightContent = content.getRightContent(oldInput);
4850
		
4844
		
4851
		if (leftContent != null && getCompareConfiguration().isLeftEditable() && isLeftDirty()) {
4845
		if (leftContent != null && getCompareConfiguration().isLeftEditable() && isLeftDirty()) {
4852
			if (fLeftContributor.hasSharedDocument(leftContent)) {
4846
			if (fLeftContributor.hasSharedDocument(leftContent)) {
Lines 4854-4859 Link Here
4854
					setLeftDirty(false);
4848
					setLeftDirty(false);
4855
			}
4849
			}
4856
		}
4850
		}
4851
	}
4852
	
4853
	protected void flushRightSide(Object oldInput, IProgressMonitor monitor){
4854
		IMergeViewerContentProvider content= getMergeContentProvider();
4855
		Object rightContent = content.getRightContent(oldInput);
4857
		
4856
		
4858
		if (rightContent != null && getCompareConfiguration().isRightEditable() && isRightDirty()) {
4857
		if (rightContent != null && getCompareConfiguration().isRightEditable() && isRightDirty()) {
4859
			if (fRightContributor.hasSharedDocument(rightContent)) {
4858
			if (fRightContributor.hasSharedDocument(rightContent)) {
Lines 4861-4867 Link Here
4861
					setRightDirty(false);
4860
					setRightDirty(false);
4862
			}
4861
			}
4863
		}
4862
		}
4864
		
4863
	}
4864
	
4865
	/* (non-Javadoc)
4866
	 * @see org.eclipse.compare.contentmergeviewer.ContentMergeViewer#flushContent(java.lang.Object, org.eclipse.core.runtime.IProgressMonitor)
4867
	 */
4868
	protected void flushContent(Object oldInput, IProgressMonitor monitor) {
4869
		flushLeftSide(oldInput, monitor);
4870
		flushRightSide(oldInput, monitor);
4871
4872
		IMergeViewerContentProvider content = getMergeContentProvider();
4873
4865
		if (!(content instanceof MergeViewerContentProvider) || isLeftDirty() || isRightDirty()) {
4874
		if (!(content instanceof MergeViewerContentProvider) || isLeftDirty() || isRightDirty()) {
4866
			super.flushContent(oldInput, monitor);
4875
			super.flushContent(oldInput, monitor);
4867
		}
4876
		}
(-)src/org/eclipse/team/internal/ui/synchronize/LocalResourceSaveableComparison.java (-2 / +21 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
2
 * Copyright (c) 2006, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 150-156 Link Here
150
	 * @throws CoreException
150
	 * @throws CoreException
151
	 */
151
	 */
152
	protected void flushViewers(IProgressMonitor monitor) throws CoreException {
152
	protected void flushViewers(IProgressMonitor monitor) throws CoreException {
153
		editorInput.saveChanges(monitor);
153
		if (editorInput instanceof SaveablesCompareEditorInput) {
154
			((SaveablesCompareEditorInput) editorInput).saveChanges(monitor, this);
155
		} else {
156
			editorInput.saveChanges(monitor);
157
		}
154
	}
158
	}
155
159
156
	/**
160
	/**
Lines 206-211 Link Here
206
	public boolean isDirty() {
210
	public boolean isDirty() {
207
		// We need to get the dirty state from the compare editor input
211
		// We need to get the dirty state from the compare editor input
208
		// since it is our only connection to the merge viewer
212
		// since it is our only connection to the merge viewer
213
		if (editorInput instanceof SaveablesCompareEditorInput) {
214
			return ((SaveablesCompareEditorInput) editorInput).isSaveNeeded(this);
215
		}
209
		return editorInput.isSaveNeeded();
216
		return editorInput.isSaveNeeded();
210
	}
217
	}
211
	
218
	
Lines 232-237 Link Here
232
	 * @see org.eclipse.ui.Saveable#getName()
239
	 * @see org.eclipse.ui.Saveable#getName()
233
	 */
240
	 */
234
	public String getName() {
241
	public String getName() {
242
		// When we compare two files with each other we need to know the exact
243
		// name of each of the files, not the name taken from the input. Input
244
		// gives the name based on the main element of the input. The way how
245
		// the main element is calculated is described in method
246
		// org.eclipse.team.internal.ui.mapping.AbstractCompareInput#getMainElement()
247
		// See bug 273450.
248
		if (fileElement.equals(input.getLeft())) {
249
			return input.getLeft().getName();
250
		}
251
		if (fileElement.equals(input.getRight())) {
252
			return input.getRight().getName();
253
		}
235
		return input.getName();
254
		return input.getName();
236
	}
255
	}
237
256
(-)src/org/eclipse/team/internal/ui/synchronize/SaveablesCompareEditorInput.java (+34 lines)
Lines 359-364 Link Here
359
		return super.isDirty();
359
		return super.isDirty();
360
	}
360
	}
361
361
362
	/* package */ boolean isSaveNeeded(Saveable saveable) {
363
		// Method gives information if the Saveable given as a parameter needs
364
		// to be saved. Parameter arg can be either equal to fLeftSaveable or to
365
		// fRightSaveable. If the parameter is null or differs from both left
366
		// and right Saveable then default isSaveNeeded() is called. Default
367
		// method isSaveNeeded() is not aware which Saveable we wish to check
368
		// therefore it returns the state of the whole CompareEditorInput.
369
		// Whenever possible this method should be called instead of default
370
		// isSaveNeeded(). See bug 273450.
371
		if (saveable == null) {
372
			return isSaveNeeded();
373
		}
374
		if (saveable.equals(fLeftSaveable)) {
375
			return isLeftSaveNeeded();
376
		}
377
		if (saveable.equals(fRightSaveable)) {
378
			return isRightSaveNeeded();
379
		}
380
		return isSaveNeeded();
381
	}
382
383
	public void saveChanges(IProgressMonitor monitor, Saveable saveable)
384
			throws CoreException {
385
		if (saveable == null) {
386
			super.flushViewers(monitor);
387
		} else if (saveable.equals(fLeftSaveable)) {
388
			flushLeftViewers(monitor);
389
		} else if (saveable.equals(fRightSaveable)) {
390
			flushRightViewers(monitor);
391
		} else {
392
			super.flushViewers(monitor);
393
		}
394
	}
395
362
	/**
396
	/**
363
	 * Close the editor if it is not dirty. If it is still dirty, let the
397
	 * Close the editor if it is not dirty. If it is still dirty, let the
364
	 * content merge viewer handle the compare input change.
398
	 * content merge viewer handle the compare input change.

Return to bug 273450