Lines 37-42
Link Here
|
37 |
import org.eclipse.compare.ITypedElement; |
37 |
import org.eclipse.compare.ITypedElement; |
38 |
import org.eclipse.compare.SharedDocumentAdapter; |
38 |
import org.eclipse.compare.SharedDocumentAdapter; |
39 |
import org.eclipse.compare.internal.BufferedCanvas; |
39 |
import org.eclipse.compare.internal.BufferedCanvas; |
|
|
40 |
import org.eclipse.compare.internal.ChangeEncodingAction; |
40 |
import org.eclipse.compare.internal.ChangePropertyAction; |
41 |
import org.eclipse.compare.internal.ChangePropertyAction; |
41 |
import org.eclipse.compare.internal.CompareEditorSelectionProvider; |
42 |
import org.eclipse.compare.internal.CompareEditorSelectionProvider; |
42 |
import org.eclipse.compare.internal.CompareHandlerService; |
43 |
import org.eclipse.compare.internal.CompareHandlerService; |
Lines 157-162
Link Here
|
157 |
import org.eclipse.ui.actions.ActionFactory; |
158 |
import org.eclipse.ui.actions.ActionFactory; |
158 |
import org.eclipse.ui.contexts.IContextService; |
159 |
import org.eclipse.ui.contexts.IContextService; |
159 |
import org.eclipse.ui.editors.text.EditorsUI; |
160 |
import org.eclipse.ui.editors.text.EditorsUI; |
|
|
161 |
import org.eclipse.ui.editors.text.IEncodingSupport; |
162 |
import org.eclipse.ui.editors.text.IStorageDocumentProvider; |
160 |
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; |
163 |
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; |
161 |
import org.eclipse.ui.texteditor.AbstractTextEditor; |
164 |
import org.eclipse.ui.texteditor.AbstractTextEditor; |
162 |
import org.eclipse.ui.texteditor.ChainedPreferenceStore; |
165 |
import org.eclipse.ui.texteditor.ChainedPreferenceStore; |
Lines 497-503
Link Here
|
497 |
} |
500 |
} |
498 |
} |
501 |
} |
499 |
|
502 |
|
500 |
class ContributorInfo implements IElementStateListener, VerifyListener, IDocumentListener { |
503 |
class ContributorInfo implements IElementStateListener, VerifyListener, IDocumentListener, IEncodingSupport { |
501 |
private final TextMergeViewer fViewer; |
504 |
private final TextMergeViewer fViewer; |
502 |
private final Object fElement; |
505 |
private final Object fElement; |
503 |
private char fLeg; |
506 |
private char fLeg; |
Lines 521-531
Link Here
|
521 |
} |
524 |
} |
522 |
} |
525 |
} |
523 |
} |
526 |
} |
524 |
|
527 |
|
|
|
528 |
public void setEncoding(String encoding) { |
529 |
if (fDocumentKey == null || fDocumentProvider == null) { |
530 |
return; |
531 |
} |
532 |
if (fDocumentProvider instanceof IStorageDocumentProvider) { |
533 |
IStorageDocumentProvider provider = (IStorageDocumentProvider) fDocumentProvider; |
534 |
String current = provider.getEncoding(fDocumentKey); |
535 |
boolean dirty = fDocumentProvider.canSaveDocument(fDocumentKey); |
536 |
if (!dirty) { |
537 |
String internal = encoding == null ? "" : encoding; //$NON-NLS-1$ |
538 |
if (!internal.equals(current)) { |
539 |
provider.setEncoding(fDocumentKey, encoding); |
540 |
try { |
541 |
fDocumentProvider.resetDocument(fDocumentKey); |
542 |
} catch (CoreException e) { |
543 |
// TODO: |
544 |
e.printStackTrace(); |
545 |
} |
546 |
} |
547 |
} |
548 |
} |
549 |
} |
550 |
|
525 |
public String getEncoding() { |
551 |
public String getEncoding() { |
526 |
if (fEncoding == null) |
552 |
if (fDocumentProvider != null && fDocumentKey != null |
527 |
return ResourcesPlugin.getEncoding(); |
553 |
&& fDocumentProvider instanceof IStorageDocumentProvider) { |
528 |
return fEncoding; |
554 |
IStorageDocumentProvider provider = (IStorageDocumentProvider) fDocumentProvider; |
|
|
555 |
return provider.getEncoding(fDocumentKey); |
556 |
} |
557 |
return null; |
558 |
} |
559 |
|
560 |
public String getDefaultEncoding() { |
561 |
if (fDocumentProvider != null && fDocumentKey != null |
562 |
&& fDocumentProvider instanceof IStorageDocumentProvider) { |
563 |
IStorageDocumentProvider provider = (IStorageDocumentProvider) fDocumentProvider; |
564 |
return provider.getDefaultEncoding(); |
565 |
} |
566 |
return null; |
567 |
} |
568 |
|
569 |
public String getInternalEncoding() { |
570 |
if (fEncoding != null) { |
571 |
return fEncoding; |
572 |
} |
573 |
return ResourcesPlugin.getEncoding(); |
529 |
} |
574 |
} |
530 |
|
575 |
|
531 |
public void setEncodingIfAbsent(ContributorInfo otherContributor) { |
576 |
public void setEncodingIfAbsent(ContributorInfo otherContributor) { |
Lines 716-722
Link Here
|
716 |
String s= null; |
761 |
String s= null; |
717 |
|
762 |
|
718 |
try { |
763 |
try { |
719 |
String encoding = getEncoding(); |
764 |
String encoding = getInternalEncoding(); |
720 |
s = Utilities.readString(sca, encoding); |
765 |
s = Utilities.readString(sca, encoding); |
721 |
} catch (CoreException ex) { |
766 |
} catch (CoreException ex) { |
722 |
this.fViewer.setError(fLeg, ex.getMessage()); |
767 |
this.fViewer.setError(fLeg, ex.getMessage()); |
Lines 836-842
Link Here
|
836 |
* </ol> |
881 |
* </ol> |
837 |
* @return the document key used to obtain a shared document or <code>null</code> |
882 |
* @return the document key used to obtain a shared document or <code>null</code> |
838 |
*/ |
883 |
*/ |
839 |
private IEditorInput getDocumentKey() { |
884 |
public IEditorInput getDocumentKey() { |
840 |
if (fDocumentKey != null) |
885 |
if (fDocumentKey != null) |
841 |
return fDocumentKey; |
886 |
return fDocumentKey; |
842 |
if (isUsingDefaultContentProvider() && fElement != null && canHaveSharedDocument()) { |
887 |
if (isUsingDefaultContentProvider() && fElement != null && canHaveSharedDocument()) { |
Lines 979-984
Link Here
|
979 |
if (oldContributor != null) { |
1024 |
if (oldContributor != null) { |
980 |
fSelection = oldContributor.fSelection; |
1025 |
fSelection = oldContributor.fSelection; |
981 |
fTopIndex = oldContributor.fTopIndex; |
1026 |
fTopIndex = oldContributor.fTopIndex; |
|
|
1027 |
fEncoding = oldContributor.fEncoding; |
982 |
} |
1028 |
} |
983 |
|
1029 |
|
984 |
} |
1030 |
} |
Lines 1937-1942
Link Here
|
1937 |
service.activateContext("org.eclipse.ui.textEditorScope"); //$NON-NLS-1$ |
1983 |
service.activateContext("org.eclipse.ui.textEditorScope"); //$NON-NLS-1$ |
1938 |
} |
1984 |
} |
1939 |
} |
1985 |
} |
|
|
1986 |
|
1987 |
contributeChangeEncodingAction(fAncestor, MergeViewerContentProvider.ANCESTOR_CONTRIBUTOR); |
1988 |
contributeChangeEncodingAction(fLeft, MergeViewerContentProvider.LEFT_CONTRIBUTOR); |
1989 |
contributeChangeEncodingAction(fRight, MergeViewerContentProvider.RIGHT_CONTRIBUTOR); |
1940 |
} |
1990 |
} |
1941 |
|
1991 |
|
1942 |
private void hsynchViewport(final TextViewer tv1, final TextViewer tv2, final TextViewer tv3) { |
1992 |
private void hsynchViewport(final TextViewer tv1, final TextViewer tv2, final TextViewer tv3) { |
Lines 2430-2435
Link Here
|
2430 |
viewer.addAction(MergeSourceViewer.GOTO_LINE_ID, action); |
2480 |
viewer.addAction(MergeSourceViewer.GOTO_LINE_ID, action); |
2431 |
} |
2481 |
} |
2432 |
|
2482 |
|
|
|
2483 |
private void contributeChangeEncodingAction(MergeSourceViewer viewer, char type) { |
2484 |
IAction action = new ChangeEncodingAction(this, type, fComposite.getShell()); |
2485 |
viewer.addAction(MergeSourceViewer.CHANGE_ENCODING_ID, action); |
2486 |
} |
2487 |
|
2433 |
private void connectGlobalActions(final MergeSourceViewer part) { |
2488 |
private void connectGlobalActions(final MergeSourceViewer part) { |
2434 |
if (fHandlerService != null) { |
2489 |
if (fHandlerService != null) { |
2435 |
if (part != null) |
2490 |
if (part != null) |
Lines 2938-2944
Link Here
|
2938 |
if (contents != null) { |
2993 |
if (contents != null) { |
2939 |
byte[] bytes; |
2994 |
byte[] bytes; |
2940 |
try { |
2995 |
try { |
2941 |
bytes= contents.getBytes(left ? fLeftContributor.getEncoding() : fRightContributor.getEncoding()); |
2996 |
bytes= contents.getBytes(left ? fLeftContributor.getInternalEncoding() : fRightContributor.getInternalEncoding()); |
2942 |
} catch(UnsupportedEncodingException ex) { |
2997 |
} catch(UnsupportedEncodingException ex) { |
2943 |
// use default encoding |
2998 |
// use default encoding |
2944 |
bytes= contents.getBytes(); |
2999 |
bytes= contents.getBytes(); |
Lines 4898-4901
Link Here
|
4898 |
return true; |
4953 |
return true; |
4899 |
return false; |
4954 |
return false; |
4900 |
} |
4955 |
} |
|
|
4956 |
|
4957 |
/** |
4958 |
* Returns an encoding support for a specified side. |
4959 |
* |
4960 |
* @param type |
4961 |
* side for which editor input is returned. Allowed values are: |
4962 |
* <li>{@link MergeViewerContentProvider#ANCESTOR_CONTRIBUTOR}</li> |
4963 |
* <li>{@link MergeViewerContentProvider#LEFT_CONTRIBUTOR}</li> |
4964 |
* <li>{@link MergeViewerContentProvider#RIGHT_CONTRIBUTOR}</li> |
4965 |
* @return the encoding support |
4966 |
* |
4967 |
* @since 3.5 |
4968 |
*/ |
4969 |
public IEncodingSupport getEncodingSupport(char type) { |
4970 |
switch (type) { |
4971 |
case MergeViewerContentProvider.ANCESTOR_CONTRIBUTOR: |
4972 |
return fAncestorContributor; |
4973 |
case MergeViewerContentProvider.LEFT_CONTRIBUTOR: |
4974 |
return fLeftContributor; |
4975 |
case MergeViewerContentProvider.RIGHT_CONTRIBUTOR: |
4976 |
return fRightContributor; |
4977 |
default: |
4978 |
return null; |
4979 |
} |
4980 |
} |
4981 |
|
4982 |
/** |
4983 |
* Returns an editor input for a specified side. |
4984 |
* |
4985 |
* @param type |
4986 |
* side for which editor input is returned. Allowed values are: |
4987 |
* <li>{@link MergeViewerContentProvider#ANCESTOR_CONTRIBUTOR}</li> |
4988 |
* <li>{@link MergeViewerContentProvider#LEFT_CONTRIBUTOR}</li> |
4989 |
* <li>{@link MergeViewerContentProvider#RIGHT_CONTRIBUTOR}</li> |
4990 |
* @return the editor input |
4991 |
* |
4992 |
* @since 3.5 |
4993 |
*/ |
4994 |
public IEditorInput getEditorInput(char type) { |
4995 |
switch (type) { |
4996 |
case MergeViewerContentProvider.ANCESTOR_CONTRIBUTOR: |
4997 |
return fAncestorContributor.getDocumentKey(); |
4998 |
case MergeViewerContentProvider.LEFT_CONTRIBUTOR: |
4999 |
return fLeftContributor.getDocumentKey(); |
5000 |
case MergeViewerContentProvider.RIGHT_CONTRIBUTOR: |
5001 |
return fRightContributor.getDocumentKey(); |
5002 |
default: |
5003 |
return null; |
5004 |
} |
5005 |
} |
5006 |
|
5007 |
protected void setLeftDirty(boolean dirty) { |
5008 |
super.setLeftDirty(dirty); |
5009 |
IAction action = fLeft.getAction(MergeSourceViewer.CHANGE_ENCODING_ID); |
5010 |
if (action != null) { |
5011 |
action.setEnabled(!dirty); |
5012 |
} |
5013 |
} |
5014 |
|
5015 |
protected void setRightDirty(boolean dirty) { |
5016 |
super.setRightDirty(dirty); |
5017 |
IAction action = fRight.getAction(MergeSourceViewer.CHANGE_ENCODING_ID); |
5018 |
if (action != null) { |
5019 |
action.setEnabled(!dirty); |
5020 |
} |
5021 |
} |
5022 |
|
5023 |
/** |
5024 |
* Updates the viewers' content and recalculates diffs. |
5025 |
* |
5026 |
* @since 3.5 |
5027 |
*/ |
5028 |
public void update() { |
5029 |
update(true); |
5030 |
} |
5031 |
|
4901 |
} |
5032 |
} |