Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2008 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2009 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 55-60
Link Here
|
55 |
import org.eclipse.swt.widgets.*; |
55 |
import org.eclipse.swt.widgets.*; |
56 |
import org.eclipse.ui.*; |
56 |
import org.eclipse.ui.*; |
57 |
import org.eclipse.ui.actions.ActionFactory; |
57 |
import org.eclipse.ui.actions.ActionFactory; |
|
|
58 |
import org.eclipse.ui.editors.text.IEncodingSupport; |
59 |
import org.eclipse.ui.editors.text.IStorageDocumentProvider; |
60 |
import org.eclipse.ui.progress.UIJob; |
58 |
import org.eclipse.ui.texteditor.*; |
61 |
import org.eclipse.ui.texteditor.*; |
59 |
|
62 |
|
60 |
import com.ibm.icu.text.MessageFormat; |
63 |
import com.ibm.icu.text.MessageFormat; |
Lines 363-369
Link Here
|
363 |
} |
366 |
} |
364 |
} |
367 |
} |
365 |
|
368 |
|
366 |
class ContributorInfo implements IElementStateListener, VerifyListener, IDocumentListener { |
369 |
class ContributorInfo implements IElementStateListener, VerifyListener, IDocumentListener, IEncodingSupport { |
367 |
private final TextMergeViewer fViewer; |
370 |
private final TextMergeViewer fViewer; |
368 |
private final Object fElement; |
371 |
private final Object fElement; |
369 |
private char fLeg; |
372 |
private char fLeg; |
Lines 387-397
Link Here
|
387 |
} |
390 |
} |
388 |
} |
391 |
} |
389 |
} |
392 |
} |
390 |
|
393 |
|
|
|
394 |
public void setEncoding(String encoding) { |
395 |
if (fDocumentKey == null || fDocumentProvider == null) { |
396 |
return; |
397 |
} |
398 |
if (fDocumentProvider instanceof IStorageDocumentProvider) { |
399 |
IStorageDocumentProvider provider = (IStorageDocumentProvider) fDocumentProvider; |
400 |
String current = provider.getEncoding(fDocumentKey); |
401 |
boolean dirty = fDocumentProvider.canSaveDocument(fDocumentKey); |
402 |
if (!dirty) { |
403 |
String internal = encoding == null ? "" : encoding; //$NON-NLS-1$ |
404 |
if (!internal.equals(current)) { |
405 |
provider.setEncoding(fDocumentKey, encoding); |
406 |
try { |
407 |
fDocumentProvider.resetDocument(fDocumentKey); |
408 |
} catch (CoreException e) { |
409 |
CompareUIPlugin.log(e); |
410 |
} finally { |
411 |
update(true); |
412 |
} |
413 |
} |
414 |
} |
415 |
} |
416 |
} |
417 |
|
391 |
public String getEncoding() { |
418 |
public String getEncoding() { |
392 |
if (fEncoding == null) |
419 |
if (fDocumentProvider != null && fDocumentKey != null |
393 |
return ResourcesPlugin.getEncoding(); |
420 |
&& fDocumentProvider instanceof IStorageDocumentProvider) { |
394 |
return fEncoding; |
421 |
IStorageDocumentProvider provider = (IStorageDocumentProvider) fDocumentProvider; |
|
|
422 |
return provider.getEncoding(fDocumentKey); |
423 |
} |
424 |
return null; |
425 |
} |
426 |
|
427 |
public String getDefaultEncoding() { |
428 |
if (fDocumentProvider != null && fDocumentKey != null |
429 |
&& fDocumentProvider instanceof IStorageDocumentProvider) { |
430 |
IStorageDocumentProvider provider = (IStorageDocumentProvider) fDocumentProvider; |
431 |
return provider.getDefaultEncoding(); |
432 |
} |
433 |
return null; |
434 |
} |
435 |
|
436 |
private String internalGetEncoding() { |
437 |
if (fEncoding != null) { |
438 |
return fEncoding; |
439 |
} |
440 |
return ResourcesPlugin.getEncoding(); |
395 |
} |
441 |
} |
396 |
|
442 |
|
397 |
public void setEncodingIfAbsent(ContributorInfo otherContributor) { |
443 |
public void setEncodingIfAbsent(ContributorInfo otherContributor) { |
Lines 582-588
Link Here
|
582 |
String s= null; |
628 |
String s= null; |
583 |
|
629 |
|
584 |
try { |
630 |
try { |
585 |
String encoding = getEncoding(); |
631 |
String encoding = internalGetEncoding(); |
586 |
s = Utilities.readString(sca, encoding); |
632 |
s = Utilities.readString(sca, encoding); |
587 |
} catch (CoreException ex) { |
633 |
} catch (CoreException ex) { |
588 |
this.fViewer.setError(fLeg, ex.getMessage()); |
634 |
this.fViewer.setError(fLeg, ex.getMessage()); |
Lines 812-817
Link Here
|
812 |
IEditorInput input = getDocumentKey(); |
858 |
IEditorInput input = getDocumentKey(); |
813 |
if (input != null && input.equals(element)) { |
859 |
if (input != null && input.equals(element)) { |
814 |
this.fViewer.updateDirtyState(input, getDocumentProvider(), fLeg); |
860 |
this.fViewer.updateDirtyState(input, getDocumentProvider(), fLeg); |
|
|
861 |
|
862 |
// recalculate diffs and update controls |
863 |
new UIJob(CompareMessages.DocumentMerger_0) { |
864 |
public IStatus runInUIThread(IProgressMonitor monitor) { |
865 |
update(true); |
866 |
return Status.OK_STATUS; |
867 |
} |
868 |
}.schedule(); |
815 |
} |
869 |
} |
816 |
} |
870 |
} |
817 |
public void elementContentAboutToBeReplaced(Object element) { |
871 |
public void elementContentAboutToBeReplaced(Object element) { |
Lines 845-850
Link Here
|
845 |
if (oldContributor != null) { |
899 |
if (oldContributor != null) { |
846 |
fSelection = oldContributor.fSelection; |
900 |
fSelection = oldContributor.fSelection; |
847 |
fTopIndex = oldContributor.fTopIndex; |
901 |
fTopIndex = oldContributor.fTopIndex; |
|
|
902 |
fEncoding = oldContributor.fEncoding; |
848 |
} |
903 |
} |
849 |
|
904 |
|
850 |
} |
905 |
} |
Lines 2111-2117
Link Here
|
2111 |
|
2166 |
|
2112 |
// Add the find action to the popup menu of the viewer |
2167 |
// Add the find action to the popup menu of the viewer |
2113 |
contributeFindAction(part); |
2168 |
contributeFindAction(part); |
2114 |
|
2169 |
|
|
|
2170 |
contributeChangeEncodingAction(part); |
2171 |
|
2115 |
configureTextViewer(part); |
2172 |
configureTextViewer(part); |
2116 |
|
2173 |
|
2117 |
return part; |
2174 |
return part; |
Lines 2128-2133
Link Here
|
2128 |
viewer.addAction(MergeSourceViewer.FIND_ID, action); |
2185 |
viewer.addAction(MergeSourceViewer.FIND_ID, action); |
2129 |
} |
2186 |
} |
2130 |
|
2187 |
|
|
|
2188 |
private void contributeChangeEncodingAction(MergeSourceViewer viewer) { |
2189 |
ResourceBundle bundle = ResourceBundle.getBundle("org.eclipse.ui.texteditor.ConstructedTextEditorMessages"); //$NON-NLS-1$ |
2190 |
IAction action = new ChangeEncodingAction(bundle, "Editor.ChangeEncodingAction.", getTextEditorAdapter()); //$NON-NLS-1$ |
2191 |
viewer.addAction(MergeSourceViewer.CHANGE_ENCODING_ID, action); |
2192 |
} |
2193 |
|
2131 |
private void connectGlobalActions(final MergeSourceViewer part) { |
2194 |
private void connectGlobalActions(final MergeSourceViewer part) { |
2132 |
if (fHandlerService != null) { |
2195 |
if (fHandlerService != null) { |
2133 |
if (part != null) |
2196 |
if (part != null) |
Lines 2575-2581
Link Here
|
2575 |
if (contents != null) { |
2638 |
if (contents != null) { |
2576 |
byte[] bytes; |
2639 |
byte[] bytes; |
2577 |
try { |
2640 |
try { |
2578 |
bytes= contents.getBytes(left ? fLeftContributor.getEncoding() : fRightContributor.getEncoding()); |
2641 |
bytes= contents.getBytes(left ? fLeftContributor.internalGetEncoding() : fRightContributor.internalGetEncoding()); |
2579 |
} catch(UnsupportedEncodingException ex) { |
2642 |
} catch(UnsupportedEncodingException ex) { |
2580 |
// use default encoding |
2643 |
// use default encoding |
2581 |
bytes= contents.getBytes(); |
2644 |
bytes= contents.getBytes(); |
Lines 4512-4515
Link Here
|
4512 |
return true; |
4575 |
return true; |
4513 |
return false; |
4576 |
return false; |
4514 |
} |
4577 |
} |
|
|
4578 |
|
4579 |
private ITextEditor getTextEditorAdapter() { |
4580 |
return new ITextEditor () { |
4581 |
public void close(boolean save) { |
4582 |
// Implementing interface method |
4583 |
} |
4584 |
public void doRevertToSaved() { |
4585 |
// Implementing interface method |
4586 |
} |
4587 |
public IAction getAction(String actionId) { |
4588 |
// Implementing interface method |
4589 |
return null; |
4590 |
} |
4591 |
public IDocumentProvider getDocumentProvider() { |
4592 |
// Implementing interface method |
4593 |
return null; |
4594 |
} |
4595 |
public IRegion getHighlightRange() { |
4596 |
// Implementing interface method |
4597 |
return null; |
4598 |
} |
4599 |
public ISelectionProvider getSelectionProvider() { |
4600 |
// Implementing interface method |
4601 |
return null; |
4602 |
} |
4603 |
public boolean isEditable() { |
4604 |
// Implementing interface method |
4605 |
return false; |
4606 |
} |
4607 |
public void removeActionActivationCode(String actionId) { |
4608 |
// Implementing interface method |
4609 |
} |
4610 |
public void resetHighlightRange() { |
4611 |
// Implementing interface method |
4612 |
} |
4613 |
public void selectAndReveal(int offset, int length) { |
4614 |
// Implementing interface method |
4615 |
} |
4616 |
public void setAction(String actionId, IAction action) { |
4617 |
// Implementing interface method |
4618 |
} |
4619 |
public void setActionActivationCode(String actionId, |
4620 |
char activationCharacter, int activationKeyCode, |
4621 |
int activationStateMask) { |
4622 |
// Implementing interface method |
4623 |
} |
4624 |
public void setHighlightRange(int offset, int length, |
4625 |
boolean moveCursor) { |
4626 |
// Implementing interface method |
4627 |
} |
4628 |
public void showHighlightRangeOnly(boolean showHighlightRangeOnly) { |
4629 |
// Implementing interface method |
4630 |
} |
4631 |
public boolean showsHighlightRangeOnly() { |
4632 |
// Implementing interface method |
4633 |
return false; |
4634 |
} |
4635 |
public IEditorInput getEditorInput() { |
4636 |
if (fFocusPart == fAncestor && fAncestorContributor != null) { |
4637 |
return fAncestorContributor.getDocumentKey(); |
4638 |
} else if (fFocusPart == fLeft && fLeftContributor != null) { |
4639 |
return fLeftContributor.getDocumentKey(); |
4640 |
} else if (fFocusPart == fRight && fRightContributor != null) { |
4641 |
return fRightContributor.getDocumentKey(); |
4642 |
} else { |
4643 |
return null; |
4644 |
} |
4645 |
} |
4646 |
public IEditorSite getEditorSite() { |
4647 |
// Implementing interface method |
4648 |
return null; |
4649 |
} |
4650 |
public void init(IEditorSite site, IEditorInput input) |
4651 |
throws PartInitException { |
4652 |
// Implementing interface method |
4653 |
} |
4654 |
public void addPropertyListener(IPropertyListener listener) { |
4655 |
// Implementing interface method |
4656 |
} |
4657 |
public void createPartControl(Composite parent) { |
4658 |
// Implementing interface method |
4659 |
} |
4660 |
public void dispose() { |
4661 |
// Implementing interface method |
4662 |
} |
4663 |
public IWorkbenchPartSite getSite() { |
4664 |
// Implementing interface method |
4665 |
return new IWorkbenchPartSite() { |
4666 |
public String getId() { |
4667 |
// Implementing interface method |
4668 |
return null; |
4669 |
} |
4670 |
public IKeyBindingService getKeyBindingService() { |
4671 |
// Implementing interface method |
4672 |
return null; |
4673 |
} |
4674 |
public IWorkbenchPart getPart() { |
4675 |
// Implementing interface method |
4676 |
return null; |
4677 |
} |
4678 |
public String getPluginId() { |
4679 |
// Implementing interface method |
4680 |
return null; |
4681 |
} |
4682 |
public String getRegisteredName() { |
4683 |
// Implementing interface method |
4684 |
return null; |
4685 |
} |
4686 |
public void registerContextMenu(MenuManager menuManager, |
4687 |
ISelectionProvider selectionProvider) { |
4688 |
// Implementing interface method |
4689 |
} |
4690 |
public void registerContextMenu(String menuId, |
4691 |
MenuManager menuManager, |
4692 |
ISelectionProvider selectionProvider) { |
4693 |
// Implementing interface method |
4694 |
} |
4695 |
public IWorkbenchPage getPage() { |
4696 |
// Implementing interface method |
4697 |
return null; |
4698 |
} |
4699 |
public ISelectionProvider getSelectionProvider() { |
4700 |
// Implementing interface method |
4701 |
return null; |
4702 |
} |
4703 |
public Shell getShell() { |
4704 |
return fComposite.getShell(); |
4705 |
} |
4706 |
public IWorkbenchWindow getWorkbenchWindow() { |
4707 |
// Implementing interface method |
4708 |
return null; |
4709 |
} |
4710 |
public void setSelectionProvider(ISelectionProvider provider) { |
4711 |
// Implementing interface method |
4712 |
} |
4713 |
public Object getAdapter(Class adapter) { |
4714 |
// Implementing interface method |
4715 |
return null; |
4716 |
} |
4717 |
public Object getService(Class api) { |
4718 |
// Implementing interface method |
4719 |
return null; |
4720 |
} |
4721 |
public boolean hasService(Class api) { |
4722 |
// Implementing interface method |
4723 |
return false; |
4724 |
} |
4725 |
}; |
4726 |
} |
4727 |
public String getTitle() { |
4728 |
// Implementing interface method |
4729 |
return null; |
4730 |
} |
4731 |
public Image getTitleImage() { |
4732 |
// Implementing interface method |
4733 |
return null; |
4734 |
} |
4735 |
public String getTitleToolTip() { |
4736 |
// Implementing interface method |
4737 |
return null; |
4738 |
} |
4739 |
public void removePropertyListener(IPropertyListener listener) { |
4740 |
// Implementing interface method |
4741 |
} |
4742 |
public void setFocus() { |
4743 |
// Implementing interface method |
4744 |
} |
4745 |
public Object getAdapter(Class adapter) { |
4746 |
if (adapter == IEncodingSupport.class) { |
4747 |
if (fFocusPart == fAncestor) { |
4748 |
return fAncestorContributor; |
4749 |
} else if (fFocusPart == fLeft) { |
4750 |
return fLeftContributor; |
4751 |
} else if (fFocusPart == fRight) { |
4752 |
return fRightContributor; |
4753 |
} else { |
4754 |
return null; |
4755 |
} |
4756 |
} |
4757 |
return null; |
4758 |
} |
4759 |
public void doSave(IProgressMonitor monitor) { |
4760 |
// Implementing interface method |
4761 |
} |
4762 |
public void doSaveAs() { |
4763 |
// Implementing interface method |
4764 |
} |
4765 |
public boolean isDirty() { |
4766 |
if (fFocusPart == fLeft) { |
4767 |
return isLeftDirty(); |
4768 |
} else if (fFocusPart == fRight) { |
4769 |
return isRightDirty(); |
4770 |
} |
4771 |
return false; |
4772 |
} |
4773 |
public boolean isSaveAsAllowed() { |
4774 |
// Implementing interface method |
4775 |
return false; |
4776 |
} |
4777 |
public boolean isSaveOnCloseNeeded() { |
4778 |
// Implementing interface method |
4779 |
return false; |
4780 |
} |
4781 |
}; |
4782 |
} |
4515 |
} |
4783 |
} |