View | Details | Raw Unified | Return to bug 223857 | Differences between
and this patch

Collapse All | Expand All

(-)compare/org/eclipse/compare/internal/MergeSourceViewer.java (+2 lines)
Lines 105-110 Link Here
105
	public static final String SAVE_ID= "save"; //$NON-NLS-1$
105
	public static final String SAVE_ID= "save"; //$NON-NLS-1$
106
	public static final String FIND_ID= "find"; //$NON-NLS-1$
106
	public static final String FIND_ID= "find"; //$NON-NLS-1$
107
	public static final String GOTO_LINE_ID= "gotoLine"; //$NON-NLS-1$
107
	public static final String GOTO_LINE_ID= "gotoLine"; //$NON-NLS-1$
108
	public static final String CHANGE_ENCODING_ID= "changeEncoding"; //$NON-NLS-1$
108
109
109
	class TextOperationAction extends MergeViewerAction {
110
	class TextOperationAction extends MergeViewerAction {
110
		
111
		
Lines 799-804 Link Here
799
		addMenu(menu, SELECT_ALL_ID);
800
		addMenu(menu, SELECT_ALL_ID);
800
801
801
		menu.add(new Separator("edit")); //$NON-NLS-1$
802
		menu.add(new Separator("edit")); //$NON-NLS-1$
803
		addMenu(menu, CHANGE_ENCODING_ID);
802
		menu.add(new Separator("find")); //$NON-NLS-1$
804
		menu.add(new Separator("find")); //$NON-NLS-1$
803
		addMenu(menu, FIND_ID);
805
		addMenu(menu, FIND_ID);
804
		
806
		
(-)compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java (-8 / +351 lines)
Lines 74-79 Link Here
74
import org.eclipse.jface.action.Action;
74
import org.eclipse.jface.action.Action;
75
import org.eclipse.jface.action.ActionContributionItem;
75
import org.eclipse.jface.action.ActionContributionItem;
76
import org.eclipse.jface.action.IAction;
76
import org.eclipse.jface.action.IAction;
77
import org.eclipse.jface.action.MenuManager;
77
import org.eclipse.jface.action.Separator;
78
import org.eclipse.jface.action.Separator;
78
import org.eclipse.jface.action.ToolBarManager;
79
import org.eclipse.jface.action.ToolBarManager;
79
import org.eclipse.jface.dialogs.ErrorDialog;
80
import org.eclipse.jface.dialogs.ErrorDialog;
Lines 139-144 Link Here
139
import org.eclipse.swt.graphics.Cursor;
140
import org.eclipse.swt.graphics.Cursor;
140
import org.eclipse.swt.graphics.Font;
141
import org.eclipse.swt.graphics.Font;
141
import org.eclipse.swt.graphics.GC;
142
import org.eclipse.swt.graphics.GC;
143
import org.eclipse.swt.graphics.Image;
142
import org.eclipse.swt.graphics.Point;
144
import org.eclipse.swt.graphics.Point;
143
import org.eclipse.swt.graphics.RGB;
145
import org.eclipse.swt.graphics.RGB;
144
import org.eclipse.swt.graphics.Rectangle;
146
import org.eclipse.swt.graphics.Rectangle;
Lines 152-165 Link Here
152
import org.eclipse.swt.widgets.ScrollBar;
154
import org.eclipse.swt.widgets.ScrollBar;
153
import org.eclipse.swt.widgets.Shell;
155
import org.eclipse.swt.widgets.Shell;
154
import org.eclipse.ui.IEditorInput;
156
import org.eclipse.ui.IEditorInput;
157
import org.eclipse.ui.IEditorSite;
158
import org.eclipse.ui.IKeyBindingService;
159
import org.eclipse.ui.IPropertyListener;
160
import org.eclipse.ui.IWorkbenchPage;
155
import org.eclipse.ui.IWorkbenchPart;
161
import org.eclipse.ui.IWorkbenchPart;
162
import org.eclipse.ui.IWorkbenchPartSite;
163
import org.eclipse.ui.IWorkbenchWindow;
164
import org.eclipse.ui.PartInitException;
156
import org.eclipse.ui.PlatformUI;
165
import org.eclipse.ui.PlatformUI;
157
import org.eclipse.ui.actions.ActionFactory;
166
import org.eclipse.ui.actions.ActionFactory;
158
import org.eclipse.ui.contexts.IContextService;
167
import org.eclipse.ui.contexts.IContextService;
159
import org.eclipse.ui.editors.text.EditorsUI;
168
import org.eclipse.ui.editors.text.EditorsUI;
169
import org.eclipse.ui.editors.text.IEncodingSupport;
170
import org.eclipse.ui.editors.text.IStorageDocumentProvider;
160
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
171
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
161
import org.eclipse.ui.texteditor.AbstractTextEditor;
172
import org.eclipse.ui.texteditor.AbstractTextEditor;
162
import org.eclipse.ui.texteditor.ChainedPreferenceStore;
173
import org.eclipse.ui.texteditor.ChainedPreferenceStore;
174
import org.eclipse.ui.texteditor.ChangeEncodingAction;
163
import org.eclipse.ui.texteditor.FindReplaceAction;
175
import org.eclipse.ui.texteditor.FindReplaceAction;
164
import org.eclipse.ui.texteditor.GotoLineAction;
176
import org.eclipse.ui.texteditor.GotoLineAction;
165
import org.eclipse.ui.texteditor.IDocumentProvider;
177
import org.eclipse.ui.texteditor.IDocumentProvider;
Lines 497-503 Link Here
497
		}
509
		}
