Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndre Weinand2004-03-19 12:30:22 -0500
committerAndre Weinand2004-03-19 12:30:22 -0500
commitced510bbba43f53fe04f4e63d333ca4f15655282 (patch)
tree75f9f61c41eaad2c2fe1d21cd71fc1ab302c6636 /bundles/org.eclipse.compare/compare
parentc79882bc9be2b1b141cac6b9b8908c0b68eeb22f (diff)
downloadeclipse.platform.team-ced510bbba43f53fe04f4e63d333ca4f15655282.tar.gz
eclipse.platform.team-ced510bbba43f53fe04f4e63d333ca4f15655282.tar.xz
eclipse.platform.team-ced510bbba43f53fe04f4e63d333ca4f15655282.zip
adapted to non-uniform encoding supportv20040322
Diffstat (limited to 'bundles/org.eclipse.compare/compare')
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java53
1 files changed, 23 insertions, 30 deletions
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 4e405af99..ebff2b89e 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
@@ -221,6 +221,9 @@ public class TextMergeViewer extends ContentMergeViewer {
private int fLeftLineCount;
private int fRightLineCount;
+ private String fLeftEncoding;
+ private String fRightEncoding;
+
private boolean fInScrolling;
private int fPts[]= new int[8]; // scratch area for polygon drawing
@@ -1628,8 +1631,11 @@ public class TextMergeViewer extends ContentMergeViewer {
// set new documents
setDocument(fLeft, 'L', left);
fLeftLineCount= fLeft.getLineCount();
+ fLeftEncoding= getEncoding(left);
+
setDocument(fRight, 'R', right);
fRightLineCount= fRight.getLineCount();
+ fRightEncoding= getEncoding(right);
setDocument(fAncestor, 'A', ancestor);
@@ -1656,6 +1662,20 @@ public class TextMergeViewer extends ContentMergeViewer {
}
}
+ private static String getEncoding(Object o) {
+ String encoding= null;
+ if (o instanceof IEncodedStreamContentAccessor) {
+ try {
+ encoding= ((IEncodedStreamContentAccessor)o).getCharset();
+ } catch (CoreException e) {
+ // ignored
+ }
+ }
+ if (encoding == null)
+ encoding= ResourcesPlugin.getEncoding();
+ return encoding;
+ }
+
private void updateDiffBackground(Diff diff) {
if (! fHiglightRanges)
@@ -1810,7 +1830,7 @@ public class TextMergeViewer extends ContentMergeViewer {
IDocument newDoc= null;
Position range= null;
-
+
if (o instanceof IDocumentRange) {
newDoc= ((IDocumentRange)o).getDocument();
range= ((IDocumentRange)o).getRange();
@@ -1984,7 +2004,7 @@ public class TextMergeViewer extends ContentMergeViewer {
if (contents != null) {
byte[] bytes;
try {
- bytes= contents.getBytes(ResourcesPlugin.getEncoding());
+ bytes= contents.getBytes(left ? fLeftEncoding : fRightEncoding);
} catch(UnsupportedEncodingException ex) {
// use default encoding
bytes= contents.getBytes();
@@ -1995,34 +2015,7 @@ public class TextMergeViewer extends ContentMergeViewer {
}
return null;
}
-
-// /**
-// * Returns the contents of the underlying document as an array of bytes.
-// *
-// * @param left if <code>true</code> the contents of the left side is returned; otherwise the right side
-// * @return the contents of the left or right document or null
-// */
-// protected byte[] getContents(boolean left, String encoding) {
-// MergeSourceViewer v= left ? fLeft : fRight;
-// if (v != null) {
-// IDocument d= v.getDocument();
-// if (d != null) {
-// String contents= d.get();
-// if (contents != null) {
-// byte[] bytes;
-// try {
-// bytes= contents.getBytes(encoding);
-// } catch(UnsupportedEncodingException ex) {
-// // use default encoding
-// bytes= contents.getBytes();
-// }
-// return bytes;
-// }
-// }
-// }
-// return null;
-// }
-
+
private IRegion normalizeDocumentRegion(IDocument doc, IRegion region) {
if (region == null || doc == null)

Back to the top