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 |
} |