View | Details | Raw Unified | Return to bug 267171
Collapse All | Expand All

(-)src/org/eclipse/team/internal/ui/synchronize/SaveablesCompareEditorInput.java (-45 / +116 lines)
Lines 14-21 Link Here
14
14
15
import org.eclipse.compare.*;
15
import org.eclipse.compare.*;
16
import org.eclipse.compare.structuremergeviewer.*;
16
import org.eclipse.compare.structuremergeviewer.*;
17
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.resources.*;
18
import org.eclipse.core.resources.IResource;
19
import org.eclipse.core.runtime.*;
18
import org.eclipse.core.runtime.*;
20
import org.eclipse.jface.action.*;
19
import org.eclipse.jface.action.*;
21
import org.eclipse.jface.resource.ImageDescriptor;
20
import org.eclipse.jface.resource.ImageDescriptor;
Lines 28-33 Link Here
28
import org.eclipse.swt.events.DisposeEvent;
27
import org.eclipse.swt.events.DisposeEvent;
29
import org.eclipse.swt.events.DisposeListener;
28
import org.eclipse.swt.events.DisposeListener;
30
import org.eclipse.swt.graphics.Image;
29
import org.eclipse.swt.graphics.Image;
30
import org.eclipse.swt.graphics.Point;
31
import org.eclipse.swt.widgets.*;
31
import org.eclipse.swt.widgets.*;
32
import org.eclipse.team.internal.ui.*;
32
import org.eclipse.team.internal.ui.*;
33
import org.eclipse.team.internal.ui.history.CompareFileRevisionEditorInput;
33
import org.eclipse.team.internal.ui.history.CompareFileRevisionEditorInput;
Lines 38-45 Link Here
38
import org.eclipse.team.ui.synchronize.SaveableCompareEditorInput;
38
import org.eclipse.team.ui.synchronize.SaveableCompareEditorInput;
39
import org.eclipse.ui.*;
39
import org.eclipse.ui.*;
40
import org.eclipse.ui.actions.*;
40
import org.eclipse.ui.actions.*;
41
import org.eclipse.ui.ide.IGotoMarker;
41
import org.eclipse.ui.keys.IBindingService;
42
import org.eclipse.ui.keys.IBindingService;
42
import org.eclipse.ui.services.IDisposable;
43
import org.eclipse.ui.services.IDisposable;
44
import org.eclipse.ui.texteditor.ITextEditor;
43
45
44
/**
46
/**
45
 * A compare editor input that makes use of a {@link Saveable} to manage the
47
 * A compare editor input that makes use of a {@link Saveable} to manage the
Lines 524-531 Link Here
524
		if (lLeftSaveable instanceof LocalResourceSaveableComparison) {
526
		if (lLeftSaveable instanceof LocalResourceSaveableComparison) {
525
			pMenuManager.addMenuListener(new IMenuListener() {
527
			pMenuManager.addMenuListener(new IMenuListener() {
526
				public void menuAboutToShow(IMenuManager manager) {
528
				public void menuAboutToShow(IMenuManager manager) {
527
					handleMenuAboutToShow(manager, lLeftSaveable, lLeftElement,
529
					handleMenuAboutToShow(manager, getContainer(), lLeftSaveable, lLeftElement, pSelectionProvider);
528
							pSelectionProvider);
529
				}
530
				}
530
			});
531
			});
531
		}
532
		}
Lines 535-542 Link Here
535
		if (lRightSaveable instanceof LocalResourceSaveableComparison) {
536
		if (lRightSaveable instanceof LocalResourceSaveableComparison) {
536
			pMenuManager.addMenuListener(new IMenuListener() {
537
			pMenuManager.addMenuListener(new IMenuListener() {
537
				public void menuAboutToShow(IMenuManager manager) {
538
				public void menuAboutToShow(IMenuManager manager) {
538
					handleMenuAboutToShow(manager, lRightSaveable,
539
					handleMenuAboutToShow(manager, getContainer(), lRightSaveable, lRightElement, pSelectionProvider);
539
							lRightElement, pSelectionProvider);
540
				}
540
				}
541
			});
541
			});
542
		}
542
		}
Lines 628-672 Link Here
628
		return true;
628
		return true;
629
	}
629
	}
630
630
631
	private void handleMenuAboutToShow(IMenuManager manager, Saveable saveable,
631
	private static String getShowInMenuLabel() {
632
			ITypedElement element, ISelectionProvider provider) {
633
		if (provider instanceof ITextViewer) {
634
			ITextViewer v = (ITextViewer) provider;
635
			IDocument d = v.getDocument();
636
			IDocument other = (IDocument) Utils.getAdapter(saveable,
637
					IDocument.class);
638
			if (d == other) {
639
				if (element instanceof IResourceProvider) {
640
					IResourceProvider rp = (IResourceProvider) element;
641
					IResource resource = rp.getResource();
642
					StructuredSelection selection = new StructuredSelection(
643
							resource);
644
					IWorkbenchPart workbenchPart = getContainer()
645
							.getWorkbenchPart();
646
					if (workbenchPart != null) {
647
						IWorkbenchSite ws = workbenchPart.getSite();
648
						MenuManager submenu1 = new MenuManager(
649
								getShowInMenuLabel());
650
						IContributionItem showInMenu = ContributionItemFactory.VIEWS_SHOW_IN
651
								.create(ws.getWorkbenchWindow());
652
						submenu1.add(showInMenu);
653
						manager.insertAfter("file", submenu1); //$NON-NLS-1$
654
						MenuManager submenu2 = new MenuManager(
655
								TeamUIMessages.OpenWithActionGroup_0);
656
						submenu2.add(new OpenWithMenu(ws.getPage(), resource));
657
						manager.insertAfter("file", submenu2); //$NON-NLS-1$
658
659
						OpenFileAction openFileAction = new OpenFileAction(ws
660
								.getPage());
661
						openFileAction.selectionChanged(selection);
662
						manager.insertAfter("file", openFileAction); //$NON-NLS-1$
663
					}
664
				}
665
			}
666
		}
667
	}
668
669
	private String getShowInMenuLabel() {
670
		String keyBinding = null;
632
		String keyBinding = null;
671
633
672
		IBindingService bindingService = (IBindingService) PlatformUI
634
		IBindingService bindingService = (IBindingService) PlatformUI
Lines 784-787 Link Here
784
			return false;
746
			return false;
785
		}
747
		}
786
	}
748
	}
749
750
	public static void handleMenuAboutToShow(IMenuManager manager, ICompareContainer container, Saveable saveable, ITypedElement element, ISelectionProvider provider) {
751
		if (provider instanceof ITextViewer) {
752
			final ITextViewer v= (ITextViewer)provider;
753
			IDocument d= v.getDocument();
754
			IDocument other= (IDocument)Utils.getAdapter(saveable, IDocument.class);
755
			if (d == other) {
756
				if (element instanceof IResourceProvider) {
757
					IResourceProvider rp= (IResourceProvider)element;
758
					IResource resource= rp.getResource();
759
					StructuredSelection selection= new StructuredSelection(resource);
760
					IWorkbenchPart workbenchPart= container.getWorkbenchPart();
761
					if (workbenchPart != null) {
762
						final IWorkbenchSite ws= workbenchPart.getSite();
763
764
						MenuManager submenu1= new MenuManager(getShowInMenuLabel());
765
						IContributionItem showInMenu= ContributionItemFactory.VIEWS_SHOW_IN.create(ws.getWorkbenchWindow());
766
						submenu1.add(showInMenu);
767
						manager.insertAfter("file", submenu1); //$NON-NLS-1$
768
						MenuManager submenu2= new MenuManager(TeamUIMessages.OpenWithActionGroup_0);
769
						submenu2.add(new OpenWithMenu(ws.getPage(), resource) {
770
							/*
771
							 * (non-Javadoc)
772
							 * 
773
							 * @see org.eclipse.ui.actions.OpenWithMenu#openEditor(org.eclipse.ui.
774
							 * IEditorDescriptor, boolean)
775
							 */