498
	}
510
	}
499
511
500
	class ContributorInfo implements IElementStateListener, VerifyListener, IDocumentListener {
512
	class ContributorInfo implements IElementStateListener, VerifyListener, IDocumentListener, IEncodingSupport {
501
		private final TextMergeViewer fViewer;
513
		private final TextMergeViewer fViewer;
502
		private final Object fElement;
514
		private final Object fElement;
503
		private char fLeg;
515
		private char fLeg;
Lines 521-531 Link Here
521
				}
533
				}
522
			}
534
			}
523
		}
535
		}
524
		
536
537
		public void resetDocumentProvider() {
538
			if (fDocumentProvider == null || fDocumentKey == null) {
539
				return;
540
			}
541
			try {
542
				fDocumentProvider.resetDocument(fDocumentKey);
543
			} catch (CoreException e) {
544
				// TODO:
545
				e.printStackTrace();
546
			}
547
		}
548
549
		public void setEncoding(String encoding) {
550
			if (fDocumentKey == null || fDocumentProvider == null) {
551
				return;
552
			}
553
			if (fDocumentProvider instanceof IStorageDocumentProvider) {
554
				IStorageDocumentProvider provider = (IStorageDocumentProvider) fDocumentProvider;
555
				String current = provider.getEncoding(fDocumentKey);
556
				boolean dirty = fDocumentProvider.canSaveDocument(fDocumentKey);
557
				if (!dirty) {
558
					String internal = encoding == null ? "" : encoding; //$NON-NLS-1$
559
					if (!internal.equals(current)) {
560
						provider.setEncoding(fDocumentKey, encoding);
561
						try {
562
							fDocumentProvider.resetDocument(fDocumentKey);
563
						} catch (CoreException e) {
564
							CompareUIPlugin.log(e);
565
						} finally {
566
							update(true);
567
						}
568
					}
569
				}
570
			}
571
		}
572
525
		public String getEncoding() {
573
		public String getEncoding() {
526
			if (fEncoding == null)
574
			if (fDocumentProvider != null && fDocumentKey != null
527
				return ResourcesPlugin.getEncoding();
575
					&& fDocumentProvider instanceof IStorageDocumentProvider) {
528
			return fEncoding;
576
				IStorageDocumentProvider provider = (IStorageDocumentProvider) fDocumentProvider;
577
				return provider.getEncoding(fDocumentKey);
578
			}
579
			return null;
580
		}
581
582
		public String getDefaultEncoding() {
583
			if (fDocumentProvider != null && fDocumentKey != null
584
					&& fDocumentProvider instanceof IStorageDocumentProvider) {
585
				IStorageDocumentProvider provider = (IStorageDocumentProvider) fDocumentProvider;
586
				return provider.getDefaultEncoding();
587
			}
588
			return null;
589
		}
590
591
		public String getInternalEncoding() {
592
			if (fEncoding != null) {
593
				return fEncoding;
594
			}
595
			return ResourcesPlugin.getEncoding();
529
		}
596
		}
