Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndre Weinand2002-05-15 10:06:04 +0000
committerAndre Weinand2002-05-15 10:06:04 +0000
commit064081f9af07efc402353a13800597480a058818 (patch)
tree694043b881c3f76623c78544b1df45cd487b47bf /bundles/org.eclipse.compare/compare/org/eclipse/compare
parentf47b6c6176984f79d19e56cb64630fd1f4fd65cd (diff)
downloadeclipse.platform.team-064081f9af07efc402353a13800597480a058818.tar.gz
eclipse.platform.team-064081f9af07efc402353a13800597480a058818.tar.xz
eclipse.platform.team-064081f9af07efc402353a13800597480a058818.zip
#14371, #14378
Diffstat (limited to 'bundles/org.eclipse.compare/compare/org/eclipse/compare')
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java53
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java9
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ResourceCompareInput.java13
3 files changed, 54 insertions, 21 deletions
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java
index a547d7261..f9d371eb5 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java
@@ -89,6 +89,8 @@ import org.eclipse.compare.structuremergeviewer.*;
*/
public abstract class CompareEditorInput implements IEditorInput, IPropertyChangeNotifier, IRunnableWithProgress {
+ private static final boolean DEBUG= false;
+
/**
* The name of the "dirty" property.
*/
@@ -111,6 +113,7 @@ public abstract class CompareEditorInput implements IEditorInput, IPropertyChang
private ListenerList fListenerList= new ListenerList();
private CompareNavigator fNavigator;
private boolean fDirty= false;
+ private ArrayList fDirtyViewers= new ArrayList();
private IPropertyChangeListener fDirtyStateListener;
private IgnoreWhiteSpaceAction fIgnoreWhitespace;
@@ -135,11 +138,12 @@ public abstract class CompareEditorInput implements IEditorInput, IPropertyChang
fDirtyStateListener= new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e) {
- if (Utilities.getValue(e, false))
- setDirty(true);
+ String propertyName= e.getProperty();
+ if (CompareEditorInput.DIRTY_STATE.equals(propertyName))
+ setDirty(e.getSource(), Utilities.getValue(e, false));
}
};
-
+
IPreferenceStore ps= configuration.getPreferenceStore();
if (ps != null)
fStructureCompareOnSingleClick= ps.getBoolean(ComparePreferencePage.OPEN_STRUCTURE_COMPARE);
@@ -614,13 +618,17 @@ public abstract class CompareEditorInput implements IEditorInput, IPropertyChang
* @return a compare viewer which is suitable for the given input object or <code>null</code>
*/
public Viewer findContentViewer(Viewer oldViewer, ICompareInput input, Composite parent) {
- Viewer v= CompareUIPlugin.findContentViewer(oldViewer, input, parent, fCompareConfiguration);
+
+ Viewer newViewer= CompareUIPlugin.findContentViewer(oldViewer, input, parent, fCompareConfiguration);
- if (v instanceof IPropertyChangeNotifier) {
- final IPropertyChangeNotifier dsp= (IPropertyChangeNotifier) v;
+ boolean isNewViewer= newViewer != oldViewer;
+ if (DEBUG) System.out.println("CompareEditorInput.findContentViewer: " + isNewViewer);
+
+ if (isNewViewer && newViewer instanceof IPropertyChangeNotifier) {
+ final IPropertyChangeNotifier dsp= (IPropertyChangeNotifier) newViewer;
dsp.addPropertyChangeListener(fDirtyStateListener);
- Control c= v.getControl();
+ Control c= newViewer.getControl();
c.addDisposeListener(
new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
@@ -630,7 +638,7 @@ public abstract class CompareEditorInput implements IEditorInput, IPropertyChang
);
}
- return v;
+ return newViewer;
}
/**
@@ -645,7 +653,7 @@ public abstract class CompareEditorInput implements IEditorInput, IPropertyChang
* @return <code>true</code> if there are changes that need to be saved
*/
public boolean isSaveNeeded() {
- return fDirty;
+ return fDirty || fDirtyViewers.size() > 0;
}
/**
@@ -655,13 +663,32 @@ public abstract class CompareEditorInput implements IEditorInput, IPropertyChang
* @param dirty the dirty state for this compare input
*/
public void setDirty(boolean dirty) {
- if (dirty != fDirty) {
- boolean old= fDirty;
+
+ boolean confirmSave= true;
+ Object o= fCompareConfiguration.getProperty(CompareEditor.CONFIRM_SAVE_PROPERTY);
+ if (o instanceof Boolean)
+ confirmSave= ((Boolean)o).booleanValue();
+
+ if (!confirmSave) {
fDirty= dirty;
- Utilities.firePropertyChange(fListenerList, this, DIRTY_STATE, new Boolean(old), new Boolean(fDirty));
+ if (!fDirty)
+ fDirtyViewers.clear();
}
}
+ private void setDirty(Object source, boolean dirty) {
+ Assert.isNotNull(source);
+ boolean oldDirty= fDirtyViewers.size() > 0;
+ if (dirty)
+ fDirtyViewers.add(source);
+ else
+ fDirtyViewers.remove(source);
+ boolean newDirty= fDirtyViewers.size() > 0;
+ if (DEBUG) System.out.println("setDirty("+source+", "+dirty+"): " + newDirty);
+ if (oldDirty != newDirty)
+ Utilities.firePropertyChange(fListenerList, this, DIRTY_STATE, new Boolean(oldDirty), new Boolean(newDirty));
+ }
+
/* (non Javadoc)
* see IPropertyChangeNotifier.addListener
*/
@@ -691,7 +718,7 @@ public abstract class CompareEditorInput implements IEditorInput, IPropertyChang
* Save any unsaved changes.
* Subclasses must override to save any changes.
* This implementation tries to flush changes in all viewers by
- * calling <code>setInput</code> on them.
+ * calling <code>ISavable.save</code> on them.
*
* @param progressMonitor an <code>IProgressMonitor</code> that the implementation of save may use to show progress
*/
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
index 6d0fee4f7..11921a2f6 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
@@ -1118,14 +1118,13 @@ public class TextMergeViewer extends ContentMergeViewer {
return null;
}
+ /**
+ * Returns true if the given inputs map to the same documents
+ */
boolean sameDoc(char type, Object newInput, Object oldInput) {
IDocument newDoc= getDocument2(type, newInput);
IDocument oldDoc= getDocument2(type, oldInput);
- if (newDoc == oldDoc)
- return true;
- if (newDoc == null || oldDoc == null)
- return true;
- return false;
+ return newDoc == oldDoc;
}
/**
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ResourceCompareInput.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ResourceCompareInput.java
index ad53bbac8..02a07d33b 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ResourceCompareInput.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ResourceCompareInput.java
@@ -54,12 +54,14 @@ class ResourceCompareInput extends CompareEditorInput {
if (fDiffViewer != null)
fDiffViewer.refresh(this);
}
-
+ void clearDirty() {
+ fDirty= false;
+ }
public String getName() {
if (fLastName == null)
fLastName= super.getName();
if (fDirty)
- return fLastName + " *"; //$NON-NLS-1$
+ return '<' + fLastName + '>';
return fLastName;
}
@@ -231,7 +233,9 @@ class ResourceCompareInput extends CompareEditorInput {
if (fRoot instanceof DiffNode) {
try {
commit(pm, (DiffNode) fRoot);
- } finally {
+ } finally {
+ if (fDiffViewer != null)
+ fDiffViewer.refresh();
setDirty(false);
}
}
@@ -242,6 +246,9 @@ class ResourceCompareInput extends CompareEditorInput {
*/
private static void commit(IProgressMonitor pm, DiffNode node) throws CoreException {
+ if (node instanceof MyDiffNode)
+ ((MyDiffNode)node).clearDirty();
+
ITypedElement left= node.getLeft();
if (left instanceof BufferedResourceNode)
((BufferedResourceNode) left).commit(pm);

Back to the top