776
							protected void openEditor(IEditorDescriptor editorDescriptor, boolean openUsingDescriptor) {
777
								super.openEditor(editorDescriptor, openUsingDescriptor);
778
								IEditorPart editor= ws.getPage().getActiveEditor();
779
								Point selectedRange= v.getSelectedRange();
780
								revealInEditor(editor, selectedRange.x, selectedRange.y);
781
							}
782
						});
783
						manager.insertAfter("file", submenu2); //$NON-NLS-1$
784
785
						OpenFileAction openFileAction= new OpenFileAction(ws.getPage()) {
786
							/*
787
							 * (non-Javadoc)
788
							 * 
789
							 * @see org.eclipse.ui.actions.OpenSystemEditorAction#run()
790
							 */
791
							public void run() {
792
								super.run();
793
								IEditorPart editor= ws.getPage().getActiveEditor();
794
								Point selectedRange= v.getSelectedRange();
795
								revealInEditor(editor, selectedRange.x, selectedRange.y);
796
							}
797
						};
798
						openFileAction.selectionChanged(selection);
799
						manager.insertAfter("file", openFileAction); //$NON-NLS-1$
800
					}
801
				}
802
			}
803
		}
804
	}
805
806
	/**
807
	 * Selects and reveals the given offset and length in the given editor part.
808
	 * 
809
	 * @param editor the editor part
810
	 * @param offset the offset
811
	 * @param length the length
812
	 * @since 3.6
813
	 */