530
597
531
		public void setEncodingIfAbsent(ContributorInfo otherContributor) {
598
		public void setEncodingIfAbsent(ContributorInfo otherContributor) {
Lines 716-722 Link Here
716
				String s= null;
783
				String s= null;
717
784
718
				try {
785
				try {
719
					String encoding = getEncoding();
786
					String encoding = getInternalEncoding();
720
					s = Utilities.readString(sca, encoding);
787
					s = Utilities.readString(sca, encoding);
721
				} catch (CoreException ex) {
788
				} catch (CoreException ex) {
722
					this.fViewer.setError(fLeg, ex.getMessage());
789
					this.fViewer.setError(fLeg, ex.getMessage());
Lines 836-842 Link Here
836
		 * </ol>
903
		 * </ol>
837
		 * @return the document key used to obtain a shared document or <code>null</code>
904
		 * @return the document key used to obtain a shared document or <code>null</code>
838
		 */
905
		 */
839
		private IEditorInput getDocumentKey() {
906
		public IEditorInput getDocumentKey() {
840
			if (fDocumentKey != null)
907
			if (fDocumentKey != null)
841
				return fDocumentKey;
908
				return fDocumentKey;
842
			if (isUsingDefaultContentProvider() && fElement != null && canHaveSharedDocument()) {
909
			if (isUsingDefaultContentProvider() && fElement != null && canHaveSharedDocument()) {
Lines 979-984 Link Here
979
			if (oldContributor != null) {
1046
			if (oldContributor != null) {
980
				fSelection = oldContributor.fSelection;
1047
				fSelection = oldContributor.fSelection;
981
				fTopIndex = oldContributor.fTopIndex;
1048
				fTopIndex = oldContributor.fTopIndex;
1049
				fEncoding = oldContributor.fEncoding;
982
			}
1050
			}
983
				
1051
				
984
		}
1052
		}
Lines 2391-2396 Link Here
2391
2459
2392
		contributeGotoLineAction(viewer);
2460
		contributeGotoLineAction(viewer);
2393
2461
2462
		contributeChangeEncodingAction(viewer);
2463
2394
		getSourceViewerDecorationSupport(viewer.getSourceViewer()).install(fPreferenceStore);
2464
		getSourceViewerDecorationSupport(viewer.getSourceViewer()).install(fPreferenceStore);
2395
2465
2396
		return viewer;
2466
		return viewer;
Lines 2430-2435 Link Here
2430
		viewer.addAction(MergeSourceViewer.GOTO_LINE_ID, action);
2500
		viewer.addAction(MergeSourceViewer.GOTO_LINE_ID, action);
2431
	}
2501
	}
2432
2502
2503
	private void contributeChangeEncodingAction(MergeSourceViewer viewer) {
2504
		ResourceBundle bundle = ResourceBundle.getBundle("org.eclipse.ui.texteditor.ConstructedTextEditorMessages"); //$NON-NLS-1$
2505
		IAction action = new ChangeEncodingAction(bundle, "Editor.ChangeEncodingAction.", getTextEditorAdapter()); //$NON-NLS-1$
2506
		viewer.addAction(MergeSourceViewer.CHANGE_ENCODING_ID, action);
2507
	}
2508
2509
	private ITextEditor getTextEditorAdapter() {
2510
		return new ITextEditor () {
2511
			public void close(boolean save) {
2512
				// Implementing interface method
2513
			}
2514
2515
			public void doRevertToSaved() {
2516
				// Implementing interface method
2517
			}
2518
2519
			public IAction getAction(String actionId) {
2520
				// Implementing interface method
2521
				return null;
2522
			}
2523
2524
			public IDocumentProvider getDocumentProvider() {
2525
				// Implementing interface method
2526
				return null;
2527
			}
2528
2529
			public IRegion getHighlightRange() {
2530
				// Implementing interface method
2531
				return null;
2532
			}
2533
2534
			public ISelectionProvider getSelectionProvider() {
2535
				// Implementing interface method
2536
				return null;
2537
			}
2538
2539
			public boolean isEditable() {
2540
				// Implementing interface method
2541
				return false;
2542
			}
2543
2544
			public void removeActionActivationCode(String actionId) {
2545
				// Implementing interface method
2546
			}
2547
2548
			public void resetHighlightRange() {
2549
				// Implementing interface method
2550
			}
2551
2552
			public void selectAndReveal(int offset, int length) {
2553
				// Implementing interface method
2554
			}
2555
2556
			public void setAction(String actionId, IAction action) {
2557
				// Implementing interface method
2558
			}
2559
2560
			public void setActionActivationCode(String actionId,
2561
					char activationCharacter, int activationKeyCode,
2562
					int activationStateMask) {
2563
				// Implementing interface method
2564
			}
2565
2566
			public void setHighlightRange(int offset, int length,
2567
					boolean moveCursor) {
2568
				// Implementing interface method
2569
			}
2570
2571
			public void showHighlightRangeOnly(boolean showHighlightRangeOnly) {
2572
				// Implementing interface method
2573
			}
2574
2575
			public boolean showsHighlightRangeOnly() {
2576
				// Implementing interface method
2577
				return false;
2578
			}
2579
2580
			public IEditorInput getEditorInput() {
2581
				if (fFocusPart == fAncestor && fAncestorContributor != null) {
2582
					return fAncestorContributor.getDocumentKey();
2583
				} else if (fFocusPart == fLeft && fLeftContributor != null) {
2584
					return fLeftContributor.getDocumentKey();
2585
				} else if (fFocusPart == fRight && fRightContributor != null) {
2586
					return fRightContributor.getDocumentKey();
2587
				} else {
2588
					return null;
2589
				}
2590
			}
2591
2592
			public IEditorSite getEditorSite() {
2593
				// Implementing interface method
2594
				return null;
2595
			}
2596
2597
			public void init(IEditorSite site, IEditorInput input)
2598
					throws PartInitException {
2599
				// Implementing interface method
2600
			}
2601
2602
			public void addPropertyListener(IPropertyListener listener) {
2603
				// Implementing interface method
2604
			}
2605
2606
			public void createPartControl(Composite parent) {
2607
				// Implementing interface method
2608
			}
2609
2610
			public void dispose() {
2611
				// Implementing interface method
2612
			}
2613
2614
			public IWorkbenchPartSite getSite() {
2615
				// Implementing interface method
2616
				return new IWorkbenchPartSite() {
2617
2618
					public String getId() {
2619
						// Implementing interface method
2620
						return null;
2621
					}
2622
2623
					public IKeyBindingService getKeyBindingService() {
2624
						// Implementing interface method
2625
						return null;
2626
					}
2627
2628
					public IWorkbenchPart getPart() {
2629
						// Implementing interface method
2630
						return null;
2631
					}
2632
2633
					public String getPluginId() {
2634
						// Implementing interface method
2635
						return null;
2636
					}
2637
2638
					public String getRegisteredName() {
2639
						// Implementing interface method
2640
						return null;
2641
					}
2642
2643
					public void registerContextMenu(MenuManager menuManager,
2644
							ISelectionProvider selectionProvider) {
2645
						// Implementing interface method
2646
					}
2647
2648
					public void registerContextMenu(String menuId,
2649
							MenuManager menuManager,
2650
							ISelectionProvider selectionProvider) {
2651
						// Implementing interface method
2652
					}
2653
2654
					public IWorkbenchPage getPage() {
2655
						// Implementing interface method
2656
						return null;
2657
					}
2658
2659
					public ISelectionProvider getSelectionProvider() {
2660
						// Implementing interface method
2661
						return null;
2662
					}
2663
2664
					public Shell getShell() {
2665
						return fComposite.getShell();
2666
					}
2667
2668
					public IWorkbenchWindow getWorkbenchWindow() {
2669
						// Implementing interface method
2670
						return null;
2671
					}
2672
2673
					public void setSelectionProvider(ISelectionProvider provider) {
2674
						// Implementing interface method
2675
					}
2676
2677
					public Object getAdapter(Class adapter) {
2678
						// Implementing interface method
2679
						return null;
2680
					}
2681
2682
					public Object getService(Class api) {
2683
						// Implementing interface method
2684
						return null;
2685
					}
2686
2687
					public boolean hasService(Class api) {
2688
						// Implementing interface method
2689
						return false;
2690
					}
2691
2692
				};
2693
			}
2694
2695
			public String getTitle() {
2696
				// Implementing interface method
2697
				return null;
2698
			}
2699
2700
			public Image getTitleImage() {
2701
				// Implementing interface method
2702
				return null;
2703
			}
2704
2705
			public String getTitleToolTip() {
2706
				// Implementing interface method
2707
				return null;
2708
			}
2709
2710
			public void removePropertyListener(IPropertyListener listener) {
2711
				// Implementing interface method
2712
			}
2713
2714
			public void setFocus() {
2715
				// Implementing interface method
2716
			}
2717
2718
			public Object getAdapter(Class adapter) {
2719
				if (adapter == IEncodingSupport.class) {
2720
					if (fFocusPart == fAncestor) {
2721
						return fAncestorContributor;
2722
					} else if (fFocusPart == fLeft) {
2723
						return fLeftContributor;
2724
					} else if (fFocusPart == fRight) {
2725
						return fRightContributor;
2726
					} else {
2727
						return null;
2728
					}
2729
				}
2730
				return null;
2731
			}
2732
2733
			public void doSave(IProgressMonitor monitor) {
2734
				// Implementing interface method
2735
			}
2736
2737
			public void doSaveAs() {
2738
				// Implementing interface method
2739
			}
2740
2741
			public boolean isDirty() {
2742
				// Implementing interface method
2743
				return false;
2744
			}
2745
2746
			public boolean isSaveAsAllowed() {
2747
				// Implementing interface method
2748
				return false;
2749
			}
2750
2751
			public boolean isSaveOnCloseNeeded() {
2752
				// Implementing interface method
2753
				return false;
2754
			}
2755
2756
		};
2757
	}
2758
2433
	private void connectGlobalActions(final MergeSourceViewer part) {
2759
	private void connectGlobalActions(final MergeSourceViewer part) {
2434
		if (fHandlerService != null) {
2760
		if (fHandlerService != null) {
2435
			if (part != null)
2761
			if (part != null)
Lines 2938-2944 Link Here
2938
				if (contents != null) {
3264
				if (contents != null) {
2939
					byte[] bytes;
3265
					byte[] bytes;
2940
					try {
3266
					try {
2941
						bytes= contents.getBytes(left ? fLeftContributor.getEncoding() : fRightContributor.getEncoding());
3267
						bytes= contents.getBytes(left ? fLeftContributor.getInternalEncoding() : fRightContributor.getInternalEncoding());
2942
					} catch(UnsupportedEncodingException ex) {
3268
					} catch(UnsupportedEncodingException ex) {
2943
						// use default encoding
3269
						// use default encoding
2944
						bytes= contents.getBytes();
3270
						bytes= contents.getBytes();
Lines 4898-4901 Link Here
4898
			return true;
5224
			return true;
4899
		return false;
5225
		return false;
4900
	}
5226
	}
5227
5228
	protected void setLeftDirty(boolean dirty) {
5229
		super.setLeftDirty(dirty);
5230
		IAction action = fLeft.getAction(MergeSourceViewer.CHANGE_ENCODING_ID);
5231
		if (action != null) {
5232
			action.setEnabled(!dirty);
5233
		}
5234
	}
5235
5236
	protected void setRightDirty(boolean dirty) {
5237
		super.setRightDirty(dirty);
5238
		IAction action = fRight.getAction(MergeSourceViewer.CHANGE_ENCODING_ID);
5239
		if (action != null) {
5240
			action.setEnabled(!dirty);
5241
		}
5242
	}
5243
4901
}
5244
}

Return to bug 223857