Lines 71-79
Link Here
|
71 |
import org.eclipse.core.runtime.IProgressMonitor; |
71 |
import org.eclipse.core.runtime.IProgressMonitor; |
72 |
import org.eclipse.core.runtime.IStatus; |
72 |
import org.eclipse.core.runtime.IStatus; |
73 |
import org.eclipse.core.runtime.NullProgressMonitor; |
73 |
import org.eclipse.core.runtime.NullProgressMonitor; |
|
|
74 |
import org.eclipse.core.runtime.Status; |
74 |
import org.eclipse.jface.action.Action; |
75 |
import org.eclipse.jface.action.Action; |
75 |
import org.eclipse.jface.action.ActionContributionItem; |
76 |
import org.eclipse.jface.action.ActionContributionItem; |
76 |
import org.eclipse.jface.action.IAction; |
77 |
import org.eclipse.jface.action.IAction; |
|
|
78 |
import org.eclipse.jface.action.MenuManager; |
77 |
import org.eclipse.jface.action.Separator; |
79 |
import org.eclipse.jface.action.Separator; |
78 |
import org.eclipse.jface.action.ToolBarManager; |
80 |
import org.eclipse.jface.action.ToolBarManager; |
79 |
import org.eclipse.jface.dialogs.ErrorDialog; |
81 |
import org.eclipse.jface.dialogs.ErrorDialog; |
Lines 139-144
Link Here
|
139 |
import org.eclipse.swt.graphics.Cursor; |
141 |
import org.eclipse.swt.graphics.Cursor; |
140 |
import org.eclipse.swt.graphics.Font; |
142 |
import org.eclipse.swt.graphics.Font; |
141 |
import org.eclipse.swt.graphics.GC; |
143 |
import org.eclipse.swt.graphics.GC; |
|
|
144 |
import org.eclipse.swt.graphics.Image; |
142 |
import org.eclipse.swt.graphics.Point; |
145 |
import org.eclipse.swt.graphics.Point; |
143 |
import org.eclipse.swt.graphics.RGB; |
146 |
import org.eclipse.swt.graphics.RGB; |
144 |
import org.eclipse.swt.graphics.Rectangle; |
147 |
import org.eclipse.swt.graphics.Rectangle; |
Lines 152-165
Link Here
|
152 |
import org.eclipse.swt.widgets.ScrollBar; |
155 |
import org.eclipse.swt.widgets.ScrollBar; |
153 |
import org.eclipse.swt.widgets.Shell; |
156 |
import org.eclipse.swt.widgets.Shell; |
154 |
import org.eclipse.ui.IEditorInput; |
157 |
import org.eclipse.ui.IEditorInput; |
|
|
158 |
import org.eclipse.ui.IEditorSite; |
159 |
import org.eclipse.ui.IKeyBindingService; |
160 |
import org.eclipse.ui.IPropertyListener; |
161 |
import org.eclipse.ui.IWorkbenchPage; |
155 |
import org.eclipse.ui.IWorkbenchPart; |
162 |
import org.eclipse.ui.IWorkbenchPart; |
|
|
163 |
import org.eclipse.ui.IWorkbenchPartSite; |
164 |
import org.eclipse.ui.IWorkbenchWindow; |
165 |
import org.eclipse.ui.PartInitException; |
156 |
import org.eclipse.ui.PlatformUI; |
166 |
import org.eclipse.ui.PlatformUI; |
157 |
import org.eclipse.ui.actions.ActionFactory; |
167 |
import org.eclipse.ui.actions.ActionFactory; |
158 |
import org.eclipse.ui.contexts.IContextService; |
168 |
import org.eclipse.ui.contexts.IContextService; |
159 |
import org.eclipse.ui.editors.text.EditorsUI; |
169 |
import org.eclipse.ui.editors.text.EditorsUI; |
|
|
170 |
import org.eclipse.ui.editors.text.IEncodingSupport; |
171 |
import org.eclipse.ui.editors.text.IStorageDocumentProvider; |
172 |
import org.eclipse.ui.progress.UIJob; |
160 |
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; |
173 |
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; |
161 |
import org.eclipse.ui.texteditor.AbstractTextEditor; |
174 |
import org.eclipse.ui.texteditor.AbstractTextEditor; |
162 |
import org.eclipse.ui.texteditor.ChainedPreferenceStore; |
175 |
import org.eclipse.ui.texteditor.ChainedPreferenceStore; |
|
|
176 |
import org.eclipse.ui.texteditor.ChangeEncodingAction; |
163 |
import org.eclipse.ui.texteditor.FindReplaceAction; |
177 |
import org.eclipse.ui.texteditor.FindReplaceAction; |
164 |
import org.eclipse.ui.texteditor.GotoLineAction; |
178 |
import org.eclipse.ui.texteditor.GotoLineAction; |
165 |
import org.eclipse.ui.texteditor.IDocumentProvider; |
179 |
import org.eclipse.ui.texteditor.IDocumentProvider; |
Lines 497-503
Link Here
|
497 |
} |
511 |
} |
498 |
} |
512 |
} |
499 |
|
513 |
|
500 |
class ContributorInfo implements IElementStateListener, VerifyListener, IDocumentListener { |
514 |
class ContributorInfo implements IElementStateListener, VerifyListener, IDocumentListener, IEncodingSupport { |
501 |
private final TextMergeViewer fViewer; |
515 |
private final TextMergeViewer fViewer; |
502 |
private final Object fElement; |
516 |
private final Object fElement; |
503 |
private char fLeg; |
517 |
private char fLeg; |
Lines 521-531
Link Here
|
521 |
} |
535 |
} |
522 |
} |
536 |
} |
523 |
} |
537 |
} |
524 |
|
538 |
|
|
|
539 |
public void setEncoding(String encoding) { |
540 |
if (fDocumentKey == null || fDocumentProvider == null) { |
541 |
return; |
542 |
} |
543 |
if (fDocumentProvider instanceof IStorageDocumentProvider) { |
544 |
IStorageDocumentProvider provider = (IStorageDocumentProvider) fDocumentProvider; |
545 |
String current = provider.getEncoding(fDocumentKey); |
546 |
boolean dirty = fDocumentProvider.canSaveDocument(fDocumentKey); |
547 |
if (!dirty) { |
548 |
String internal = encoding == null ? "" : encoding; //$NON-NLS-1$ |
549 |
if (!internal.equals(current)) { |
550 |
provider.setEncoding(fDocumentKey, encoding); |
551 |
try { |
552 |
fDocumentProvider.resetDocument(fDocumentKey); |
553 |
} catch (CoreException e) { |
554 |
CompareUIPlugin.log(e); |
555 |
} finally { |
556 |
update(true); |
557 |
} |
558 |
} |
559 |
} |
560 |
} |
561 |
} |
562 |
|
525 |
public String getEncoding() { |
563 |
public String getEncoding() { |
526 |
if (fEncoding == null) |
564 |
if (fDocumentProvider != null && fDocumentKey != null |
527 |
return ResourcesPlugin.getEncoding(); |
565 |
&& fDocumentProvider instanceof IStorageDocumentProvider) { |
528 |
return fEncoding; |
566 |
IStorageDocumentProvider provider = (IStorageDocumentProvider) fDocumentProvider; |
|
|
567 |
return provider.getEncoding(fDocumentKey); |
568 |
} |
569 |
return null; |
570 |
} |
571 |
|
572 |
public String getDefaultEncoding() { |
573 |
if (fDocumentProvider != null && fDocumentKey != null |
574 |
&& fDocumentProvider instanceof IStorageDocumentProvider) { |
575 |
IStorageDocumentProvider provider = (IStorageDocumentProvider) fDocumentProvider; |
576 |
return provider.getDefaultEncoding(); |
577 |
} |
578 |
return null; |
579 |
} |
580 |
|
581 |
private String internalGetEncoding() { |
582 |
if (fEncoding != null) { |
583 |
return fEncoding; |
584 |
} |
585 |
return ResourcesPlugin.getEncoding(); |
529 |
} |
586 |
} |
530 |
|
587 |
|
531 |
public void setEncodingIfAbsent(ContributorInfo otherContributor) { |
588 |
public void setEncodingIfAbsent(ContributorInfo otherContributor) { |
Lines 716-722
Link Here
|
716 |
String s= null; |
773 |
String s= null; |
717 |
|
774 |
|
718 |
try { |
775 |
try { |
719 |
String encoding = getEncoding(); |
776 |
String encoding = internalGetEncoding(); |
720 |
s = Utilities.readString(sca, encoding); |
777 |
s = Utilities.readString(sca, encoding); |
721 |
} catch (CoreException ex) { |
778 |
} catch (CoreException ex) { |
722 |
this.fViewer.setError(fLeg, ex.getMessage()); |
779 |
this.fViewer.setError(fLeg, ex.getMessage()); |
Lines 979-984
Link Here
|
979 |
if (oldContributor != null) { |
1036 |
if (oldContributor != null) { |
980 |
fSelection = oldContributor.fSelection; |
1037 |
fSelection = oldContributor.fSelection; |
981 |
fTopIndex = oldContributor.fTopIndex; |
1038 |
fTopIndex = oldContributor.fTopIndex; |
|
|
1039 |
fEncoding = oldContributor.fEncoding; |
982 |
} |
1040 |
} |
983 |
|
1041 |
|
984 |
} |
1042 |
} |
Lines 2391-2396
Link Here
|
2391 |
|
2449 |
|
2392 |
contributeGotoLineAction(viewer); |
2450 |
contributeGotoLineAction(viewer); |
2393 |
|
2451 |
|
|
|
2452 |
contributeChangeEncodingAction(viewer); |
2453 |
|
2394 |
getSourceViewerDecorationSupport(viewer.getSourceViewer()).install(fPreferenceStore); |
2454 |
getSourceViewerDecorationSupport(viewer.getSourceViewer()).install(fPreferenceStore); |
2395 |
|
2455 |
|
2396 |
return viewer; |
2456 |
return viewer; |
Lines 2430-2435
Link Here
|
2430 |
viewer.addAction(MergeSourceViewer.GOTO_LINE_ID, action); |
2490 |
viewer.addAction(MergeSourceViewer.GOTO_LINE_ID, action); |
2431 |
} |
2491 |
} |
2432 |
|
2492 |
|
|
|
2493 |
private void contributeChangeEncodingAction(MergeSourceViewer viewer) { |
2494 |
ResourceBundle bundle = ResourceBundle.getBundle("org.eclipse.ui.texteditor.ConstructedTextEditorMessages"); //$NON-NLS-1$ |
2495 |
IAction action = new ChangeEncodingAction(bundle, "Editor.ChangeEncodingAction.", getTextEditorAdapter()); //$NON-NLS-1$ |
2496 |
viewer.addAction(MergeSourceViewer.CHANGE_ENCODING_ID, action); |
2497 |
} |
2498 |
|
2433 |
private void connectGlobalActions(final MergeSourceViewer part) { |
2499 |
private void connectGlobalActions(final MergeSourceViewer part) { |
2434 |
if (fHandlerService != null) { |
2500 |
if (fHandlerService != null) { |
2435 |
if (part != null) |
2501 |
if (part != null) |
Lines 2812-2821
Link Here
|
2812 |
} else if (doc == fRight.getSourceViewer().getDocument()) { |
2878 |
} else if (doc == fRight.getSourceViewer().getDocument()) { |
2813 |
setRightDirty(dirty); |
2879 |
setRightDirty(dirty); |
2814 |
} |
2880 |
} |
2815 |
|
|
|
2816 |
updateLines(doc); |
2817 |
} |
2818 |
|
2881 |
|
|
|
2882 |
if (needsDiffRecalculation(e)) { |
2883 |
new UIJob(CompareMessages.DocumentMerger_0) { |
2884 |
public IStatus runInUIThread(IProgressMonitor monitor) { |
2885 |
// do diff and update controls |
2886 |
update(true); |
2887 |
return Status.OK_STATUS; |
2888 |
} |
2889 |
}.schedule(); |
2890 |
} else { |
2891 |
updateLines(doc); |
2892 |
} |
2893 |
} |
2894 |
|
2895 |
private boolean needsDiffRecalculation(DocumentEvent e) { |
2896 |
IDocument doc = e.getDocument(); |
2897 |
// the doc has been replaced completely |
2898 |
return e.fOffset == 0 && doc.get().length() == e.fText.length(); |
2899 |
} |
2900 |
|
2819 |
/* |
2901 |
/* |
2820 |
* This method is called if a range of text on one side is copied into an empty sub-document |
2902 |
* This method is called if a range of text on one side is copied into an empty sub-document |
2821 |
* on the other side. The method returns the position where the sub-document is placed into the base document. |
2903 |
* on the other side. The method returns the position where the sub-document is placed into the base document. |
Lines 2938-2944
Link Here
|
2938 |
if (contents != null) { |
3020 |
if (contents != null) { |
2939 |
byte[] bytes; |
3021 |
byte[] bytes; |
2940 |
try { |
3022 |
try { |
2941 |
bytes= contents.getBytes(left ? fLeftContributor.getEncoding() : fRightContributor.getEncoding()); |
3023 |
bytes= contents.getBytes(left ? fLeftContributor.internalGetEncoding() : fRightContributor.internalGetEncoding()); |
2942 |
} catch(UnsupportedEncodingException ex) { |
3024 |
} catch(UnsupportedEncodingException ex) { |
2943 |
// use default encoding |
3025 |
// use default encoding |
2944 |
bytes= contents.getBytes(); |
3026 |
bytes= contents.getBytes(); |
Lines 4898-4901
Link Here
|
4898 |
return true; |
4980 |
return true; |
4899 |
return false; |
4981 |
return false; |
4900 |
} |
4982 |
} |
|
|
4983 |
|
4984 |
private ITextEditor getTextEditorAdapter() { |
4985 |
return new ITextEditor () { |
4986 |
public void close(boolean save) { |
4987 |
// Implementing interface method |
4988 |
} |
4989 |
public void doRevertToSaved() { |
4990 |
// Implementing interface method |
4991 |
} |
4992 |
public IAction getAction(String actionId) { |
4993 |
// Implementing interface method |
4994 |
return null; |
4995 |
} |
4996 |
public IDocumentProvider getDocumentProvider() { |
4997 |
// Implementing interface method |
4998 |
return null; |
4999 |
} |
5000 |
public IRegion getHighlightRange() { |
5001 |
// Implementing interface method |
5002 |
return null; |
5003 |
} |
5004 |
public ISelectionProvider getSelectionProvider() { |
5005 |
// Implementing interface method |
5006 |
return null; |
5007 |
} |
5008 |
public boolean isEditable() { |
5009 |
// Implementing interface method |
5010 |
return false; |
5011 |
} |
5012 |
public void removeActionActivationCode(String actionId) { |
5013 |
// Implementing interface method |
5014 |
} |
5015 |
public void resetHighlightRange() { |
5016 |
// Implementing interface method |
5017 |
} |
5018 |
public void selectAndReveal(int offset, int length) { |
5019 |
// Implementing interface method |
5020 |
} |
5021 |
public void setAction(String actionId, IAction action) { |
5022 |
// Implementing interface method |
5023 |
} |
5024 |
public void setActionActivationCode(String actionId, |
5025 |
char activationCharacter, int activationKeyCode, |
5026 |
int activationStateMask) { |
5027 |
// Implementing interface method |
5028 |
} |
5029 |
public void setHighlightRange(int offset, int length, |
5030 |
boolean moveCursor) { |
5031 |
// Implementing interface method |
5032 |
} |
5033 |
public void showHighlightRangeOnly(boolean showHighlightRangeOnly) { |
5034 |
// Implementing interface method |
5035 |
} |
5036 |
public boolean showsHighlightRangeOnly() { |
5037 |
// Implementing interface method |
5038 |
return false; |
5039 |
} |
5040 |
public IEditorInput getEditorInput() { |
5041 |
if (fFocusPart == fAncestor && fAncestorContributor != null) { |
5042 |
return fAncestorContributor.getDocumentKey(); |
5043 |
} else if (fFocusPart == fLeft && fLeftContributor != null) { |
5044 |
return fLeftContributor.getDocumentKey(); |
5045 |
} else if (fFocusPart == fRight && fRightContributor != null) { |
5046 |
return fRightContributor.getDocumentKey(); |
5047 |
} else { |
5048 |
return null; |
5049 |
} |
5050 |
} |
5051 |
public IEditorSite getEditorSite() { |
5052 |
// Implementing interface method |
5053 |
return null; |
5054 |
} |
5055 |
public void init(IEditorSite site, IEditorInput input) |
5056 |
throws PartInitException { |
5057 |
// Implementing interface method |
5058 |
} |
5059 |
public void addPropertyListener(IPropertyListener listener) { |
5060 |
// Implementing interface method |
5061 |
} |
5062 |
public void createPartControl(Composite parent) { |
5063 |
// Implementing interface method |
5064 |
} |
5065 |
public void dispose() { |
5066 |
// Implementing interface method |
5067 |
} |
5068 |
public IWorkbenchPartSite getSite() { |
5069 |
// Implementing interface method |
5070 |
return new IWorkbenchPartSite() { |
5071 |
public String getId() { |
5072 |
// Implementing interface method |
5073 |
return null; |
5074 |
} |
5075 |
public IKeyBindingService getKeyBindingService() { |
5076 |
// Implementing interface method |
5077 |
return null; |
5078 |
} |
5079 |
public IWorkbenchPart getPart() { |
5080 |
// Implementing interface method |
5081 |
return null; |
5082 |
} |
5083 |
public String getPluginId() { |
5084 |
// Implementing interface method |
5085 |
return null; |
5086 |
} |
5087 |
public String getRegisteredName() { |
5088 |
// Implementing interface method |
5089 |
return null; |
5090 |
} |
5091 |
public void registerContextMenu(MenuManager menuManager, |
5092 |
ISelectionProvider selectionProvider) { |
5093 |
// Implementing interface method |
5094 |
} |
5095 |
public void registerContextMenu(String menuId, |
5096 |
MenuManager menuManager, |
5097 |
ISelectionProvider selectionProvider) { |
5098 |
// Implementing interface method |
5099 |
} |
5100 |
public IWorkbenchPage getPage() { |
5101 |
// Implementing interface method |
5102 |
return null; |
5103 |
} |
5104 |
public ISelectionProvider getSelectionProvider() { |
5105 |
// Implementing interface method |
5106 |
return null; |
5107 |
} |
5108 |
public Shell getShell() { |
5109 |
return fComposite.getShell(); |
5110 |
} |
5111 |
public IWorkbenchWindow getWorkbenchWindow() { |
5112 |
// Implementing interface method |
5113 |
return null; |
5114 |
} |
5115 |
public void setSelectionProvider(ISelectionProvider provider) { |
5116 |
// Implementing interface method |
5117 |
} |
5118 |
public Object getAdapter(Class adapter) { |
5119 |
// Implementing interface method |
5120 |
return null; |
5121 |
} |
5122 |
public Object getService(Class api) { |
5123 |
// Implementing interface method |
5124 |
return null; |
5125 |
} |
5126 |
public boolean hasService(Class api) { |
5127 |
// Implementing interface method |
5128 |
return false; |
5129 |
} |
5130 |
}; |
5131 |
} |
5132 |
public String getTitle() { |
5133 |
// Implementing interface method |
5134 |
return null; |
5135 |
} |
5136 |
public Image getTitleImage() { |
5137 |
// Implementing interface method |
5138 |
return null; |
5139 |
} |
5140 |
public String getTitleToolTip() { |
5141 |
// Implementing interface method |
5142 |
return null; |
5143 |
} |
5144 |
public void removePropertyListener(IPropertyListener listener) { |
5145 |
// Implementing interface method |
5146 |
} |
5147 |
public void setFocus() { |
5148 |
// Implementing interface method |
5149 |
} |
5150 |
public Object getAdapter(Class adapter) { |
5151 |
if (adapter == IEncodingSupport.class) { |
5152 |
if (fFocusPart == fAncestor) { |
5153 |
return fAncestorContributor; |
5154 |
} else if (fFocusPart == fLeft) { |
5155 |
return fLeftContributor; |
5156 |
} else if (fFocusPart == fRight) { |
5157 |
return fRightContributor; |
5158 |
} else { |
5159 |
return null; |
5160 |
} |
5161 |
} |
5162 |
return null; |
5163 |
} |
5164 |
public void doSave(IProgressMonitor monitor) { |
5165 |
// Implementing interface method |
5166 |
} |
5167 |
public void doSaveAs() { |
5168 |
// Implementing interface method |
5169 |
} |
5170 |
public boolean isDirty() { |
5171 |
if (fFocusPart == fLeft) { |
5172 |
return isLeftDirty(); |
5173 |
} else if (fFocusPart == fRight) { |
5174 |
return isRightDirty(); |
5175 |
} |
5176 |
return false; |
5177 |
} |
5178 |
public boolean isSaveAsAllowed() { |
5179 |
// Implementing interface method |
5180 |
return false; |
5181 |
} |
5182 |
public boolean isSaveOnCloseNeeded() { |
5183 |
// Implementing interface method |
5184 |
return false; |
5185 |
} |
5186 |
}; |
5187 |
} |
4901 |
} |
5188 |
} |