Lines 96-101
Link Here
|
96 |
import org.eclipse.jface.text.source.Annotation; |
96 |
import org.eclipse.jface.text.source.Annotation; |
97 |
import org.eclipse.jface.text.source.AnnotationRulerColumn; |
97 |
import org.eclipse.jface.text.source.AnnotationRulerColumn; |
98 |
import org.eclipse.jface.text.source.CompositeRuler; |
98 |
import org.eclipse.jface.text.source.CompositeRuler; |
|
|
99 |
import org.eclipse.jface.text.source.IAnnotationHover; |
100 |
import org.eclipse.jface.text.source.IAnnotationHoverExtension; |
99 |
import org.eclipse.jface.text.source.IAnnotationModel; |
101 |
import org.eclipse.jface.text.source.IAnnotationModel; |
100 |
import org.eclipse.jface.text.source.IAnnotationModelExtension; |
102 |
import org.eclipse.jface.text.source.IAnnotationModelExtension; |
101 |
import org.eclipse.jface.text.source.ICharacterPairMatcher; |
103 |
import org.eclipse.jface.text.source.ICharacterPairMatcher; |
Lines 104-110
Link Here
|
104 |
import org.eclipse.jface.text.source.ISourceViewerExtension2; |
106 |
import org.eclipse.jface.text.source.ISourceViewerExtension2; |
105 |
import org.eclipse.jface.text.source.IVerticalRuler; |
107 |
import org.eclipse.jface.text.source.IVerticalRuler; |
106 |
import org.eclipse.jface.text.source.IVerticalRulerColumn; |
108 |
import org.eclipse.jface.text.source.IVerticalRulerColumn; |
|
|
109 |
import org.eclipse.jface.text.source.IVerticalRulerInfo; |
107 |
import org.eclipse.jface.text.source.LineChangeHover; |
110 |
import org.eclipse.jface.text.source.LineChangeHover; |
|
|
111 |
import org.eclipse.jface.text.source.SourceViewer; |
108 |
import org.eclipse.jface.text.source.SourceViewerConfiguration; |
112 |
import org.eclipse.jface.text.source.SourceViewerConfiguration; |
109 |
import org.eclipse.jface.text.source.projection.ProjectionSupport; |
113 |
import org.eclipse.jface.text.source.projection.ProjectionSupport; |
110 |
import org.eclipse.jface.text.source.projection.ProjectionViewer; |
114 |
import org.eclipse.jface.text.source.projection.ProjectionViewer; |
Lines 674-679
Link Here
|
674 |
*/ |
678 |
*/ |
675 |
class InformationDispatchAction extends TextEditorAction { |
679 |
class InformationDispatchAction extends TextEditorAction { |
676 |
|
680 |
|
|
|
681 |
/** |
682 |
* Information provider used to present the information. |
683 |
* |
684 |
* @since 3.0 |
685 |
*/ |
686 |
class InformationProvider implements IInformationProvider, IInformationProviderExtension2 { |
687 |
|
688 |
private IRegion fHoverRegion; |
689 |
private String fHoverInfo; |
690 |
private IInformationControlCreator fControlCreator; |
691 |
|
692 |
InformationProvider(IRegion hoverRegion, String hoverInfo, IInformationControlCreator controlCreator) { |
693 |
fHoverRegion= hoverRegion; |
694 |
fHoverInfo= hoverInfo; |
695 |
fControlCreator= controlCreator; |
696 |
} |
697 |
/* |
698 |
* @see org.eclipse.jface.text.information.IInformationProvider#getSubject(org.eclipse.jface.text.ITextViewer, int) |
699 |
*/ |
700 |
public IRegion getSubject(ITextViewer textViewer, int invocationOffset) { |
701 |
return fHoverRegion; |
702 |
} |
703 |
/* |
704 |
* @see org.eclipse.jface.text.information.IInformationProvider#getInformation(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion) |
705 |
*/ |
706 |
public String getInformation(ITextViewer textViewer, IRegion subject) { |
707 |
return fHoverInfo; |
708 |
} |
709 |
/* |
710 |
* @see org.eclipse.jface.text.information.IInformationProviderExtension2#getInformationPresenterControlCreator() |
711 |
* @since 3.0 |
712 |
*/ |
713 |
public IInformationControlCreator getInformationPresenterControlCreator() { |
714 |
return fControlCreator; |
715 |
} |
716 |
} |
717 |
|
677 |
/** The wrapped text operation action. */ |
718 |
/** The wrapped text operation action. */ |
678 |
private final TextOperationAction fTextOperationAction; |
719 |
private final TextOperationAction fTextOperationAction; |
679 |
|
720 |
|
Lines 696-738
Link Here
|
696 |
*/ |
737 |
*/ |
697 |
public void run() { |
738 |
public void run() { |
698 |
|
739 |
|
699 |
/** |
|
|
700 |
* Information provider used to present the information. |
701 |
* |
702 |
* @since 3.0 |
703 |
*/ |
704 |
class InformationProvider implements IInformationProvider, IInformationProviderExtension2 { |
705 |
|
706 |
private IRegion fHoverRegion; |
707 |
private String fHoverInfo; |
708 |
private IInformationControlCreator fControlCreator; |
709 |
|
710 |
InformationProvider(IRegion hoverRegion, String hoverInfo, IInformationControlCreator controlCreator) { |
711 |
fHoverRegion= hoverRegion; |
712 |
fHoverInfo= hoverInfo; |
713 |
fControlCreator= controlCreator; |
714 |
} |
715 |
/* |
716 |
* @see org.eclipse.jface.text.information.IInformationProvider#getSubject(org.eclipse.jface.text.ITextViewer, int) |
717 |
*/ |
718 |
public IRegion getSubject(ITextViewer textViewer, int invocationOffset) { |
719 |
return fHoverRegion; |
720 |
} |
721 |
/* |
722 |
* @see org.eclipse.jface.text.information.IInformationProvider#getInformation(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion) |
723 |
*/ |
724 |
public String getInformation(ITextViewer textViewer, IRegion subject) { |
725 |
return fHoverInfo; |
726 |
} |
727 |
/* |
728 |
* @see org.eclipse.jface.text.information.IInformationProviderExtension2#getInformationPresenterControlCreator() |
729 |
* @since 3.0 |
730 |
*/ |
731 |
public IInformationControlCreator getInformationPresenterControlCreator() { |
732 |
return fControlCreator; |
733 |
} |
734 |
} |
735 |
|
736 |
ISourceViewer sourceViewer= getSourceViewer(); |
740 |
ISourceViewer sourceViewer= getSourceViewer(); |
737 |
if (sourceViewer == null) { |
741 |
if (sourceViewer == null) { |
738 |
fTextOperationAction.run(); |
742 |
fTextOperationAction.run(); |
Lines 754-765
Link Here
|
754 |
|
758 |
|
755 |
// does a text hover exist? |
759 |
// does a text hover exist? |
756 |
ITextHover textHover= textViewerExtension2.getCurrentTextHover(); |
760 |
ITextHover textHover= textViewerExtension2.getCurrentTextHover(); |
757 |
if (textHover == null) { |
761 |
if (textHover != null) { |
758 |
fTextOperationAction.run(); |
762 |
showStickyHover(sourceViewer, textViewerExtension2, textHover); |
759 |
return; |
763 |
return; |
760 |
} |
764 |
} |
|
|
765 |
|
766 |
if (sourceViewer instanceof SourceViewer) { |
767 |
IAnnotationHover annotationHover= ((SourceViewer) sourceViewer).getCurrentAnnotationHover(); |
768 |
if (annotationHover != null) { |
769 |
if (showStickyHover((SourceViewer) sourceViewer, annotationHover)) |
770 |
return; |
771 |
} |
772 |
} |
773 |
|
774 |
fTextOperationAction.run(); |
775 |
} |
776 |
|
777 |
private boolean showStickyHover(SourceViewer sourceViewer, IAnnotationHover annotationHover) { |
778 |
IVerticalRulerInfo info= getVerticalRuler(); |
779 |
int line= info.getLineOfLastMouseButtonActivity(); |
780 |
if (line == -1) { |
781 |
return false; |
782 |
} |
783 |
|
784 |
try { |
785 |
// get the text hover content |
786 |
|
787 |
// IRegion hoverRegion= annotationHover.getHoverRegion(sourceViewer, offset); |
788 |
IDocument document= sourceViewer.getDocument(); |
789 |
IRegion hoverRegion= document.getLineInformation(line); |
790 |
int offset= hoverRegion.getOffset(); |
791 |
|
792 |
String hoverInfo= annotationHover.getHoverInfo(sourceViewer, line); |
793 |
String contentType= TextUtilities.getContentType(document, IJavaPartitions.JAVA_PARTITIONING, offset, true); |
761 |
|
794 |
|
762 |
Point hoverEventLocation= textViewerExtension2.getHoverEventLocation(); |
795 |
IInformationControlCreator controlCreator= null; |
|
|
796 |
if (annotationHover instanceof IAnnotationHoverExtension) |
797 |
controlCreator= ((IAnnotationHoverExtension) annotationHover).getHoverControlCreator(); |
798 |
|
799 |
IInformationProvider informationProvider= new InformationProvider(hoverRegion, hoverInfo, controlCreator); |
800 |
|
801 |
|
802 |
fInformationPresenter.setOffset(offset); |
803 |
fInformationPresenter.setDocumentPartitioning(IJavaPartitions.JAVA_PARTITIONING); |
804 |
fInformationPresenter.setInformationProvider(informationProvider, contentType); |
805 |
fInformationPresenter.showInformation(); |
806 |
|
807 |
return true; |
808 |
|
809 |
} catch (BadLocationException e) { |
810 |
return false; |
811 |
} |
812 |
} |
813 |
|
814 |
private void showStickyHover(ISourceViewer sourceViewer, ITextViewerExtension2 textViewerExtension2, ITextHover textHover) { |
815 |
Point hoverEventLocation= textViewerExtension2.getHoverEventLocation(); |
763 |
int offset= computeOffsetAtLocation(sourceViewer, hoverEventLocation.x, hoverEventLocation.y); |
816 |
int offset= computeOffsetAtLocation(sourceViewer, hoverEventLocation.x, hoverEventLocation.y); |
764 |
if (offset == -1) { |
817 |
if (offset == -1) { |
765 |
fTextOperationAction.run(); |
818 |
fTextOperationAction.run(); |
Lines 789-795
Link Here
|
789 |
|
842 |
|
790 |
} catch (BadLocationException e) { |
843 |
} catch (BadLocationException e) { |
791 |
} |
844 |
} |
792 |
} |
845 |
} |
793 |
|
846 |
|
794 |
// modified version from TextViewer |
847 |
// modified version from TextViewer |
795 |
private int computeOffsetAtLocation(ITextViewer textViewer, int x, int y) { |
848 |
private int computeOffsetAtLocation(ITextViewer textViewer, int x, int y) { |