814
	private static void revealInEditor(IEditorPart editor, final int offset, final int length) {
815
		if (editor instanceof ITextEditor) {
816
			((ITextEditor)editor).selectAndReveal(offset, length);
817
			return;
818
		}
819
820
		// Support for non-text editor - try IGotoMarker interface
821
		final IGotoMarker gotoMarkerTarget;
822
		if (editor instanceof IGotoMarker)
823
			gotoMarkerTarget= (IGotoMarker)editor;
824
		else
825
			gotoMarkerTarget= editor != null ? (IGotoMarker)editor.getAdapter(IGotoMarker.class) : null;
826
		if (gotoMarkerTarget != null) {
827
			final IEditorInput input= editor.getEditorInput();
828
			if (input instanceof IFileEditorInput) {
829
				WorkspaceModifyOperation op= new WorkspaceModifyOperation() {
830
					protected void execute(IProgressMonitor monitor) throws CoreException {
831
						IMarker marker= null;
832
						try {
833
							marker= ((IFileEditorInput)input).getFile().createMarker(IMarker.TEXT);
834
							marker.setAttribute(IMarker.CHAR_START, offset);
835
							marker.setAttribute(IMarker.CHAR_END, offset + length);
836
837
							gotoMarkerTarget.gotoMarker(marker);
838
839
						} finally {
840
							if (marker != null)
841
								marker.delete();
842
						}
843
					}
844
				};
845
846
				try {
847
					op.run(null);
848
				} catch (InvocationTargetException ex) {
849
					// reveal failed
850
				} catch (InterruptedException e) {
851
					Assert.isTrue(false, "this operation can not be canceled"); //$NON-NLS-1$
852
				}
853
			}
854
			return;
855
		}
856
	}
