Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndre Weinand2002-03-12 16:52:12 +0000
committerAndre Weinand2002-03-12 16:52:12 +0000
commit0b9c7481e4d54d92d419cac3237d5a36439d6072 (patch)
treee099aa51da9f31da35d8ee3d45d28ecee49afb1b
parent36f16f9018c7db7a8cc2f8f2c084d80b0c3f70bd (diff)
downloadeclipse.platform.team-0b9c7481e4d54d92d419cac3237d5a36439d6072.tar.gz
eclipse.platform.team-0b9c7481e4d54d92d419cac3237d5a36439d6072.tar.xz
eclipse.platform.team-0b9c7481e4d54d92d419cac3237d5a36439d6072.zip
structure compare is always on
-rw-r--r--bundles/org.eclipse.compare/.classpath2
-rw-r--r--bundles/org.eclipse.compare/buildnotes_compare.html30
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java37
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java19
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/ContentMergeViewer.java47
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/IDocumentRange.java2
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java580
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/DocumentManager.java59
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ISavable.java13
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ViewerDescriptor.java13
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PreviewPatchPage.java2
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewer.java27
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewerResources.properties7
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DocumentRangeNode.java18
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/.classpath2
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/buildnotes_compare.html30
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java37
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java19
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/ContentMergeViewer.java47
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/IDocumentRange.java2
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java580
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/DocumentManager.java59
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ISavable.java13
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ViewerDescriptor.java13
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PreviewPatchPage.java2
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewer.java27
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewerResources.properties7
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DocumentRangeNode.java18
28 files changed, 1394 insertions, 318 deletions
diff --git a/bundles/org.eclipse.compare/.classpath b/bundles/org.eclipse.compare/.classpath
index ce863b74a..d8b8ad011 100644
--- a/bundles/org.eclipse.compare/.classpath
+++ b/bundles/org.eclipse.compare/.classpath
@@ -5,7 +5,7 @@
<classpathentry kind="src" path="/org.eclipse.core.runtime"/>
<classpathentry kind="src" path="/org.eclipse.ui"/>
<classpathentry kind="src" path="/org.eclipse.core.resources"/>
- <classpathentry exported="true" kind="lib" path="compare.jar" sourcepath="/org.eclipse.compare/comparesrc.zip"/>
+ <classpathentry exported="true" kind="lib" path="compare.jar"/>
<classpathentry kind="var" path="JRE_LIB" rootpath="JRE_SRCROOT" sourcepath="JRE_SRC"/>
<classpathentry kind="src" path="/org.eclipse.swt"/>
<classpathentry kind="output" path="bin"/>
diff --git a/bundles/org.eclipse.compare/buildnotes_compare.html b/bundles/org.eclipse.compare/buildnotes_compare.html
index 0c0ce4004..ba0c3d36f 100644
--- a/bundles/org.eclipse.compare/buildnotes_compare.html
+++ b/bundles/org.eclipse.compare/buildnotes_compare.html
@@ -11,6 +11,36 @@
<h1>
Eclipse Platform Build Notes<br>
Compare</h1>
+Eclipse Build Input March 12th 2002
+
+<h2>
+What's new in this drop</h2>
+Structure Compare viewers are enabled by default.<br>
+
+<h3>
+API changes</h3>
+
+<h3>
+API Additions</h3>
+
+<h3>
+Other highlights</h3>
+
+<h2>
+Known deficiencies</h2>
+
+<h2>
+Problem reports fixed</h2>
+<a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=10379">#10379</a>: Compare with Local History Dialog: lower pane is missing a bordeer<br>
+<a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=9768">#9768</a>: (empty-menu) in compare view<br>
+<a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=9842">#9842</a>: Expand All action needed in structure compare view<br>
+
+
+<h2>
+Problem reports closed</h2>
+
+<h1>
+<hr WIDTH="100%"></h1>
Eclipse Build Input March 5th 2002
<h2>
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 1f25f0901..d6ac8c45d 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java
@@ -89,12 +89,6 @@ import org.eclipse.compare.structuremergeviewer.*;
public abstract class CompareEditorInput implements IEditorInput, IPropertyChangeNotifier, IRunnableWithProgress {
/**
- * Work in progres !!
- * SHOW_STRUCTURE is not public API.
- */
- public static final boolean SHOW_STRUCTURE= false;
-
- /**
* The name of the "dirty" property.
*/
public static final String DIRTY_STATE= "DIRTY_STATE"; //$NON-NLS-1$
@@ -121,7 +115,7 @@ public abstract class CompareEditorInput implements IEditorInput, IPropertyChang
private IgnoreWhiteSpaceAction fIgnoreWhitespace;
private ShowPseudoConflicts fShowPseudoConflicts;
- boolean fStructureCompareOnSingleClick= false;
+ boolean fStructureCompareOnSingleClick= true;
/**
* Creates a <code>CompareEditorInput</code> which is initialized with the given
@@ -621,14 +615,8 @@ public abstract class CompareEditorInput implements IEditorInput, IPropertyChang
public Viewer findContentViewer(Viewer oldViewer, ICompareInput input, Composite parent) {
Viewer v= CompareUIPlugin.findContentViewer(oldViewer, input, parent, fCompareConfiguration);
- if (SHOW_STRUCTURE) {
- if (oldViewer != null && v != null && oldViewer.getClass() == v.getClass())
- v= oldViewer;
- }
-
if (v instanceof IPropertyChangeNotifier) {
final IPropertyChangeNotifier dsp= (IPropertyChangeNotifier) v;
-
dsp.addPropertyChangeListener(fDirtyStateListener);
Control c= v.getControl();
@@ -709,28 +697,19 @@ public abstract class CompareEditorInput implements IEditorInput, IPropertyChang
public void saveChanges(IProgressMonitor pm) throws CoreException {
// flush changes in any dirty viewer
- flushViewer(fStructureInputPane);
- flushViewer(fStructurePane1);
- flushViewer(fStructurePane2);
- flushViewer(fContentInputPane);
+ flushViewer(fStructureInputPane, pm);
+ flushViewer(fStructurePane1, pm);
+ flushViewer(fStructurePane2, pm);
+ flushViewer(fContentInputPane, pm);
save(pm);
}
- private static void flushViewer(CompareViewerSwitchingPane pane) {
+ private static void flushViewer(CompareViewerSwitchingPane pane, IProgressMonitor pm) throws CoreException {
if (pane != null) {
Viewer v= pane.getViewer();
- if (v != null) {
-
- // since we have already asked the user whether he wants to save
- // changes, we disable the confirmation alert in
- // ContentMergeViewer.inputChanged
- if (v instanceof ContentMergeViewer)
- ((ContentMergeViewer)v).setConfirmSave(false);
-
- Object input= pane.getInput();
- v.setInput(input);
- }
+ if (v instanceof ISavable)
+ ((ISavable)v).save(pm);
}
}
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java
index b5ab58a43..2530338e9 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java
@@ -88,11 +88,8 @@ public abstract class CompareViewerSwitchingPane extends CompareViewerPane
*/
private void setViewer(Viewer newViewer) {
- if (newViewer == fViewer) {
- if (CompareEditorInput.SHOW_STRUCTURE)
- System.out.println("Same viewer: " + fViewer.getClass().getName());
+ if (newViewer == fViewer)
return;
- }
boolean oldEmpty= isEmpty();
@@ -210,14 +207,12 @@ public abstract class CompareViewerSwitchingPane extends CompareViewerPane
boolean hadFocus= hasFocus2();
- if (! CompareEditorInput.SHOW_STRUCTURE) {
- try {
- if (fViewer != null)
- fViewer.setInput(null); // force save before switching viewer
- } catch (ViewerSwitchingCancelled ex) {
- return;
- }
- }
+// try {
+// if (fViewer != null)
+// fViewer.setInput(null); // force save before switching viewer
+// } catch (ViewerSwitchingCancelled ex) {
+// return;
+// }
fInput= input;
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/ContentMergeViewer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/ContentMergeViewer.java
index 2ba364cf1..7878ff22a 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/ContentMergeViewer.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/ContentMergeViewer.java
@@ -12,6 +12,9 @@ import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.custom.CLabel;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.CoreException;
+
import org.eclipse.jface.util.*;
import org.eclipse.jface.action.*;
import org.eclipse.jface.dialogs.*;
@@ -52,7 +55,8 @@ import org.eclipse.compare.internal.*;
* @see IMergeViewerContentProvider
* @see TextMergeViewer
*/
-public abstract class ContentMergeViewer extends ContentViewer implements IPropertyChangeNotifier {
+public abstract class ContentMergeViewer extends ContentViewer
+ implements IPropertyChangeNotifier, ISavable {
class SaveAction extends MergeViewerAction {
@@ -493,6 +497,23 @@ public abstract class ContentMergeViewer extends ContentViewer implements IPrope
if (oldInput instanceof ICompareInput)
((ICompareInput)oldInput).removeCompareInputChangeListener(fCompareInputChangeListener);
+ boolean success= doSave(input, oldInput);
+
+ if (input != oldInput)
+ if (input instanceof ICompareInput)
+ ((ICompareInput)input).addCompareInputChangeListener(fCompareInputChangeListener);
+
+ if (success) {
+ setLeftDirty(false);
+ setRightDirty(false);
+ }
+
+ if (input != oldInput)
+ internalRefresh(input);
+ }
+
+ protected boolean doSave(Object newInput, Object oldInput) {
+
// before setting the new input we have to save the old
if (fLeftSaveAction.isEnabled() || fRightSaveAction.isEnabled()) {
@@ -508,7 +529,7 @@ public abstract class ContentMergeViewer extends ContentViewer implements IPrope
new String[] {
IDialogConstants.YES_LABEL,
IDialogConstants.NO_LABEL,
- IDialogConstants.CANCEL_LABEL
+// IDialogConstants.CANCEL_LABEL
},
0); // default button index
@@ -525,19 +546,11 @@ public abstract class ContentMergeViewer extends ContentViewer implements IPrope
}
} else
saveContent(oldInput);
+ return true;
}
-
- if (input != oldInput)
- if (input instanceof ICompareInput)
- ((ICompareInput)input).addCompareInputChangeListener(fCompareInputChangeListener);
-
- setLeftDirty(false);
- setRightDirty(false);
-
- if (input != oldInput)
- internalRefresh(input);
+ return false;
}
-
+
public void setConfirmSave(boolean enable) {
fConfirmSave= enable;
}
@@ -890,6 +903,10 @@ public abstract class ContentMergeViewer extends ContentViewer implements IPrope
}
}
+ public void save(IProgressMonitor pm) throws CoreException {
+ saveContent(getInput());
+ }
+
/**
* Save modified content back to input elements via the content provider.
*/
@@ -898,8 +915,8 @@ public abstract class ContentMergeViewer extends ContentViewer implements IPrope
// write back modified contents
IMergeViewerContentProvider content= (IMergeViewerContentProvider) getContentProvider();
- boolean leftEmpty= content.getLeftContent(oldInput) != null;
- boolean rightEmpty= content.getRightContent(oldInput) != null;
+ boolean leftEmpty= content.getLeftContent(oldInput) == null;
+ boolean rightEmpty= content.getRightContent(oldInput) == null;
if (fCompareConfiguration.isLeftEditable() && fLeftSaveAction.isEnabled()) {
byte[] bytes= getContents(true);
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/IDocumentRange.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/IDocumentRange.java
index 1db51c482..a713fb44f 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/IDocumentRange.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/IDocumentRange.java
@@ -24,7 +24,7 @@ import org.eclipse.jface.text.IDocument;
*/
public interface IDocumentRange {
- public static final String RANGE_CATEGORY= "DocumentRangeCategory";
+ public static final String RANGE_CATEGORY= "DocumentRangeCategory"; //$NON-NLS-1$
/**
* Returns the underlying document.
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 50aaf9b71..b54d72dd1 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
@@ -62,8 +62,9 @@ import org.eclipse.compare.internal.MergeViewerAction;
import org.eclipse.compare.internal.INavigatable;
import org.eclipse.compare.internal.CompareNavigator;
import org.eclipse.compare.internal.TimeoutContext;
+import org.eclipse.compare.internal.DocumentManager;
import org.eclipse.compare.rangedifferencer.*;
-import org.eclipse.compare.structuremergeviewer.Differencer;
+import org.eclipse.compare.structuremergeviewer.*;
/**
* A text merge viewer uses the <code>RangeDifferencer</code> to perform a
@@ -113,6 +114,8 @@ import org.eclipse.compare.structuremergeviewer.Differencer;
*/
public class TextMergeViewer extends ContentMergeViewer {
+ private static final boolean DEBUG= true;
+
private static final String[] GLOBAL_ACTIONS= {
IWorkbenchActionConstants.UNDO,
IWorkbenchActionConstants.REDO,
@@ -133,9 +136,7 @@ public class TextMergeViewer extends ContentMergeViewer {
MergeSourceViewer.SELECT_ALL_ID,
MergeSourceViewer.SAVE_ID
};
-
- private static final String MY_UPDATER= "my_updater"; //$NON-NLS-1$
-
+
private static final String SYNC_SCROLLING= "SYNC_SCROLLING"; //$NON-NLS-1$
private static final String BUNDLE_NAME= "org.eclipse.compare.contentmergeviewer.TextMergeViewerResources"; //$NON-NLS-1$
@@ -207,6 +208,14 @@ public class TextMergeViewer extends ContentMergeViewer {
/** The current diff */
private Diff fCurrentDiff;
+ private HashMap fNewAncestorRanges= new HashMap();
+ private HashMap fNewLeftRanges= new HashMap();
+ private HashMap fNewRightRanges= new HashMap();
+
+ private Object fAncestorInput;
+ private Object fLeftInput;
+ private Object fRightInput;
+
private MergeSourceViewer fAncestor;
private MergeSourceViewer fLeft;
private MergeSourceViewer fRight;
@@ -223,6 +232,7 @@ public class TextMergeViewer extends ContentMergeViewer {
private boolean fIgnoreAncestor= false;
private ActionContributionItem fIgnoreAncestorItem;
+ private boolean fHiglightRanges;
private boolean fShowPseudoConflicts= false;
@@ -251,7 +261,57 @@ public class TextMergeViewer extends ContentMergeViewer {
private Map fColors;
private Font fFont;
-
+ /**
+ * The position updater used to adapt the positions representing
+ * the child document ranges to changes of the parent document.
+ */
+ class ChildPositionUpdater extends DefaultPositionUpdater {
+
+ /**
+ * Creates the position updated.
+ */
+ protected ChildPositionUpdater(String category) {
+ super(category);
+ }
+
+ /**
+ * Child document ranges cannot be deleted other then by calling
+ * freeChildDocument.
+ */
+ protected boolean notDeleted() {
+ return true;
+ }
+
+ /**
+ * If an insertion happens at a child document's start offset, the
+ * position is extended rather than shifted. Also, if something is added
+ * right behind the end of the position, the position is extended rather
+ * than kept stable.
+ */
+ protected void adaptToInsert() {
+
+ if (fPosition == fLeft.getRegion() || fPosition == fRight.getRegion()) {
+ int myStart= fPosition.offset;
+ int myEnd= fPosition.offset + fPosition.length;
+ myEnd= Math.max(myStart, myEnd);
+
+ int yoursStart= fOffset;
+ int yoursEnd= fOffset + fReplaceLength -1;
+ yoursEnd= Math.max(yoursStart, yoursEnd);
+
+ if (myEnd < yoursStart)
+ return;
+
+ if (myStart <= yoursStart)
+ fPosition.length += fReplaceLength;
+ else
+ fPosition.offset += fReplaceLength;
+ } else {
+ super.adaptToInsert();
+ }
+ }
+ }
+
/**
* A Diff represents synchronized character ranges in two or three Documents.
* The MergeTextViewer uses Diffs to find differences in line and token ranges.
@@ -275,16 +335,33 @@ public class TextMergeViewer extends ContentMergeViewer {
/**
* Create Diff from two ranges and an optional parent diff.
*/
- Diff(Diff parent, int dir, IDocument ancestorDoc, int ancestorStart, int ancestorEnd,
- IDocument leftDoc, int leftStart, int leftEnd,
- IDocument rightDoc, int rightStart, int rightEnd) {
+ Diff(Diff parent, int dir, IDocument ancestorDoc, Position aRange, int ancestorStart, int ancestorEnd,
+ IDocument leftDoc, Position lRange, int leftStart, int leftEnd,
+ IDocument rightDoc, Position rRange, int rightStart, int rightEnd) {
fParent= parent != null ? parent : this;
fDirection= dir;
- fLeftPos= createPosition(leftDoc, leftStart, leftEnd);
- fRightPos= createPosition(rightDoc, rightStart, rightEnd);
+ fLeftPos= createPosition(leftDoc, lRange, leftStart, leftEnd);
+ fRightPos= createPosition(rightDoc, rRange, rightStart, rightEnd);
if (ancestorDoc != null)
- fAncestorPos= createPosition(ancestorDoc, ancestorStart, ancestorEnd);
+ fAncestorPos= createPosition(ancestorDoc, aRange, ancestorStart, ancestorEnd);
+ }
+
+ Position getPosition(char type) {
+ switch (type) {
+ case 'A':
+ return fAncestorPos;
+ case 'L':
+ return fLeftPos;
+ case 'R':
+ return fRightPos;
+ }
+ return null;
+ }
+
+ boolean isInRange(char type, int pos) {
+ Position p= getPosition(type);
+ return (pos >= p.offset) && (pos < (p.offset+p.length));
}
String changeType() {
@@ -324,12 +401,18 @@ public class TextMergeViewer extends ContentMergeViewer {
return null;
}
- Position createPosition(IDocument doc, int start, int end) {
+ Position createPosition(IDocument doc, Position range, int start, int end) {
try {
- int dl= doc.getLength();
int l= end-start;
- if (start+l > dl)
- l= dl-start;
+ if (range != null) {
+ int dl= range.length;
+ if (l > dl)
+ l= dl;
+ } else {
+ int dl= doc.getLength();
+ if (start+l > dl)
+ l= dl-start;
+ }
Position p= null;
try {
@@ -339,7 +422,7 @@ public class TextMergeViewer extends ContentMergeViewer {
}
try {
- doc.addPosition(MY_UPDATER, p);
+ doc.addPosition(IDocumentRange.RANGE_CATEGORY, p);
} catch (BadPositionCategoryException ex) {
}
return p;
@@ -360,7 +443,7 @@ public class TextMergeViewer extends ContentMergeViewer {
return true;
return fLeftPos.isDeleted() || fRightPos.isDeleted();
}
-
+
void setResolved(boolean r) {
fResolved= r;
if (r)
@@ -554,6 +637,14 @@ public class TextMergeViewer extends ContentMergeViewer {
*/
protected void handleDispose(DisposeEvent event) {
+ Object input= getInput();
+ DocumentManager.remove(getDocument2('A', input));
+ DocumentManager.remove(getDocument2('L', input));
+ DocumentManager.remove(getDocument2('R', input));
+
+ if (DEBUG)
+ DocumentManager.dump();
+
if (fPreferenceChangeListener != null) {
if (fPreferenceStore != null)
fPreferenceStore.removePropertyChangeListener(fPreferenceChangeListener);
@@ -567,7 +658,7 @@ public class TextMergeViewer extends ContentMergeViewer {
unsetDocument(fAncestor);
unsetDocument(fLeft);
unsetDocument(fRight);
-
+
if (fColors != null) {
Iterator i= fColors.values().iterator();
while (i.hasNext()) {
@@ -775,7 +866,93 @@ public class TextMergeViewer extends ContentMergeViewer {
actionBars.updateActionBars();
}
}
+
+ ITypedElement getLeg(char type, Object input) {
+ if (input instanceof ICompareInput) {
+ switch (type) {
+ case 'A':
+ return ((ICompareInput)input).getAncestor();
+ case 'L':
+ return ((ICompareInput)input).getLeft();
+ case 'R':
+ return ((ICompareInput)input).getRight();
+ }
+ }
+ return null;
+ }
+ IDocument getDocument(char type, Object input) {
+ ITypedElement te= getLeg(type, input);
+ if (te instanceof IDocument)
+ return (IDocument) te;
+ if (te instanceof IDocumentRange)
+ return ((IDocumentRange) te).getDocument();
+ if (te instanceof IStreamContentAccessor)
+ return DocumentManager.get(te);
+ return null;
+ }
+
+ IDocument getDocument2(char type, Object input) {
+ IDocument doc= getDocument(type, input);
+ if (doc != null)
+ return doc;
+
+ if (input instanceof IDiffElement) {
+ IDiffContainer parent= ((IDiffElement)input).getParent();
+ return getDocument(type, parent);
+ }
+ return null;
+ }
+
+ 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;
+ }
+
+ /**
+ * Overridden to prevent save confirmation if new input is sub document of current input.
+ */
+ protected boolean doSave(Object newInput, Object oldInput) {
+
+ if (oldInput != null && newInput != null) {
+ // check whether underlying documents have changed.
+ if (sameDoc('A', newInput, oldInput) &&
+ sameDoc('L', newInput, oldInput) &&
+ sameDoc('R', newInput, oldInput)) {
+ if (DEBUG) System.out.println("----- Same docs !!!!");
+ return false;
+ }
+ }
+
+ if (DEBUG) System.out.println("***** New docs !!!!");
+
+ IDocument aDoc= getDocument2('A', oldInput);
+ DocumentManager.remove(aDoc);
+ IDocument lDoc= getDocument2('L', oldInput);
+ DocumentManager.remove(lDoc);
+ IDocument rDoc= getDocument2('R', oldInput);
+ DocumentManager.remove(rDoc);
+
+ if (DEBUG)
+ DocumentManager.dump();
+
+ return super.doSave(newInput, oldInput);
+ }
+
+ private ITypedElement getParent(char type) {
+ Object input= getInput();
+ if (input instanceof IDiffElement) {
+ IDiffContainer parent= ((IDiffElement)input).getParent();
+ return getLeg(type, parent);
+ }
+ return null;
+ }
+
/**
* Initializes the text viewers of the three content areas with the given input objects.
* Subclasses may extend.
@@ -784,6 +961,13 @@ public class TextMergeViewer extends ContentMergeViewer {
boolean emptyInput= (ancestor == null && left == null && right == null);
+ int n= 0;
+ if (left != null)
+ n++;
+ if (right != null)
+ n++;
+ fHiglightRanges= n > 1;
+
// clear stuff
fCurrentDiff= null;
fChangeDiffs= null;
@@ -800,16 +984,19 @@ public class TextMergeViewer extends ContentMergeViewer {
fRight.setEditable(rightEditable);
fLeft.setEditable(leftEditable);
-
+
// set new documents
- setDocument(fLeft, left);
+ fLeftInput= left;
+ setDocument(fLeft, 'L', left);
fLeftLineCount= fLeft.getLineCount();
- setDocument(fRight, right);
+ fRightInput= right;
+ setDocument(fRight, 'R', right);
fRightLineCount= fRight.getLineCount();
- setDocument(fAncestor, ancestor);
-
+ fAncestorInput= ancestor;
+ setDocument(fAncestor, 'A', ancestor);
+
doDiff();
invalidateLines();
@@ -830,6 +1017,9 @@ public class TextMergeViewer extends ContentMergeViewer {
private void updateDiffBackground(Diff diff) {
+ if (! fHiglightRanges)
+ return;
+
if (diff == null || diff.fIsToken)
return;
@@ -846,18 +1036,6 @@ public class TextMergeViewer extends ContentMergeViewer {
fRight.setLineBackground(diff.fRightPos, c);
}
- private void unsetDocument(MergeSourceViewer tp) {
- IDocument oldDoc= tp.getDocument();
- if (oldDoc != null) { // deinstall old positions
- if (fPositionUpdater != null)
- oldDoc.removePositionUpdater(fPositionUpdater);
- try {
- oldDoc.removePositionCategory(MY_UPDATER);
- } catch (BadPositionCategoryException ex) {
- }
- }
- }
-
boolean isCurrentDiff(Diff diff) {
if (diff == null)
return false;
@@ -888,71 +1066,160 @@ public class TextMergeViewer extends ContentMergeViewer {
updateLines(doc);
}
+ private static ITypedElement getLeg(ICompareInput input, char type) {
+ switch (type) {
+ case 'A':
+ return input.getAncestor();
+ case 'L':
+ return input.getLeft();
+ case 'R':
+ return input.getRight();
+ }
+ return null;
+ }
+
+ private int findInsertionPosition(char type) {
+ Object in= getInput();
+ if (in instanceof ICompareInput) {
+
+ ITypedElement other= null;
+ ICompareInput input= (ICompareInput) in;
+ char otherType= 0;
+
+ switch (type) {
+ case 'A':
+ other= input.getLeft();
+ otherType= 'L';
+ if (other == null) {
+ other= input.getRight();
+ otherType= 'R';
+ }
+ break;
+ case 'L':
+ other= input.getRight();
+ otherType= 'R';
+ if (other == null) {
+ other= input.getAncestor();
+ otherType= 'A';
+ }
+ break;
+ case 'R':
+ other= input.getLeft();
+ otherType= 'L';
+ if (other == null) {
+ other= input.getAncestor();
+ otherType= 'A';
+ }
+ break;
+ }
+
+ if (other instanceof IDocumentRange) {
+ IDocumentRange dr= (IDocumentRange) other;
+ Position p= dr.getRange();
+ Diff diff= findDiff(otherType, p.offset);
+ if (diff != null) {
+ switch (type) {
+ case 'A':
+ return diff.fAncestorPos.offset;
+ case 'L':
+ return diff.fLeftPos.offset;
+ case 'R':
+ return diff.fRightPos.offset;
+ }
+ }
+ }
+ }
+ return 0;
+ }
+
/**
* Returns true if a new Document could be installed.
*/
- private boolean setDocument(MergeSourceViewer tp, Object o) {
+ private boolean setDocument(MergeSourceViewer tp, char type, Object o) {
if (tp == null)
return false;
IDocument newDoc= null;
+ Position range= null;
if (o instanceof IDocumentRange) {
newDoc= ((IDocumentRange)o).getDocument();
+ range= ((IDocumentRange)o).getRange();
- } else if (o instanceof Document) {
- newDoc= (Document) o;
+ } else if (o instanceof IDocument) {
+ newDoc= (IDocument) o;
} else if (o instanceof IStreamContentAccessor) {
- IStreamContentAccessor sca= (IStreamContentAccessor) o;
- if (sca != null) {
+
+ newDoc= DocumentManager.get(o);
+ if (newDoc == null) {
+ IStreamContentAccessor sca= (IStreamContentAccessor) o;
String s= null;
-
+
try {
s= Utilities.readString(sca.getContents());
} catch (CoreException ex) {
}
-
+
newDoc= new Document(s != null ? s : ""); //$NON-NLS-1$
+ DocumentManager.put(o, newDoc);
IDocumentPartitioner partitioner= getDocumentPartitioner();
if (partitioner != null) {
newDoc.setDocumentPartitioner(partitioner);
partitioner.connect(newDoc);
}
}
+ } else if (o == null) {
+ ITypedElement parent= getParent(type);
+ if (parent instanceof IDocumentRange) {
+ newDoc= ((IDocumentRange)parent).getDocument();
+ newDoc.addPositionCategory(IDocumentRange.RANGE_CATEGORY);
+ Object input= getInput();
+ range= getNewRange(type, input);
+ if (range == null) {
+ range= new Position(findInsertionPosition(type), 0);
+ try {
+ newDoc.addPosition(IDocumentRange.RANGE_CATEGORY, range);
+ } catch (BadPositionCategoryException ex) {
+ System.out.println("BadPositionCategoryException: " + ex);
+ } catch (BadLocationException ex) {
+ System.out.println("BadLocationException: " + ex);
+ }
+ addNewRange(type, input, range);
+ }
+ } else if (parent instanceof IDocument) {
+ newDoc= ((IDocumentRange)o).getDocument();
+ }
}
boolean enabled= true;
if (newDoc == null) {
+ //System.out.println("setDocument: create new Document");
newDoc= new Document(""); //$NON-NLS-1$
enabled= false;
}
IDocument oldDoc= tp.getDocument();
- unsetDocument(tp);
-
- if (newDoc != null) {
- newDoc.addPositionCategory(MY_UPDATER);
- if (fPositionUpdater == null)
- fPositionUpdater= new DefaultPositionUpdater(MY_UPDATER);
- newDoc.addPositionUpdater(fPositionUpdater);
- }
-
- if (newDoc != oldDoc) { // new document
+ if (newDoc != oldDoc) {
+
+ // got a new document
- // deinstall old document
- if (oldDoc != null)
- oldDoc.removeDocumentListener(fDocumentListener);
+ unsetDocument(tp);
+ if (newDoc != null) {
+ newDoc.addPositionCategory(IDocumentRange.RANGE_CATEGORY);
+ if (fPositionUpdater == null)
+ fPositionUpdater= new ChildPositionUpdater(IDocumentRange.RANGE_CATEGORY);
+ else
+ newDoc.removePositionUpdater(fPositionUpdater);
+ newDoc.addPositionUpdater(fPositionUpdater);
+ }
+
// install new document
if (newDoc != null) {
- Position range= null;
- if (o instanceof IDocumentRange)
- range= ((IDocumentRange) o).getRange();
-
tp.setRegion(range);
if (fSubDoc) {
if (range != null) {
@@ -966,19 +1233,17 @@ public class TextMergeViewer extends ContentMergeViewer {
newDoc.addDocumentListener(fDocumentListener);
}
- } else { // just different range
+ } else { // same document but different range
- Position range= null;
- if (o instanceof IDocumentRange)
- range= ((IDocumentRange) o).getRange();
-
tp.setRegion(range);
if (fSubDoc) {
if (range != null) {
- IRegion r= normalizeDocumentRegion(tp.getDocument(), toRegion(range));
+ IRegion r= normalizeDocumentRegion(newDoc, toRegion(range));
tp.setVisibleRegion(r.getOffset(), r.getLength());
- }
- }
+ } else
+ tp.resetVisibleRegion();
+ } else
+ tp.resetVisibleRegion();
}
tp.setEnabled(enabled);
@@ -986,6 +1251,47 @@ public class TextMergeViewer extends ContentMergeViewer {
return enabled;
}
+ private Position getNewRange(char type, Object input) {
+ switch (type) {
+ case 'A':
+ return (Position) fNewAncestorRanges.get(input);
+ case 'L':
+ return (Position) fNewLeftRanges.get(input);
+ case 'R':
+ return (Position) fNewRightRanges.get(input);
+ }
+ return null;
+ }
+
+ private void addNewRange(char type, Object input, Position range) {
+ switch (type) {
+ case 'A':
+ fNewAncestorRanges.put(input, range);
+ break;
+ case 'L':
+ fNewLeftRanges.put(input, range);
+ break;
+ case 'R':
+ fNewRightRanges.put(input, range);
+ break;
+ }
+ }
+
+ private void unsetDocument(MergeSourceViewer tp) {
+ IDocument oldDoc= tp.getDocument();
+ if (oldDoc != null) {
+ // deinstall old positions
+ if (fPositionUpdater != null)
+ oldDoc.removePositionUpdater(fPositionUpdater);
+ try {
+ oldDoc.removePositionCategory(IDocumentRange.RANGE_CATEGORY);
+ } catch (BadPositionCategoryException ex) {
+ }
+
+ oldDoc.removeDocumentListener(fDocumentListener);
+ }
+ }
+
/**
* Returns the contents of the underlying document as an array of bytes.
*
@@ -1193,9 +1499,9 @@ public class TextMergeViewer extends ContentMergeViewer {
if (as > 0 || ys > 0 || ms > 0) {
Diff diff= new Diff(null, RangeDifference.NOCHANGE,
- aDoc, 0, astart,
- lDoc, 0, lRegion.getOffset(),
- rDoc, 0, rRegion.getOffset());
+ aDoc, aRegion, 0, astart,
+ lDoc, lRegion, 0, lRegion.getOffset(),
+ rDoc, rRegion, 0, rRegion.getOffset());
fAllDiffs.add(diff);
}
}
@@ -1238,9 +1544,9 @@ public class TextMergeViewer extends ContentMergeViewer {
if (e == null) {
// we create a NOCHANGE range for the whole document
Diff diff= new Diff(null, RangeDifference.NOCHANGE,
- aDoc, 0, aDoc != null ? aDoc.getLength() : 0,
- lDoc, 0, lDoc.getLength(),
- rDoc, 0, rDoc.getLength());
+ aDoc, aRegion, 0, aDoc != null ? aDoc.getLength() : 0,
+ lDoc, lRegion, 0, lDoc.getLength(),
+ rDoc, rRegion, 0, rDoc.getLength());
fAllDiffs.add(diff);
} else {
@@ -1264,9 +1570,9 @@ public class TextMergeViewer extends ContentMergeViewer {
int rightEnd= getTokenEnd2(sright, es.rightStart(), es.rightLength());
Diff diff= new Diff(null, kind,
- aDoc, ancestorStart, ancestorEnd,
- lDoc, leftStart, leftEnd,
- rDoc, rightStart, rightEnd);
+ aDoc, aRegion, ancestorStart, ancestorEnd,
+ lDoc, lRegion, leftStart, leftEnd,
+ rDoc, rRegion, rightStart, rightEnd);
fAllDiffs.add(diff); // remember all range diffs for scrolling
@@ -1311,13 +1617,105 @@ public class TextMergeViewer extends ContentMergeViewer {
aLen= aDoc.getLength();
}
Diff diff= new Diff(null, RangeDifference.NOCHANGE,
- aDoc, aEnd, aLen,
- lDoc, lRegion.getOffset()+lRegion.getLength(), lDoc.getLength(),
- rDoc, rRegion.getOffset()+rRegion.getLength(), rDoc.getLength());
+ aDoc, aRegion, aEnd, aLen,
+ lDoc, lRegion, lRegion.getOffset()+lRegion.getLength(), lDoc.getLength(),
+ rDoc, rRegion, rRegion.getOffset()+rRegion.getLength(), rDoc.getLength());
fAllDiffs.add(diff);
}
}
+ private Diff findDiff(char type, int pos) {
+
+ IDocument aDoc= null;
+ IDocument lDoc= fLeft.getDocument();
+ IDocument rDoc= fRight.getDocument();
+ if (lDoc == null || rDoc == null)
+ return null;
+
+ Position aRegion= null;
+ Position lRegion= null;
+ Position rRegion= null;
+
+ boolean threeWay= isThreeWay();
+
+ if (threeWay && !fIgnoreAncestor)
+ aDoc= fAncestor.getDocument();
+
+ boolean ignoreWhiteSpace= Utilities.getBoolean(getCompareConfiguration(), CompareConfiguration.IGNORE_WHITESPACE, false);
+
+ DocLineComparator sright= new DocLineComparator(rDoc, toRegion(rRegion), ignoreWhiteSpace);
+ DocLineComparator sleft= new DocLineComparator(lDoc, toRegion(lRegion), ignoreWhiteSpace);
+ DocLineComparator sancestor= null;
+ if (aDoc != null)
+ sancestor= new DocLineComparator(aDoc, toRegion(aRegion), ignoreWhiteSpace);
+
+ final ResourceBundle bundle= getResourceBundle();
+
+ final Object[] result= new Object[1];
+ final DocLineComparator sa= sancestor, sl= sleft, sr= sright;
+ IRunnableWithProgress runnable= new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException {
+ String progressTitle= Utilities.getString(bundle, "compareProgressTask.title"); //$NON-NLS-1$
+ monitor.beginTask(progressTitle, maxWork(sa, sl, sr));
+ try {
+ result[0]= RangeDifferencer.findRanges(monitor, sa, sl, sr);
+ } catch (OutOfMemoryError ex) {
+ System.gc();
+ throw new InvocationTargetException(ex);
+ }
+ if (monitor.isCanceled()) { // cancelled
+ throw new InterruptedException();
+ }
+ monitor.done();
+ }
+ };
+
+ RangeDifference[] e= null;
+ try {
+ TimeoutContext.run(true, TIMEOUT, getControl().getShell(), runnable);
+ e= (RangeDifference[]) result[0];
+ } catch (InvocationTargetException ex) {
+ String title= Utilities.getString(bundle, "tooComplexError.title"); //$NON-NLS-1$
+ String format= Utilities.getString(bundle, "tooComplexError.format"); //$NON-NLS-1$
+ String msg= MessageFormat.format(format, new Object[] { Integer.toString(TIMEOUT/1000) } );
+ MessageDialog.openError(fComposite.getShell(), title, msg);
+ e= null;
+ } catch (InterruptedException ex) {
+ //
+ }
+
+ if (e != null) {
+ for (int i= 0; i < e.length; i++) {
+ RangeDifference es= e[i];
+
+ int kind= es.kind();
+
+ int ancestorStart= 0;
+ int ancestorEnd= 0;
+ if (sancestor != null) {
+ ancestorStart= sancestor.getTokenStart(es.ancestorStart());
+ ancestorEnd= getTokenEnd2(sancestor, es.ancestorStart(), es.ancestorLength());
+ }
+
+ int leftStart= sleft.getTokenStart(es.leftStart());
+ int leftEnd= getTokenEnd2(sleft, es.leftStart(), es.leftLength());
+
+ int rightStart= sright.getTokenStart(es.rightStart());
+ int rightEnd= getTokenEnd2(sright, es.rightStart(), es.rightLength());
+
+ Diff diff= new Diff(null, kind,
+ aDoc, aRegion, ancestorStart, ancestorEnd,
+ lDoc, lRegion, leftStart, leftEnd,
+ rDoc, rRegion, rightStart, rightEnd);
+
+ if (diff.isInRange(type, pos))
+ return diff;
+ }
+ }
+
+ return null;
+ }
+
/**
* Returns true if kind of change should be shown.
*/
@@ -1421,9 +1819,9 @@ public class TextMergeViewer extends ContentMergeViewer {
int rightEnd2= rightStart + getTokenEnd(sm, es.rightStart(), es.rightLength());
Diff diff= new Diff(baseDiff, kind,
- ancestorDoc, ancestorStart2, ancestorEnd2,
- leftDoc, leftStart2, leftEnd2,
- rightDoc, rightStart2, rightEnd2);
+ ancestorDoc, null, ancestorStart2, ancestorEnd2,
+ leftDoc, null, leftStart2, leftEnd2,
+ rightDoc, null, rightStart2, rightEnd2);
diff.fIsToken= true;
// add to base Diff
baseDiff.add(diff);
@@ -1512,9 +1910,9 @@ public class TextMergeViewer extends ContentMergeViewer {
int rightStart2= rightStart+sm.getTokenStart(first.rightStart());
int rightEnd2= rightStart+getTokenEnd(sm, last.rightStart(), last.rightLength());
Diff diff= new Diff(baseDiff, first.kind(),
- ancestorDoc, ancestorStart2, ancestorEnd2+1,
- leftDoc, leftStart2, leftEnd2+1,
- rightDoc, rightStart2, rightEnd2+1);
+ ancestorDoc, null, ancestorStart2, ancestorEnd2+1,
+ leftDoc, null, leftStart2, leftEnd2+1,
+ rightDoc, null, rightStart2, rightEnd2+1);
diff.fIsToken= true;
baseDiff.add(diff);
}
@@ -1539,7 +1937,7 @@ public class TextMergeViewer extends ContentMergeViewer {
}
if (fDirectionLabel != null) {
- if (fCurrentDiff != null && isThreeWay() && !fIgnoreAncestor) {
+ if (fHiglightRanges && fCurrentDiff != null && isThreeWay() && !fIgnoreAncestor) {
fDirectionLabel.setImage(fCurrentDiff.getImage());
} else {
fDirectionLabel.setImage(null);
@@ -1973,6 +2371,9 @@ public class TextMergeViewer extends ContentMergeViewer {
g.fillRectangle(w-1, 0, 1, size.y);
}
+ if (! fHiglightRanges)
+ return;
+
if (fChangeDiffs != null) {
int lshift= fLeft.getVerticalScrollOffset();
int rshift= fRight.getVerticalScrollOffset();
@@ -2016,7 +2417,7 @@ public class TextMergeViewer extends ContentMergeViewer {
}
private void paintSides(GC g, MergeSourceViewer tp, Canvas canvas, boolean right) {
-
+
int lineHeight= tp.getTextWidget().getLineHeight();
int visibleHeight= tp.getViewportHeight();
@@ -2036,6 +2437,9 @@ public class TextMergeViewer extends ContentMergeViewer {
g.fillRectangle(size.x-1, 0, 1, size.y);
}
+ if (! fHiglightRanges)
+ return;
+
if (fChangeDiffs != null) {
int shift= tp.getVerticalScrollOffset() + (2-LW);
@@ -2080,6 +2484,8 @@ public class TextMergeViewer extends ContentMergeViewer {
private void paint(PaintEvent event, MergeSourceViewer tp) {
+ if (! fHiglightRanges)
+ return;
if (fChangeDiffs == null)
return;
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/DocumentManager.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/DocumentManager.java
new file mode 100644
index 000000000..76491b987
--- /dev/null
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/DocumentManager.java
@@ -0,0 +1,59 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package org.eclipse.compare.internal;
+
+import java.util.*;
+
+import org.eclipse.jface.text.IDocument;
+
+/**
+ * No API yet.
+ */
+public class DocumentManager {
+
+ private static final boolean DEBUG= false;
+
+ private static ArrayList fgKeys= new ArrayList();
+ private static ArrayList fgValues= new ArrayList();
+
+ public static IDocument get(Object o) {
+
+ for (int i= 0; i < fgKeys.size(); i++) {
+ if (fgKeys.get(i) == o)
+ return (IDocument) fgValues.get(i);
+ }
+ return null;
+ }
+
+ public static void put(Object o, IDocument document) {
+ if (DEBUG) System.out.println("DocumentManager.put: " + document); //$NON-NLS-1$
+ for (int i= 0; i < fgKeys.size(); i++) {
+ if (fgKeys.get(i) == o) {
+ fgValues.set(i, document);
+ return;
+ }
+ }
+ fgKeys.add(o);
+ fgValues.add(document);
+ }
+
+ public static void remove(IDocument document) {
+ if (document != null) {
+ if (DEBUG) System.out.println("DocumentManager.remove: " + document); //$NON-NLS-1$
+ for (int i= 0; i < fgValues.size(); i++) {
+ if (fgValues.get(i) == document) {
+ fgKeys.remove(i);
+ fgValues.remove(i);
+ return;
+ }
+ }
+ if (DEBUG) System.out.println("DocumentManager.remove: not found"); //$NON-NLS-1$
+ }
+ }
+
+ public static void dump() {
+ if (DEBUG) System.out.println("DocumentManager: managed docs:" + fgValues.size()); //$NON-NLS-1$
+ }
+}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ISavable.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ISavable.java
new file mode 100644
index 000000000..d4b4cc2f8
--- /dev/null
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ISavable.java
@@ -0,0 +1,13 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package org.eclipse.compare.internal;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.CoreException;
+
+public interface ISavable {
+
+ void save(IProgressMonitor pm) throws CoreException;
+}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ViewerDescriptor.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ViewerDescriptor.java
index e2fe7d010..d6a64cd6b 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ViewerDescriptor.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ViewerDescriptor.java
@@ -12,6 +12,8 @@ import org.eclipse.compare.*;
import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.ui.internal.ViewerActionBuilder;
+
/**
* Creates <code>Viewer</code>s from an <code>IConfigurationElement</code>.
*/
@@ -22,16 +24,19 @@ public class ViewerDescriptor implements IViewerDescriptor {
private IConfigurationElement fConfiguration;
private IViewerCreator fViewerCreator;
+ private Class fViewerClass;
public ViewerDescriptor(IConfigurationElement config) {
fConfiguration= config;
}
public Viewer createViewer(Viewer currentViewer, Composite parent, CompareConfiguration mp) {
- String className= fConfiguration.getAttribute(CLASS_ATTRIBUTE);
- if (currentViewer != null && currentViewer.getClass().getName().equals(className)) {
+
+ if (currentViewer != null && currentViewer.getClass() == fViewerClass) {
+ //System.out.println("reused viewer: " + currentViewer.getClass().getName());
return currentViewer;
}
+
if (fViewerCreator == null) {
try {
fViewerCreator= (IViewerCreator) fConfiguration.createExecutableExtension(CLASS_ATTRIBUTE);
@@ -41,8 +46,8 @@ public class ViewerDescriptor implements IViewerDescriptor {
if (fViewerCreator != null) {
Viewer viewer= fViewerCreator.createViewer(parent, mp);
- //if (viewer != null && currentViewer != null && viewer.getClass() == currentViewer.getClass())
- // return currentViewer;
+ if (viewer != null)
+ fViewerClass= viewer.getClass();
return viewer;
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PreviewPatchPage.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PreviewPatchPage.java
index 8c2ca8212..0b18ba2c1 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PreviewPatchPage.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PreviewPatchPage.java
@@ -169,7 +169,7 @@ import org.eclipse.compare.structuremergeviewer.*;
fTree.setLayoutData(gd);
// bottom pane showing hunks in compare viewer
- fHunkViewer= new CompareViewerSwitchingPane(splitter, SWT.BORDER) {
+ fHunkViewer= new CompareViewerSwitchingPane(splitter, SWT.BORDER | SWT.FLAT) {
protected Viewer getViewer(Viewer oldViewer, Object input) {
return CompareUI.findContentViewer(oldViewer, (ICompareInput)input, this, fCompareConfiguration);
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewer.java
index d5930d835..90a451564 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewer.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewer.java
@@ -145,6 +145,7 @@ public class DiffTreeViewer extends TreeViewer {
private Action fNextAction;
private Action fPreviousAction;
private Action fEmptyMenuAction;
+ private Action fExpandAllAction;
/**
* Creates a new viewer for the given SWT tree control with the specified configuration.
@@ -411,13 +412,23 @@ public class DiffTreeViewer extends TreeViewer {
/**
* This method is called to add actions to the viewer's context menu.
- * It installs actions for copying one side of a <code>DiffNode</code> to the other side.
+ * It installs actions for expanding tree nodes, copying one side of a <code>DiffNode</code> to the other side.
* Clients can override this method and are free to decide whether they want to call
* the inherited method.
*
* @param manager the menu manager for which to add the actions
*/
protected void fillContextMenu(IMenuManager manager) {
+ if (fExpandAllAction == null) {
+ fExpandAllAction= new Action() {
+ public void run() {
+ expandSelection();
+ }
+ };
+ Utilities.initAction(fExpandAllAction, fBundle, "action.ExpandAll."); //$NON-NLS-1$
+ }
+ manager.add(fExpandAllAction);
+
if (fCopyLeftToRightAction != null)
manager.add(fCopyLeftToRightAction);
if (fCopyRightToLeftAction != null)
@@ -425,6 +436,20 @@ public class DiffTreeViewer extends TreeViewer {
}
/**
+ * Expands to infinity all items in the selection.
+ */
+ protected void expandSelection() {
+ ISelection selection= getSelection();
+ if (selection instanceof IStructuredSelection) {
+ Iterator elements= ((IStructuredSelection)selection).iterator();
+ while (elements.hasNext()) {
+ Object next= elements.next();
+ expandToLevel(next, ALL_LEVELS);
+ }
+ }
+ }
+
+ /**
* Copies one side of all <code>DiffNode</code>s in the current selection to the other side.
* Called from the (internal) actions for copying the sides of a <code>DiffNode</code>.
* Clients may override.
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewerResources.properties b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewerResources.properties
index 9a91be426..9fc63b64b 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewerResources.properties
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewerResources.properties
@@ -21,9 +21,12 @@ emptyMenuItem= <Empty Menu>
#####################################################
action.Smart.label=Smart
-action.Smart.tooltip=Try to Guess Corresponding Elements
+action.Smart.tooltip=Try to Guess Similar Elements
action.Smart.image=smartmode_co.gif
+action.ExpandAll.label=Expand All
+action.ExpandAll.tooltip=Expand All Nodes
+
action.NextDiff.label=Next
action.NextDiff.tooltip=Select Next Change
action.NextDiff.image=next_nav.gif
@@ -37,5 +40,5 @@ action.TakeLeft.tooltip=Copy Selected Nodes from Left to Right
action.TakeLeft.image=copycont_r_co.gif
action.TakeRight.label=Copy Right to Left
-action.TakeRight.tooltip=Copy selected Nodes from Right to Left
+action.TakeRight.tooltip=Copy Selected Nodes from Right to Left
action.TakeRight.image=copycont_l_co.gif
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DocumentRangeNode.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DocumentRangeNode.java
index b68de6d02..57073008b 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DocumentRangeNode.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DocumentRangeNode.java
@@ -14,7 +14,9 @@ import org.eclipse.jface.text.*;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.compare.*;
import org.eclipse.compare.internal.Utilities;
+import org.eclipse.compare.contentmergeviewer.*;
import org.eclipse.compare.contentmergeviewer.IDocumentRange;
+import org.eclipse.compare.contentmergeviewer.TextMergeViewer;
/**
@@ -39,7 +41,7 @@ public class DocumentRangeNode
implements IDocumentRange, IStructureComparator, IEditableContent, IStreamContentAccessor {
private static final boolean POS_UPDATE= true;
-
+
private IDocument fBaseDocument;
private Position fRange; // the range in the base document
private int fTypeCode;
@@ -65,11 +67,13 @@ public class DocumentRangeNode
fID= id;
fBaseDocument= document;
+ fBaseDocument.addPositionCategory(RANGE_CATEGORY);
fRange= new Position(start, length);
if (POS_UPDATE) {
try {
- document.addPosition(fRange);
+ document.addPosition(RANGE_CATEGORY, fRange);
+ } catch (BadPositionCategoryException ex) {
} catch (BadLocationException ex) {
}
}
@@ -163,8 +167,9 @@ public class DocumentRangeNode
fBaseDocument.removePosition(fAppendPosition);
try {
Position p= new Position(pos);
- fBaseDocument.addPosition(p);
+ fBaseDocument.addPosition(RANGE_CATEGORY, p);
fAppendPosition= p;
+ } catch (BadPositionCategoryException ex) {
} catch (BadLocationException ex) {
// ignore
}
@@ -185,8 +190,9 @@ public class DocumentRangeNode
if (POS_UPDATE) {
try {
Position p= new Position(fBaseDocument.getLength());
- fBaseDocument.addPosition(p);
+ fBaseDocument.addPosition(RANGE_CATEGORY, p);
fAppendPosition= p;
+ } catch (BadPositionCategoryException ex) {
} catch (BadLocationException ex) {
// ignore
}
@@ -236,7 +242,7 @@ public class DocumentRangeNode
//try {
Position po= new Position(p.getOffset() + p.getLength() + 1, 0);
- //c.fBaseDocument.addPosition(po);
+ //c.fBaseDocument.addPosition(RANGE_CATEGORY, po);
return po;
//} catch (BadLocationException ex) {
//}
@@ -253,7 +259,7 @@ public class DocumentRangeNode
Position p= c.fRange;
//try {
Position po= new Position(p.getOffset(), 0);
- //c.fBaseDocument.addPosition(po);
+ //c.fBaseDocument.addPosition(RANGE_CATEGORY, po);
return po;
//} catch (BadLocationException ex) {
//}
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/.classpath b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/.classpath
index ce863b74a..d8b8ad011 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/.classpath
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/.classpath
@@ -5,7 +5,7 @@
<classpathentry kind="src" path="/org.eclipse.core.runtime"/>
<classpathentry kind="src" path="/org.eclipse.ui"/>
<classpathentry kind="src" path="/org.eclipse.core.resources"/>
- <classpathentry exported="true" kind="lib" path="compare.jar" sourcepath="/org.eclipse.compare/comparesrc.zip"/>
+ <classpathentry exported="true" kind="lib" path="compare.jar"/>
<classpathentry kind="var" path="JRE_LIB" rootpath="JRE_SRCROOT" sourcepath="JRE_SRC"/>
<classpathentry kind="src" path="/org.eclipse.swt"/>
<classpathentry kind="output" path="bin"/>
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/buildnotes_compare.html b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/buildnotes_compare.html
index 0c0ce4004..ba0c3d36f 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/buildnotes_compare.html
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/buildnotes_compare.html
@@ -11,6 +11,36 @@
<h1>
Eclipse Platform Build Notes<br>
Compare</h1>
+Eclipse Build Input March 12th 2002
+
+<h2>
+What's new in this drop</h2>
+Structure Compare viewers are enabled by default.<br>
+
+<h3>
+API changes</h3>
+
+<h3>
+API Additions</h3>
+
+<h3>
+Other highlights</h3>
+
+<h2>
+Known deficiencies</h2>
+
+<h2>
+Problem reports fixed</h2>
+<a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=10379">#10379</a>: Compare with Local History Dialog: lower pane is missing a bordeer<br>
+<a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=9768">#9768</a>: (empty-menu) in compare view<br>
+<a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=9842">#9842</a>: Expand All action needed in structure compare view<br>
+
+
+<h2>
+Problem reports closed</h2>
+
+<h1>
+<hr WIDTH="100%"></h1>
Eclipse Build Input March 5th 2002
<h2>
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java
index 1f25f0901..d6ac8c45d 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java
@@ -89,12 +89,6 @@ import org.eclipse.compare.structuremergeviewer.*;
public abstract class CompareEditorInput implements IEditorInput, IPropertyChangeNotifier, IRunnableWithProgress {
/**
- * Work in progres !!
- * SHOW_STRUCTURE is not public API.
- */
- public static final boolean SHOW_STRUCTURE= false;
-
- /**
* The name of the "dirty" property.
*/
public static final String DIRTY_STATE= "DIRTY_STATE"; //$NON-NLS-1$
@@ -121,7 +115,7 @@ public abstract class CompareEditorInput implements IEditorInput, IPropertyChang
private IgnoreWhiteSpaceAction fIgnoreWhitespace;
private ShowPseudoConflicts fShowPseudoConflicts;
- boolean fStructureCompareOnSingleClick= false;
+ boolean fStructureCompareOnSingleClick= true;
/**
* Creates a <code>CompareEditorInput</code> which is initialized with the given
@@ -621,14 +615,8 @@ public abstract class CompareEditorInput implements IEditorInput, IPropertyChang
public Viewer findContentViewer(Viewer oldViewer, ICompareInput input, Composite parent) {
Viewer v= CompareUIPlugin.findContentViewer(oldViewer, input, parent, fCompareConfiguration);
- if (SHOW_STRUCTURE) {
- if (oldViewer != null && v != null && oldViewer.getClass() == v.getClass())
- v= oldViewer;
- }
-
if (v instanceof IPropertyChangeNotifier) {
final IPropertyChangeNotifier dsp= (IPropertyChangeNotifier) v;
-
dsp.addPropertyChangeListener(fDirtyStateListener);
Control c= v.getControl();
@@ -709,28 +697,19 @@ public abstract class CompareEditorInput implements IEditorInput, IPropertyChang
public void saveChanges(IProgressMonitor pm) throws CoreException {
// flush changes in any dirty viewer
- flushViewer(fStructureInputPane);
- flushViewer(fStructurePane1);
- flushViewer(fStructurePane2);
- flushViewer(fContentInputPane);
+ flushViewer(fStructureInputPane, pm);
+ flushViewer(fStructurePane1, pm);
+ flushViewer(fStructurePane2, pm);
+ flushViewer(fContentInputPane, pm);
save(pm);
}
- private static void flushViewer(CompareViewerSwitchingPane pane) {
+ private static void flushViewer(CompareViewerSwitchingPane pane, IProgressMonitor pm) throws CoreException {
if (pane != null) {
Viewer v= pane.getViewer();
- if (v != null) {
-
- // since we have already asked the user whether he wants to save
- // changes, we disable the confirmation alert in
- // ContentMergeViewer.inputChanged
- if (v instanceof ContentMergeViewer)
- ((ContentMergeViewer)v).setConfirmSave(false);
-
- Object input= pane.getInput();
- v.setInput(input);
- }
+ if (v instanceof ISavable)
+ ((ISavable)v).save(pm);
}
}
}
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java
index b5ab58a43..2530338e9 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java
@@ -88,11 +88,8 @@ public abstract class CompareViewerSwitchingPane extends CompareViewerPane
*/
private void setViewer(Viewer newViewer) {
- if (newViewer == fViewer) {
- if (CompareEditorInput.SHOW_STRUCTURE)
- System.out.println("Same viewer: " + fViewer.getClass().getName());
+ if (newViewer == fViewer)
return;
- }
boolean oldEmpty= isEmpty();
@@ -210,14 +207,12 @@ public abstract class CompareViewerSwitchingPane extends CompareViewerPane
boolean hadFocus= hasFocus2();
- if (! CompareEditorInput.SHOW_STRUCTURE) {
- try {
- if (fViewer != null)
- fViewer.setInput(null); // force save before switching viewer
- } catch (ViewerSwitchingCancelled ex) {
- return;
- }
- }
+// try {
+// if (fViewer != null)
+// fViewer.setInput(null); // force save before switching viewer
+// } catch (ViewerSwitchingCancelled ex) {
+// return;
+// }
fInput= input;
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/ContentMergeViewer.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/ContentMergeViewer.java
index 2ba364cf1..7878ff22a 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/ContentMergeViewer.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/ContentMergeViewer.java
@@ -12,6 +12,9 @@ import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.custom.CLabel;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.CoreException;
+
import org.eclipse.jface.util.*;
import org.eclipse.jface.action.*;
import org.eclipse.jface.dialogs.*;
@@ -52,7 +55,8 @@ import org.eclipse.compare.internal.*;
* @see IMergeViewerContentProvider
* @see TextMergeViewer
*/
-public abstract class ContentMergeViewer extends ContentViewer implements IPropertyChangeNotifier {
+public abstract class ContentMergeViewer extends ContentViewer
+ implements IPropertyChangeNotifier, ISavable {
class SaveAction extends MergeViewerAction {
@@ -493,6 +497,23 @@ public abstract class ContentMergeViewer extends ContentViewer implements IPrope
if (oldInput instanceof ICompareInput)
((ICompareInput)oldInput).removeCompareInputChangeListener(fCompareInputChangeListener);
+ boolean success= doSave(input, oldInput);
+
+ if (input != oldInput)
+ if (input instanceof ICompareInput)
+ ((ICompareInput)input).addCompareInputChangeListener(fCompareInputChangeListener);
+
+ if (success) {
+ setLeftDirty(false);
+ setRightDirty(false);
+ }
+
+ if (input != oldInput)
+ internalRefresh(input);
+ }
+
+ protected boolean doSave(Object newInput, Object oldInput) {
+
// before setting the new input we have to save the old
if (fLeftSaveAction.isEnabled() || fRightSaveAction.isEnabled()) {
@@ -508,7 +529,7 @@ public abstract class ContentMergeViewer extends ContentViewer implements IPrope
new String[] {
IDialogConstants.YES_LABEL,
IDialogConstants.NO_LABEL,
- IDialogConstants.CANCEL_LABEL
+// IDialogConstants.CANCEL_LABEL
},
0); // default button index
@@ -525,19 +546,11 @@ public abstract class ContentMergeViewer extends ContentViewer implements IPrope
}
} else
saveContent(oldInput);
+ return true;
}
-
- if (input != oldInput)
- if (input instanceof ICompareInput)
- ((ICompareInput)input).addCompareInputChangeListener(fCompareInputChangeListener);
-
- setLeftDirty(false);
- setRightDirty(false);
-
- if (input != oldInput)
- internalRefresh(input);
+ return false;
}
-
+
public void setConfirmSave(boolean enable) {
fConfirmSave= enable;
}
@@ -890,6 +903,10 @@ public abstract class ContentMergeViewer extends ContentViewer implements IPrope
}
}
+ public void save(IProgressMonitor pm) throws CoreException {
+ saveContent(getInput());
+ }
+
/**
* Save modified content back to input elements via the content provider.
*/
@@ -898,8 +915,8 @@ public abstract class ContentMergeViewer extends ContentViewer implements IPrope
// write back modified contents
IMergeViewerContentProvider content= (IMergeViewerContentProvider) getContentProvider();
- boolean leftEmpty= content.getLeftContent(oldInput) != null;
- boolean rightEmpty= content.getRightContent(oldInput) != null;
+ boolean leftEmpty= content.getLeftContent(oldInput) == null;
+ boolean rightEmpty= content.getRightContent(oldInput) == null;
if (fCompareConfiguration.isLeftEditable() && fLeftSaveAction.isEnabled()) {
byte[] bytes= getContents(true);
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/IDocumentRange.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/IDocumentRange.java
index 1db51c482..a713fb44f 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/IDocumentRange.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/IDocumentRange.java
@@ -24,7 +24,7 @@ import org.eclipse.jface.text.IDocument;
*/
public interface IDocumentRange {
- public static final String RANGE_CATEGORY= "DocumentRangeCategory";
+ public static final String RANGE_CATEGORY= "DocumentRangeCategory"; //$NON-NLS-1$
/**
* Returns the underlying document.
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
index 50aaf9b71..b54d72dd1 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
@@ -62,8 +62,9 @@ import org.eclipse.compare.internal.MergeViewerAction;
import org.eclipse.compare.internal.INavigatable;
import org.eclipse.compare.internal.CompareNavigator;
import org.eclipse.compare.internal.TimeoutContext;
+import org.eclipse.compare.internal.DocumentManager;
import org.eclipse.compare.rangedifferencer.*;
-import org.eclipse.compare.structuremergeviewer.Differencer;
+import org.eclipse.compare.structuremergeviewer.*;
/**
* A text merge viewer uses the <code>RangeDifferencer</code> to perform a
@@ -113,6 +114,8 @@ import org.eclipse.compare.structuremergeviewer.Differencer;
*/
public class TextMergeViewer extends ContentMergeViewer {
+ private static final boolean DEBUG= true;
+
private static final String[] GLOBAL_ACTIONS= {
IWorkbenchActionConstants.UNDO,
IWorkbenchActionConstants.REDO,
@@ -133,9 +136,7 @@ public class TextMergeViewer extends ContentMergeViewer {
MergeSourceViewer.SELECT_ALL_ID,
MergeSourceViewer.SAVE_ID
};
-
- private static final String MY_UPDATER= "my_updater"; //$NON-NLS-1$
-
+
private static final String SYNC_SCROLLING= "SYNC_SCROLLING"; //$NON-NLS-1$
private static final String BUNDLE_NAME= "org.eclipse.compare.contentmergeviewer.TextMergeViewerResources"; //$NON-NLS-1$
@@ -207,6 +208,14 @@ public class TextMergeViewer extends ContentMergeViewer {
/** The current diff */
private Diff fCurrentDiff;
+ private HashMap fNewAncestorRanges= new HashMap();
+ private HashMap fNewLeftRanges= new HashMap();
+ private HashMap fNewRightRanges= new HashMap();
+
+ private Object fAncestorInput;
+ private Object fLeftInput;
+ private Object fRightInput;
+
private MergeSourceViewer fAncestor;
private MergeSourceViewer fLeft;
private MergeSourceViewer fRight;
@@ -223,6 +232,7 @@ public class TextMergeViewer extends ContentMergeViewer {
private boolean fIgnoreAncestor= false;
private ActionContributionItem fIgnoreAncestorItem;
+ private boolean fHiglightRanges;
private boolean fShowPseudoConflicts= false;
@@ -251,7 +261,57 @@ public class TextMergeViewer extends ContentMergeViewer {
private Map fColors;
private Font fFont;
-
+ /**
+ * The position updater used to adapt the positions representing
+ * the child document ranges to changes of the parent document.
+ */
+ class ChildPositionUpdater extends DefaultPositionUpdater {
+
+ /**
+ * Creates the position updated.
+ */
+ protected ChildPositionUpdater(String category) {
+ super(category);
+ }
+
+ /**
+ * Child document ranges cannot be deleted other then by calling
+ * freeChildDocument.
+ */
+ protected boolean notDeleted() {
+ return true;
+ }
+
+ /**
+ * If an insertion happens at a child document's start offset, the
+ * position is extended rather than shifted. Also, if something is added
+ * right behind the end of the position, the position is extended rather
+ * than kept stable.
+ */
+ protected void adaptToInsert() {
+
+ if (fPosition == fLeft.getRegion() || fPosition == fRight.getRegion()) {
+ int myStart= fPosition.offset;
+ int myEnd= fPosition.offset + fPosition.length;
+ myEnd= Math.max(myStart, myEnd);
+
+ int yoursStart= fOffset;
+ int yoursEnd= fOffset + fReplaceLength -1;
+ yoursEnd= Math.max(yoursStart, yoursEnd);
+
+ if (myEnd < yoursStart)
+ return;
+
+ if (myStart <= yoursStart)
+ fPosition.length += fReplaceLength;
+ else
+ fPosition.offset += fReplaceLength;
+ } else {
+ super.adaptToInsert();
+ }
+ }
+ }
+
/**
* A Diff represents synchronized character ranges in two or three Documents.
* The MergeTextViewer uses Diffs to find differences in line and token ranges.
@@ -275,16 +335,33 @@ public class TextMergeViewer extends ContentMergeViewer {
/**
* Create Diff from two ranges and an optional parent diff.
*/
- Diff(Diff parent, int dir, IDocument ancestorDoc, int ancestorStart, int ancestorEnd,
- IDocument leftDoc, int leftStart, int leftEnd,
- IDocument rightDoc, int rightStart, int rightEnd) {
+ Diff(Diff parent, int dir, IDocument ancestorDoc, Position aRange, int ancestorStart, int ancestorEnd,
+ IDocument leftDoc, Position lRange, int leftStart, int leftEnd,
+ IDocument rightDoc, Position rRange, int rightStart, int rightEnd) {
fParent= parent != null ? parent : this;
fDirection= dir;
- fLeftPos= createPosition(leftDoc, leftStart, leftEnd);
- fRightPos= createPosition(rightDoc, rightStart, rightEnd);
+ fLeftPos= createPosition(leftDoc, lRange, leftStart, leftEnd);
+ fRightPos= createPosition(rightDoc, rRange, rightStart, rightEnd);
if (ancestorDoc != null)
- fAncestorPos= createPosition(ancestorDoc, ancestorStart, ancestorEnd);
+ fAncestorPos= createPosition(ancestorDoc, aRange, ancestorStart, ancestorEnd);
+ }
+
+ Position getPosition(char type) {
+ switch (type) {
+ case 'A':
+ return fAncestorPos;
+ case 'L':
+ return fLeftPos;
+ case 'R':
+ return fRightPos;
+ }
+ return null;
+ }
+
+ boolean isInRange(char type, int pos) {
+ Position p= getPosition(type);
+ return (pos >= p.offset) && (pos < (p.offset+p.length));
}
String changeType() {
@@ -324,12 +401,18 @@ public class TextMergeViewer extends ContentMergeViewer {
return null;
}
- Position createPosition(IDocument doc, int start, int end) {
+ Position createPosition(IDocument doc, Position range, int start, int end) {
try {
- int dl= doc.getLength();
int l= end-start;
- if (start+l > dl)
- l= dl-start;
+ if (range != null) {
+ int dl= range.length;
+ if (l > dl)
+ l= dl;
+ } else {
+ int dl= doc.getLength();
+ if (start+l > dl)
+ l= dl-start;
+ }
Position p= null;
try {
@@ -339,7 +422,7 @@ public class TextMergeViewer extends ContentMergeViewer {
}
try {
- doc.addPosition(MY_UPDATER, p);
+ doc.addPosition(IDocumentRange.RANGE_CATEGORY, p);
} catch (BadPositionCategoryException ex) {
}
return p;
@@ -360,7 +443,7 @@ public class TextMergeViewer extends ContentMergeViewer {
return true;
return fLeftPos.isDeleted() || fRightPos.isDeleted();
}
-
+
void setResolved(boolean r) {
fResolved= r;
if (r)
@@ -554,6 +637,14 @@ public class TextMergeViewer extends ContentMergeViewer {
*/
protected void handleDispose(DisposeEvent event) {
+ Object input= getInput();
+ DocumentManager.remove(getDocument2('A', input));
+ DocumentManager.remove(getDocument2('L', input));
+ DocumentManager.remove(getDocument2('R', input));
+
+ if (DEBUG)
+ DocumentManager.dump();
+
if (fPreferenceChangeListener != null) {
if (fPreferenceStore != null)
fPreferenceStore.removePropertyChangeListener(fPreferenceChangeListener);
@@ -567,7 +658,7 @@ public class TextMergeViewer extends ContentMergeViewer {
unsetDocument(fAncestor);
unsetDocument(fLeft);
unsetDocument(fRight);
-
+
if (fColors != null) {
Iterator i= fColors.values().iterator();
while (i.hasNext()) {
@@ -775,7 +866,93 @@ public class TextMergeViewer extends ContentMergeViewer {
actionBars.updateActionBars();
}
}
+
+ ITypedElement getLeg(char type, Object input) {
+ if (input instanceof ICompareInput) {
+ switch (type) {
+ case 'A':
+ return ((ICompareInput)input).getAncestor();
+ case 'L':
+ return ((ICompareInput)input).getLeft();
+ case 'R':
+ return ((ICompareInput)input).getRight();
+ }
+ }
+ return null;
+ }
+ IDocument getDocument(char type, Object input) {
+ ITypedElement te= getLeg(type, input);
+ if (te instanceof IDocument)
+ return (IDocument) te;
+ if (te instanceof IDocumentRange)
+ return ((IDocumentRange) te).getDocument();
+ if (te instanceof IStreamContentAccessor)
+ return DocumentManager.get(te);
+ return null;
+ }
+
+ IDocument getDocument2(char type, Object input) {
+ IDocument doc= getDocument(type, input);
+ if (doc != null)
+ return doc;
+
+ if (input instanceof IDiffElement) {
+ IDiffContainer parent= ((IDiffElement)input).getParent();
+ return getDocument(type, parent);
+ }
+ return null;
+ }
+
+ 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;
+ }
+
+ /**
+ * Overridden to prevent save confirmation if new input is sub document of current input.
+ */
+ protected boolean doSave(Object newInput, Object oldInput) {
+
+ if (oldInput != null && newInput != null) {
+ // check whether underlying documents have changed.
+ if (sameDoc('A', newInput, oldInput) &&
+ sameDoc('L', newInput, oldInput) &&
+ sameDoc('R', newInput, oldInput)) {
+ if (DEBUG) System.out.println("----- Same docs !!!!");
+ return false;
+ }
+ }
+
+ if (DEBUG) System.out.println("***** New docs !!!!");
+
+ IDocument aDoc= getDocument2('A', oldInput);
+ DocumentManager.remove(aDoc);
+ IDocument lDoc= getDocument2('L', oldInput);
+ DocumentManager.remove(lDoc);
+ IDocument rDoc= getDocument2('R', oldInput);
+ DocumentManager.remove(rDoc);
+
+ if (DEBUG)
+ DocumentManager.dump();
+
+ return super.doSave(newInput, oldInput);
+ }
+
+ private ITypedElement getParent(char type) {
+ Object input= getInput();
+ if (input instanceof IDiffElement) {
+ IDiffContainer parent= ((IDiffElement)input).getParent();
+ return getLeg(type, parent);
+ }
+ return null;
+ }
+
/**
* Initializes the text viewers of the three content areas with the given input objects.
* Subclasses may extend.
@@ -784,6 +961,13 @@ public class TextMergeViewer extends ContentMergeViewer {
boolean emptyInput= (ancestor == null && left == null && right == null);
+ int n= 0;
+ if (left != null)
+ n++;
+ if (right != null)
+ n++;
+ fHiglightRanges= n > 1;
+
// clear stuff
fCurrentDiff= null;
fChangeDiffs= null;
@@ -800,16 +984,19 @@ public class TextMergeViewer extends ContentMergeViewer {
fRight.setEditable(rightEditable);
fLeft.setEditable(leftEditable);
-
+
// set new documents
- setDocument(fLeft, left);
+ fLeftInput= left;
+ setDocument(fLeft, 'L', left);
fLeftLineCount= fLeft.getLineCount();
- setDocument(fRight, right);
+ fRightInput= right;
+ setDocument(fRight, 'R', right);
fRightLineCount= fRight.getLineCount();
- setDocument(fAncestor, ancestor);
-
+ fAncestorInput= ancestor;
+ setDocument(fAncestor, 'A', ancestor);
+
doDiff();
invalidateLines();
@@ -830,6 +1017,9 @@ public class TextMergeViewer extends ContentMergeViewer {
private void updateDiffBackground(Diff diff) {
+ if (! fHiglightRanges)
+ return;
+
if (diff == null || diff.fIsToken)
return;
@@ -846,18 +1036,6 @@ public class TextMergeViewer extends ContentMergeViewer {
fRight.setLineBackground(diff.fRightPos, c);
}
- private void unsetDocument(MergeSourceViewer tp) {
- IDocument oldDoc= tp.getDocument();
- if (oldDoc != null) { // deinstall old positions
- if (fPositionUpdater != null)
- oldDoc.removePositionUpdater(fPositionUpdater);
- try {
- oldDoc.removePositionCategory(MY_UPDATER);
- } catch (BadPositionCategoryException ex) {
- }
- }
- }
-
boolean isCurrentDiff(Diff diff) {
if (diff == null)
return false;
@@ -888,71 +1066,160 @@ public class TextMergeViewer extends ContentMergeViewer {
updateLines(doc);
}
+ private static ITypedElement getLeg(ICompareInput input, char type) {
+ switch (type) {
+ case 'A':
+ return input.getAncestor();
+ case 'L':
+ return input.getLeft();
+ case 'R':
+ return input.getRight();
+ }
+ return null;
+ }
+
+ private int findInsertionPosition(char type) {
+ Object in= getInput();
+ if (in instanceof ICompareInput) {
+
+ ITypedElement other= null;
+ ICompareInput input= (ICompareInput) in;
+ char otherType= 0;
+
+ switch (type) {
+ case 'A':
+ other= input.getLeft();
+ otherType= 'L';
+ if (other == null) {
+ other= input.getRight();
+ otherType= 'R';
+ }
+ break;
+ case 'L':
+ other= input.getRight();
+ otherType= 'R';
+ if (other == null) {
+ other= input.getAncestor();
+ otherType= 'A';
+ }
+ break;
+ case 'R':
+ other= input.getLeft();
+ otherType= 'L';
+ if (other == null) {
+ other= input.getAncestor();
+ otherType= 'A';
+ }
+ break;
+ }
+
+ if (other instanceof IDocumentRange) {
+ IDocumentRange dr= (IDocumentRange) other;
+ Position p= dr.getRange();
+ Diff diff= findDiff(otherType, p.offset);
+ if (diff != null) {
+ switch (type) {
+ case 'A':
+ return diff.fAncestorPos.offset;
+ case 'L':
+ return diff.fLeftPos.offset;
+ case 'R':
+ return diff.fRightPos.offset;
+ }
+ }
+ }
+ }
+ return 0;
+ }
+
/**
* Returns true if a new Document could be installed.
*/
- private boolean setDocument(MergeSourceViewer tp, Object o) {
+ private boolean setDocument(MergeSourceViewer tp, char type, Object o) {
if (tp == null)
return false;
IDocument newDoc= null;
+ Position range= null;
if (o instanceof IDocumentRange) {
newDoc= ((IDocumentRange)o).getDocument();
+ range= ((IDocumentRange)o).getRange();
- } else if (o instanceof Document) {
- newDoc= (Document) o;
+ } else if (o instanceof IDocument) {
+ newDoc= (IDocument) o;
} else if (o instanceof IStreamContentAccessor) {
- IStreamContentAccessor sca= (IStreamContentAccessor) o;
- if (sca != null) {
+
+ newDoc= DocumentManager.get(o);
+ if (newDoc == null) {
+ IStreamContentAccessor sca= (IStreamContentAccessor) o;
String s= null;
-
+
try {
s= Utilities.readString(sca.getContents());
} catch (CoreException ex) {
}
-
+
newDoc= new Document(s != null ? s : ""); //$NON-NLS-1$
+ DocumentManager.put(o, newDoc);
IDocumentPartitioner partitioner= getDocumentPartitioner();
if (partitioner != null) {
newDoc.setDocumentPartitioner(partitioner);
partitioner.connect(newDoc);
}
}
+ } else if (o == null) {
+ ITypedElement parent= getParent(type);
+ if (parent instanceof IDocumentRange) {
+ newDoc= ((IDocumentRange)parent).getDocument();
+ newDoc.addPositionCategory(IDocumentRange.RANGE_CATEGORY);
+ Object input= getInput();
+ range= getNewRange(type, input);
+ if (range == null) {
+ range= new Position(findInsertionPosition(type), 0);
+ try {
+ newDoc.addPosition(IDocumentRange.RANGE_CATEGORY, range);
+ } catch (BadPositionCategoryException ex) {
+ System.out.println("BadPositionCategoryException: " + ex);
+ } catch (BadLocationException ex) {
+ System.out.println("BadLocationException: " + ex);
+ }
+ addNewRange(type, input, range);
+ }
+ } else if (parent instanceof IDocument) {
+ newDoc= ((IDocumentRange)o).getDocument();
+ }
}
boolean enabled= true;
if (newDoc == null) {
+ //System.out.println("setDocument: create new Document");
newDoc= new Document(""); //$NON-NLS-1$
enabled= false;
}
IDocument oldDoc= tp.getDocument();
- unsetDocument(tp);
-
- if (newDoc != null) {
- newDoc.addPositionCategory(MY_UPDATER);
- if (fPositionUpdater == null)
- fPositionUpdater= new DefaultPositionUpdater(MY_UPDATER);
- newDoc.addPositionUpdater(fPositionUpdater);
- }
-
- if (newDoc != oldDoc) { // new document
+ if (newDoc != oldDoc) {
+
+ // got a new document
- // deinstall old document
- if (oldDoc != null)
- oldDoc.removeDocumentListener(fDocumentListener);
+ unsetDocument(tp);
+ if (newDoc != null) {
+ newDoc.addPositionCategory(IDocumentRange.RANGE_CATEGORY);
+ if (fPositionUpdater == null)
+ fPositionUpdater= new ChildPositionUpdater(IDocumentRange.RANGE_CATEGORY);
+ else
+ newDoc.removePositionUpdater(fPositionUpdater);
+ newDoc.addPositionUpdater(fPositionUpdater);
+ }
+
// install new document
if (newDoc != null) {
- Position range= null;
- if (o instanceof IDocumentRange)
- range= ((IDocumentRange) o).getRange();
-
tp.setRegion(range);
if (fSubDoc) {
if (range != null) {
@@ -966,19 +1233,17 @@ public class TextMergeViewer extends ContentMergeViewer {
newDoc.addDocumentListener(fDocumentListener);
}
- } else { // just different range
+ } else { // same document but different range
- Position range= null;
- if (o instanceof IDocumentRange)
- range= ((IDocumentRange) o).getRange();
-
tp.setRegion(range);
if (fSubDoc) {
if (range != null) {
- IRegion r= normalizeDocumentRegion(tp.getDocument(), toRegion(range));
+ IRegion r= normalizeDocumentRegion(newDoc, toRegion(range));
tp.setVisibleRegion(r.getOffset(), r.getLength());
- }
- }
+ } else
+ tp.resetVisibleRegion();
+ } else
+ tp.resetVisibleRegion();
}
tp.setEnabled(enabled);
@@ -986,6 +1251,47 @@ public class TextMergeViewer extends ContentMergeViewer {
return enabled;
}
+ private Position getNewRange(char type, Object input) {
+ switch (type) {
+ case 'A':
+ return (Position) fNewAncestorRanges.get(input);
+ case 'L':
+ return (Position) fNewLeftRanges.get(input);
+ case 'R':
+ return (Position) fNewRightRanges.get(input);
+ }
+ return null;
+ }
+
+ private void addNewRange(char type, Object input, Position range) {
+ switch (type) {
+ case 'A':
+ fNewAncestorRanges.put(input, range);
+ break;
+ case 'L':
+ fNewLeftRanges.put(input, range);
+ break;
+ case 'R':
+ fNewRightRanges.put(input, range);
+ break;
+ }
+ }
+
+ private void unsetDocument(MergeSourceViewer tp) {
+ IDocument oldDoc= tp.getDocument();
+ if (oldDoc != null) {
+ // deinstall old positions
+ if (fPositionUpdater != null)
+ oldDoc.removePositionUpdater(fPositionUpdater);
+ try {
+ oldDoc.removePositionCategory(IDocumentRange.RANGE_CATEGORY);
+ } catch (BadPositionCategoryException ex) {
+ }
+
+ oldDoc.removeDocumentListener(fDocumentListener);
+ }
+ }
+
/**
* Returns the contents of the underlying document as an array of bytes.
*
@@ -1193,9 +1499,9 @@ public class TextMergeViewer extends ContentMergeViewer {
if (as > 0 || ys > 0 || ms > 0) {
Diff diff= new Diff(null, RangeDifference.NOCHANGE,
- aDoc, 0, astart,
- lDoc, 0, lRegion.getOffset(),
- rDoc, 0, rRegion.getOffset());
+ aDoc, aRegion, 0, astart,
+ lDoc, lRegion, 0, lRegion.getOffset(),
+ rDoc, rRegion, 0, rRegion.getOffset());
fAllDiffs.add(diff);
}
}
@@ -1238,9 +1544,9 @@ public class TextMergeViewer extends ContentMergeViewer {
if (e == null) {
// we create a NOCHANGE range for the whole document
Diff diff= new Diff(null, RangeDifference.NOCHANGE,
- aDoc, 0, aDoc != null ? aDoc.getLength() : 0,
- lDoc, 0, lDoc.getLength(),
- rDoc, 0, rDoc.getLength());
+ aDoc, aRegion, 0, aDoc != null ? aDoc.getLength() : 0,
+ lDoc, lRegion, 0, lDoc.getLength(),
+ rDoc, rRegion, 0, rDoc.getLength());
fAllDiffs.add(diff);
} else {
@@ -1264,9 +1570,9 @@ public class TextMergeViewer extends ContentMergeViewer {
int rightEnd= getTokenEnd2(sright, es.rightStart(), es.rightLength());
Diff diff= new Diff(null, kind,
- aDoc, ancestorStart, ancestorEnd,
- lDoc, leftStart, leftEnd,
- rDoc, rightStart, rightEnd);
+ aDoc, aRegion, ancestorStart, ancestorEnd,
+ lDoc, lRegion, leftStart, leftEnd,
+ rDoc, rRegion, rightStart, rightEnd);
fAllDiffs.add(diff); // remember all range diffs for scrolling
@@ -1311,13 +1617,105 @@ public class TextMergeViewer extends ContentMergeViewer {
aLen= aDoc.getLength();
}
Diff diff= new Diff(null, RangeDifference.NOCHANGE,
- aDoc, aEnd, aLen,
- lDoc, lRegion.getOffset()+lRegion.getLength(), lDoc.getLength(),
- rDoc, rRegion.getOffset()+rRegion.getLength(), rDoc.getLength());
+ aDoc, aRegion, aEnd, aLen,
+ lDoc, lRegion, lRegion.getOffset()+lRegion.getLength(), lDoc.getLength(),
+ rDoc, rRegion, rRegion.getOffset()+rRegion.getLength(), rDoc.getLength());
fAllDiffs.add(diff);
}
}
+ private Diff findDiff(char type, int pos) {
+
+ IDocument aDoc= null;
+ IDocument lDoc= fLeft.getDocument();
+ IDocument rDoc= fRight.getDocument();
+ if (lDoc == null || rDoc == null)
+ return null;
+
+ Position aRegion= null;
+ Position lRegion= null;
+ Position rRegion= null;
+
+ boolean threeWay= isThreeWay();
+
+ if (threeWay && !fIgnoreAncestor)
+ aDoc= fAncestor.getDocument();
+
+ boolean ignoreWhiteSpace= Utilities.getBoolean(getCompareConfiguration(), CompareConfiguration.IGNORE_WHITESPACE, false);
+
+ DocLineComparator sright= new DocLineComparator(rDoc, toRegion(rRegion), ignoreWhiteSpace);
+ DocLineComparator sleft= new DocLineComparator(lDoc, toRegion(lRegion), ignoreWhiteSpace);
+ DocLineComparator sancestor= null;
+ if (aDoc != null)
+ sancestor= new DocLineComparator(aDoc, toRegion(aRegion), ignoreWhiteSpace);
+
+ final ResourceBundle bundle= getResourceBundle();
+
+ final Object[] result= new Object[1];
+ final DocLineComparator sa= sancestor, sl= sleft, sr= sright;
+ IRunnableWithProgress runnable= new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException {
+ String progressTitle= Utilities.getString(bundle, "compareProgressTask.title"); //$NON-NLS-1$
+ monitor.beginTask(progressTitle, maxWork(sa, sl, sr));
+ try {
+ result[0]= RangeDifferencer.findRanges(monitor, sa, sl, sr);
+ } catch (OutOfMemoryError ex) {
+ System.gc();
+ throw new InvocationTargetException(ex);
+ }
+ if (monitor.isCanceled()) { // cancelled
+ throw new InterruptedException();
+ }
+ monitor.done();
+ }
+ };
+
+ RangeDifference[] e= null;
+ try {
+ TimeoutContext.run(true, TIMEOUT, getControl().getShell(), runnable);
+ e= (RangeDifference[]) result[0];
+ } catch (InvocationTargetException ex) {
+ String title= Utilities.getString(bundle, "tooComplexError.title"); //$NON-NLS-1$
+ String format= Utilities.getString(bundle, "tooComplexError.format"); //$NON-NLS-1$
+ String msg= MessageFormat.format(format, new Object[] { Integer.toString(TIMEOUT/1000) } );
+ MessageDialog.openError(fComposite.getShell(), title, msg);
+ e= null;
+ } catch (InterruptedException ex) {
+ //
+ }
+
+ if (e != null) {
+ for (int i= 0; i < e.length; i++) {
+ RangeDifference es= e[i];
+
+ int kind= es.kind();
+
+ int ancestorStart= 0;
+ int ancestorEnd= 0;
+ if (sancestor != null) {
+ ancestorStart= sancestor.getTokenStart(es.ancestorStart());
+ ancestorEnd= getTokenEnd2(sancestor, es.ancestorStart(), es.ancestorLength());
+ }
+
+ int leftStart= sleft.getTokenStart(es.leftStart());
+ int leftEnd= getTokenEnd2(sleft, es.leftStart(), es.leftLength());
+
+ int rightStart= sright.getTokenStart(es.rightStart());
+ int rightEnd= getTokenEnd2(sright, es.rightStart(), es.rightLength());
+
+ Diff diff= new Diff(null, kind,
+ aDoc, aRegion, ancestorStart, ancestorEnd,
+ lDoc, lRegion, leftStart, leftEnd,
+ rDoc, rRegion, rightStart, rightEnd);
+
+ if (diff.isInRange(type, pos))
+ return diff;
+ }
+ }
+
+ return null;
+ }
+
/**
* Returns true if kind of change should be shown.
*/
@@ -1421,9 +1819,9 @@ public class TextMergeViewer extends ContentMergeViewer {
int rightEnd2= rightStart + getTokenEnd(sm, es.rightStart(), es.rightLength());
Diff diff= new Diff(baseDiff, kind,
- ancestorDoc, ancestorStart2, ancestorEnd2,
- leftDoc, leftStart2, leftEnd2,
- rightDoc, rightStart2, rightEnd2);
+ ancestorDoc, null, ancestorStart2, ancestorEnd2,
+ leftDoc, null, leftStart2, leftEnd2,
+ rightDoc, null, rightStart2, rightEnd2);
diff.fIsToken= true;
// add to base Diff
baseDiff.add(diff);
@@ -1512,9 +1910,9 @@ public class TextMergeViewer extends ContentMergeViewer {
int rightStart2= rightStart+sm.getTokenStart(first.rightStart());
int rightEnd2= rightStart+getTokenEnd(sm, last.rightStart(), last.rightLength());
Diff diff= new Diff(baseDiff, first.kind(),
- ancestorDoc, ancestorStart2, ancestorEnd2+1,
- leftDoc, leftStart2, leftEnd2+1,
- rightDoc, rightStart2, rightEnd2+1);
+ ancestorDoc, null, ancestorStart2, ancestorEnd2+1,
+ leftDoc, null, leftStart2, leftEnd2+1,
+ rightDoc, null, rightStart2, rightEnd2+1);
diff.fIsToken= true;
baseDiff.add(diff);
}
@@ -1539,7 +1937,7 @@ public class TextMergeViewer extends ContentMergeViewer {
}
if (fDirectionLabel != null) {
- if (fCurrentDiff != null && isThreeWay() && !fIgnoreAncestor) {
+ if (fHiglightRanges && fCurrentDiff != null && isThreeWay() && !fIgnoreAncestor) {
fDirectionLabel.setImage(fCurrentDiff.getImage());
} else {
fDirectionLabel.setImage(null);
@@ -1973,6 +2371,9 @@ public class TextMergeViewer extends ContentMergeViewer {
g.fillRectangle(w-1, 0, 1, size.y);
}
+ if (! fHiglightRanges)
+ return;
+
if (fChangeDiffs != null) {
int lshift= fLeft.getVerticalScrollOffset();
int rshift= fRight.getVerticalScrollOffset();
@@ -2016,7 +2417,7 @@ public class TextMergeViewer extends ContentMergeViewer {
}
private void paintSides(GC g, MergeSourceViewer tp, Canvas canvas, boolean right) {
-
+
int lineHeight= tp.getTextWidget().getLineHeight();
int visibleHeight= tp.getViewportHeight();
@@ -2036,6 +2437,9 @@ public class TextMergeViewer extends ContentMergeViewer {
g.fillRectangle(size.x-1, 0, 1, size.y);
}
+ if (! fHiglightRanges)
+ return;
+
if (fChangeDiffs != null) {
int shift= tp.getVerticalScrollOffset() + (2-LW);
@@ -2080,6 +2484,8 @@ public class TextMergeViewer extends ContentMergeViewer {
private void paint(PaintEvent event, MergeSourceViewer tp) {
+ if (! fHiglightRanges)
+ return;
if (fChangeDiffs == null)
return;
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/DocumentManager.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/DocumentManager.java
new file mode 100644
index 000000000..76491b987
--- /dev/null
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/DocumentManager.java
@@ -0,0 +1,59 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package org.eclipse.compare.internal;
+
+import java.util.*;
+
+import org.eclipse.jface.text.IDocument;
+
+/**
+ * No API yet.
+ */
+public class DocumentManager {
+
+ private static final boolean DEBUG= false;
+
+ private static ArrayList fgKeys= new ArrayList();
+ private static ArrayList fgValues= new ArrayList();
+
+ public static IDocument get(Object o) {
+
+ for (int i= 0; i < fgKeys.size(); i++) {
+ if (fgKeys.get(i) == o)
+ return (IDocument) fgValues.get(i);
+ }
+ return null;
+ }
+
+ public static void put(Object o, IDocument document) {
+ if (DEBUG) System.out.println("DocumentManager.put: " + document); //$NON-NLS-1$
+ for (int i= 0; i < fgKeys.size(); i++) {
+ if (fgKeys.get(i) == o) {
+ fgValues.set(i, document);
+ return;
+ }
+ }
+ fgKeys.add(o);
+ fgValues.add(document);
+ }
+
+ public static void remove(IDocument document) {
+ if (document != null) {
+ if (DEBUG) System.out.println("DocumentManager.remove: " + document); //$NON-NLS-1$
+ for (int i= 0; i < fgValues.size(); i++) {
+ if (fgValues.get(i) == document) {
+ fgKeys.remove(i);
+ fgValues.remove(i);
+ return;
+ }
+ }
+ if (DEBUG) System.out.println("DocumentManager.remove: not found"); //$NON-NLS-1$
+ }
+ }
+
+ public static void dump() {
+ if (DEBUG) System.out.println("DocumentManager: managed docs:" + fgValues.size()); //$NON-NLS-1$
+ }
+}
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ISavable.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ISavable.java
new file mode 100644
index 000000000..d4b4cc2f8
--- /dev/null
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ISavable.java
@@ -0,0 +1,13 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package org.eclipse.compare.internal;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.CoreException;
+
+public interface ISavable {
+
+ void save(IProgressMonitor pm) throws CoreException;
+}
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ViewerDescriptor.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ViewerDescriptor.java
index e2fe7d010..d6a64cd6b 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ViewerDescriptor.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ViewerDescriptor.java
@@ -12,6 +12,8 @@ import org.eclipse.compare.*;
import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.ui.internal.ViewerActionBuilder;
+
/**
* Creates <code>Viewer</code>s from an <code>IConfigurationElement</code>.
*/
@@ -22,16 +24,19 @@ public class ViewerDescriptor implements IViewerDescriptor {
private IConfigurationElement fConfiguration;
private IViewerCreator fViewerCreator;
+ private Class fViewerClass;
public ViewerDescriptor(IConfigurationElement config) {
fConfiguration= config;
}
public Viewer createViewer(Viewer currentViewer, Composite parent, CompareConfiguration mp) {
- String className= fConfiguration.getAttribute(CLASS_ATTRIBUTE);
- if (currentViewer != null && currentViewer.getClass().getName().equals(className)) {
+
+ if (currentViewer != null && currentViewer.getClass() == fViewerClass) {
+ //System.out.println("reused viewer: " + currentViewer.getClass().getName());
return currentViewer;
}
+
if (fViewerCreator == null) {
try {
fViewerCreator= (IViewerCreator) fConfiguration.createExecutableExtension(CLASS_ATTRIBUTE);
@@ -41,8 +46,8 @@ public class ViewerDescriptor implements IViewerDescriptor {
if (fViewerCreator != null) {
Viewer viewer= fViewerCreator.createViewer(parent, mp);
- //if (viewer != null && currentViewer != null && viewer.getClass() == currentViewer.getClass())
- // return currentViewer;
+ if (viewer != null)
+ fViewerClass= viewer.getClass();
return viewer;
}
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PreviewPatchPage.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PreviewPatchPage.java
index 8c2ca8212..0b18ba2c1 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PreviewPatchPage.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PreviewPatchPage.java
@@ -169,7 +169,7 @@ import org.eclipse.compare.structuremergeviewer.*;
fTree.setLayoutData(gd);
// bottom pane showing hunks in compare viewer
- fHunkViewer= new CompareViewerSwitchingPane(splitter, SWT.BORDER) {
+ fHunkViewer= new CompareViewerSwitchingPane(splitter, SWT.BORDER | SWT.FLAT) {
protected Viewer getViewer(Viewer oldViewer, Object input) {
return CompareUI.findContentViewer(oldViewer, (ICompareInput)input, this, fCompareConfiguration);
}
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewer.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewer.java
index d5930d835..90a451564 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewer.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewer.java
@@ -145,6 +145,7 @@ public class DiffTreeViewer extends TreeViewer {
private Action fNextAction;
private Action fPreviousAction;
private Action fEmptyMenuAction;
+ private Action fExpandAllAction;
/**
* Creates a new viewer for the given SWT tree control with the specified configuration.
@@ -411,13 +412,23 @@ public class DiffTreeViewer extends TreeViewer {
/**
* This method is called to add actions to the viewer's context menu.
- * It installs actions for copying one side of a <code>DiffNode</code> to the other side.
+ * It installs actions for expanding tree nodes, copying one side of a <code>DiffNode</code> to the other side.
* Clients can override this method and are free to decide whether they want to call
* the inherited method.
*
* @param manager the menu manager for which to add the actions
*/
protected void fillContextMenu(IMenuManager manager) {
+ if (fExpandAllAction == null) {
+ fExpandAllAction= new Action() {
+ public void run() {
+ expandSelection();
+ }
+ };
+ Utilities.initAction(fExpandAllAction, fBundle, "action.ExpandAll."); //$NON-NLS-1$
+ }
+ manager.add(fExpandAllAction);
+
if (fCopyLeftToRightAction != null)
manager.add(fCopyLeftToRightAction);
if (fCopyRightToLeftAction != null)
@@ -425,6 +436,20 @@ public class DiffTreeViewer extends TreeViewer {
}
/**
+ * Expands to infinity all items in the selection.
+ */
+ protected void expandSelection() {
+ ISelection selection= getSelection();
+ if (selection instanceof IStructuredSelection) {
+ Iterator elements= ((IStructuredSelection)selection).iterator();
+ while (elements.hasNext()) {
+ Object next= elements.next();
+ expandToLevel(next, ALL_LEVELS);
+ }
+ }
+ }
+
+ /**
* Copies one side of all <code>DiffNode</code>s in the current selection to the other side.
* Called from the (internal) actions for copying the sides of a <code>DiffNode</code>.
* Clients may override.
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewerResources.properties b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewerResources.properties
index 9a91be426..9fc63b64b 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewerResources.properties
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewerResources.properties
@@ -21,9 +21,12 @@ emptyMenuItem= <Empty Menu>
#####################################################
action.Smart.label=Smart
-action.Smart.tooltip=Try to Guess Corresponding Elements
+action.Smart.tooltip=Try to Guess Similar Elements
action.Smart.image=smartmode_co.gif
+action.ExpandAll.label=Expand All
+action.ExpandAll.tooltip=Expand All Nodes
+
action.NextDiff.label=Next
action.NextDiff.tooltip=Select Next Change
action.NextDiff.image=next_nav.gif
@@ -37,5 +40,5 @@ action.TakeLeft.tooltip=Copy Selected Nodes from Left to Right
action.TakeLeft.image=copycont_r_co.gif
action.TakeRight.label=Copy Right to Left
-action.TakeRight.tooltip=Copy selected Nodes from Right to Left
+action.TakeRight.tooltip=Copy Selected Nodes from Right to Left
action.TakeRight.image=copycont_l_co.gif
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DocumentRangeNode.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DocumentRangeNode.java
index b68de6d02..57073008b 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DocumentRangeNode.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DocumentRangeNode.java
@@ -14,7 +14,9 @@ import org.eclipse.jface.text.*;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.compare.*;
import org.eclipse.compare.internal.Utilities;
+import org.eclipse.compare.contentmergeviewer.*;
import org.eclipse.compare.contentmergeviewer.IDocumentRange;
+import org.eclipse.compare.contentmergeviewer.TextMergeViewer;
/**
@@ -39,7 +41,7 @@ public class DocumentRangeNode
implements IDocumentRange, IStructureComparator, IEditableContent, IStreamContentAccessor {
private static final boolean POS_UPDATE= true;
-
+
private IDocument fBaseDocument;
private Position fRange; // the range in the base document
private int fTypeCode;
@@ -65,11 +67,13 @@ public class DocumentRangeNode
fID= id;
fBaseDocument= document;
+ fBaseDocument.addPositionCategory(RANGE_CATEGORY);
fRange= new Position(start, length);
if (POS_UPDATE) {
try {
- document.addPosition(fRange);
+ document.addPosition(RANGE_CATEGORY, fRange);
+ } catch (BadPositionCategoryException ex) {
} catch (BadLocationException ex) {
}
}
@@ -163,8 +167,9 @@ public class DocumentRangeNode
fBaseDocument.removePosition(fAppendPosition);
try {
Position p= new Position(pos);
- fBaseDocument.addPosition(p);
+ fBaseDocument.addPosition(RANGE_CATEGORY, p);
fAppendPosition= p;
+ } catch (BadPositionCategoryException ex) {
} catch (BadLocationException ex) {
// ignore
}
@@ -185,8 +190,9 @@ public class DocumentRangeNode
if (POS_UPDATE) {
try {
Position p= new Position(fBaseDocument.getLength());
- fBaseDocument.addPosition(p);
+ fBaseDocument.addPosition(RANGE_CATEGORY, p);
fAppendPosition= p;
+ } catch (BadPositionCategoryException ex) {
} catch (BadLocationException ex) {
// ignore
}
@@ -236,7 +242,7 @@ public class DocumentRangeNode
//try {
Position po= new Position(p.getOffset() + p.getLength() + 1, 0);
- //c.fBaseDocument.addPosition(po);
+ //c.fBaseDocument.addPosition(RANGE_CATEGORY, po);
return po;
//} catch (BadLocationException ex) {
//}
@@ -253,7 +259,7 @@ public class DocumentRangeNode
Position p= c.fRange;
//try {
Position po= new Position(p.getOffset(), 0);
- //c.fBaseDocument.addPosition(po);
+ //c.fBaseDocument.addPosition(RANGE_CATEGORY, po);
return po;
//} catch (BadLocationException ex) {
//}

Back to the top