857
787
}
858
}
(-)src/org/eclipse/team/ui/synchronize/SaveableCompareEditorInput.java (-56 / +6 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2009 IBM Corporation and others.
2
 * Copyright (c) 2006, 2010 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 20-29 Link Here
20
import org.eclipse.jface.action.*;
20
import org.eclipse.jface.action.*;
21
import org.eclipse.jface.resource.ImageDescriptor;
21
import org.eclipse.jface.resource.ImageDescriptor;
22
import org.eclipse.jface.resource.ImageRegistry;
22
import org.eclipse.jface.resource.ImageRegistry;
23
import org.eclipse.jface.text.IDocument;
24
import org.eclipse.jface.text.ITextViewer;
25
import org.eclipse.jface.util.IPropertyChangeListener;
23
import org.eclipse.jface.util.IPropertyChangeListener;
26
import org.eclipse.jface.viewers.*;
24
import org.eclipse.jface.viewers.ISelectionProvider;
25
import org.eclipse.jface.viewers.Viewer;
27
import org.eclipse.osgi.util.NLS;
26
import org.eclipse.osgi.util.NLS;
28
import org.eclipse.swt.events.DisposeEvent;
27
import org.eclipse.swt.events.DisposeEvent;
29
import org.eclipse.swt.events.DisposeListener;
28
import org.eclipse.swt.events.DisposeListener;
Lines 31-43 Link Here
31
import org.eclipse.swt.widgets.*;
30
import org.eclipse.swt.widgets.*;
32
import org.eclipse.team.internal.ui.*;
31
import org.eclipse.team.internal.ui.*;
33
import org.eclipse.team.internal.ui.history.CompareFileRevisionEditorInput;
32
import org.eclipse.team.internal.ui.history.CompareFileRevisionEditorInput;
34
import org.eclipse.team.internal.ui.synchronize.LocalResourceSaveableComparison;
35
import org.eclipse.team.internal.ui.synchronize.LocalResourceTypedElement;
36
import org.eclipse.team.internal.ui.synchronize.EditableSharedDocumentAdapter.ISharedDocumentAdapterListener;
33
import org.eclipse.team.internal.ui.synchronize.EditableSharedDocumentAdapter.ISharedDocumentAdapterListener;
34
import org.eclipse.team.internal.ui.synchronize.*;
37
import org.eclipse.team.ui.mapping.SaveableComparison;
35
import org.eclipse.team.ui.mapping.SaveableComparison;
38
import org.eclipse.ui.*;
36
import org.eclipse.ui.*;
39
import org.eclipse.ui.actions.*;
40
import org.eclipse.ui.keys.IBindingService;
41
import org.eclipse.ui.services.IDisposable;
37
import org.eclipse.ui.services.IDisposable;
42
38
43
/**
39
/**
Lines 472-530 Link Here
472
		super.registerContextMenu(menu, selectionProvider);
468
		super.registerContextMenu(menu, selectionProvider);
473
		final Saveable saveable = getSaveable();
469
		final Saveable saveable = getSaveable();
474
		if (saveable instanceof LocalResourceSaveableComparison) {
470
		if (saveable instanceof LocalResourceSaveableComparison) {
471
			final ITypedElement element= getFileElement(getCompareInput(), this);
475
			menu.addMenuListener(new IMenuListener() {
472
			menu.addMenuListener(new IMenuListener() {
476
				public void menuAboutToShow(IMenuManager manager) {
473
				public void menuAboutToShow(IMenuManager manager) {
477
					handleMenuAboutToShow(manager, saveable, selectionProvider);
474
					SaveablesCompareEditorInput.handleMenuAboutToShow(manager, getContainer(), saveable, element, selectionProvider);
478
				}
475
				}
479
			});
476
			});
480
		}
477
		}
481
	}
478
	}
482
	
479
	
483
	/* package */ void handleMenuAboutToShow (IMenuManager manager, Saveable saveable, ISelectionProvider provider) {
484
		if (provider instanceof ITextViewer) {
485
			ITextViewer v = (ITextViewer) provider;
486
			IDocument d = v.getDocument();
487
			IDocument other = (IDocument)Utils.getAdapter(saveable, IDocument.class);
488
			if (d == other) {
489
				ITypedElement element = getFileElement(getCompareInput(), this);
490
				if (element instanceof IResourceProvider) {
491
					IResourceProvider rp = (IResourceProvider) element;
492
					IResource resource = rp.getResource();
493
					StructuredSelection selection = new StructuredSelection(resource);
494
					IWorkbenchPart workbenchPart = getContainer().getWorkbenchPart();
495
					if (workbenchPart != null) {
496
						IWorkbenchSite ws = workbenchPart.getSite();
497
						
498
						MenuManager submenu1 =
499
							new MenuManager(getShowInMenuLabel());
500
						IContributionItem showInMenu = ContributionItemFactory.VIEWS_SHOW_IN.create(ws.getWorkbenchWindow());
501
						submenu1.add(showInMenu);
502
						manager.insertAfter("file", submenu1); //$NON-NLS-1$
503
						MenuManager submenu2 =
504
							new MenuManager(TeamUIMessages.OpenWithActionGroup_0);
505
						submenu2.add(new OpenWithMenu(ws.getPage(), resource));
506
						manager.insertAfter("file", submenu2); //$NON-NLS-1$
507
						
508
						OpenFileAction openFileAction = new OpenFileAction(ws.getPage());
509
						openFileAction.selectionChanged(selection);
510
						manager.insertAfter("file", openFileAction); //$NON-NLS-1$
511
					}
512
				}
513
			}
514
		}
515
	}
516
	
517
	private String getShowInMenuLabel() {
518
		String keyBinding= null;
519
		
520
		IBindingService bindingService= (IBindingService)PlatformUI.getWorkbench().getAdapter(IBindingService.class);
521
		if (bindingService != null)
522
			keyBinding= bindingService.getBestActiveBindingFormattedFor(IWorkbenchCommandConstants.NAVIGATE_SHOW_IN_QUICK_MENU);
523
		
524
		if (keyBinding == null)
525
			keyBinding= ""; //$NON-NLS-1$
526
		
527
		return NLS.bind(TeamUIMessages.SaveableCompareEditorInput_0, keyBinding);
528
	}
529
530
}
480
}

Return to bug 267171