Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 275890 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ui/texteditor/AbstractTextEditor.java (-107 / +7 lines)
Lines 110-123 Link Here
110
110
111
import org.eclipse.jface.text.AbstractInformationControlManager;
111
import org.eclipse.jface.text.AbstractInformationControlManager;
112
import org.eclipse.jface.text.BadLocationException;
112
import org.eclipse.jface.text.BadLocationException;
113
import org.eclipse.jface.text.DefaultInformationControl;
114
import org.eclipse.jface.text.DefaultLineTracker;
113
import org.eclipse.jface.text.DefaultLineTracker;
115
import org.eclipse.jface.text.DocumentEvent;
114
import org.eclipse.jface.text.DocumentEvent;
116
import org.eclipse.jface.text.IDocument;
115
import org.eclipse.jface.text.IDocument;
117
import org.eclipse.jface.text.IDocumentListener;
116
import org.eclipse.jface.text.IDocumentListener;
118
import org.eclipse.jface.text.IFindReplaceTarget;
117
import org.eclipse.jface.text.IFindReplaceTarget;
119
import org.eclipse.jface.text.IFindReplaceTargetExtension;
118
import org.eclipse.jface.text.IFindReplaceTargetExtension;
120
import org.eclipse.jface.text.IInformationControl;
121
import org.eclipse.jface.text.IInformationControlCreator;
119
import org.eclipse.jface.text.IInformationControlCreator;
122
import org.eclipse.jface.text.IMarkRegionTarget;
120
import org.eclipse.jface.text.IMarkRegionTarget;
123
import org.eclipse.jface.text.IRegion;
121
import org.eclipse.jface.text.IRegion;
Lines 147-155 Link Here
147
import org.eclipse.jface.text.ITextViewerExtension8.EnrichMode;
145
import org.eclipse.jface.text.ITextViewerExtension8.EnrichMode;
148
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
146
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
149
import org.eclipse.jface.text.information.IInformationProvider;
147
import org.eclipse.jface.text.information.IInformationProvider;
150
import org.eclipse.jface.text.information.IInformationProviderExtension;
151
import org.eclipse.jface.text.information.IInformationProviderExtension2;
148
import org.eclipse.jface.text.information.IInformationProviderExtension2;
152
import org.eclipse.jface.text.information.InformationPresenter;
153
import org.eclipse.jface.text.link.LinkedModeModel;
149
import org.eclipse.jface.text.link.LinkedModeModel;
154
import org.eclipse.jface.text.link.LinkedPosition;
150
import org.eclipse.jface.text.link.LinkedPosition;
155
import org.eclipse.jface.text.quickassist.IQuickAssistAssistant;
151
import org.eclipse.jface.text.quickassist.IQuickAssistAssistant;
Lines 157-165 Link Here
157
import org.eclipse.jface.text.source.Annotation;
153
import org.eclipse.jface.text.source.Annotation;
158
import org.eclipse.jface.text.source.CompositeRuler;
154
import org.eclipse.jface.text.source.CompositeRuler;
159
import org.eclipse.jface.text.source.IAnnotationHover;
155
import org.eclipse.jface.text.source.IAnnotationHover;
160
import org.eclipse.jface.text.source.IAnnotationHoverExtension;
161
import org.eclipse.jface.text.source.IAnnotationModel;
156
import org.eclipse.jface.text.source.IAnnotationModel;
162
import org.eclipse.jface.text.source.ILineRange;
163
import org.eclipse.jface.text.source.ISourceViewer;
157
import org.eclipse.jface.text.source.ISourceViewer;
164
import org.eclipse.jface.text.source.ISourceViewerExtension3;
158
import org.eclipse.jface.text.source.ISourceViewerExtension3;
165
import org.eclipse.jface.text.source.ISourceViewerExtension4;
159
import org.eclipse.jface.text.source.ISourceViewerExtension4;
Lines 202-207 Link Here
202
import org.eclipse.ui.dialogs.PropertyDialogAction;
196
import org.eclipse.ui.dialogs.PropertyDialogAction;
203
import org.eclipse.ui.dnd.IDragAndDropService;
197
import org.eclipse.ui.dnd.IDragAndDropService;
204
import org.eclipse.ui.internal.texteditor.EditPosition;
198
import org.eclipse.ui.internal.texteditor.EditPosition;
199
import org.eclipse.ui.internal.texteditor.FocusedInformationPresenter;
205
import org.eclipse.ui.internal.texteditor.NLSUtility;
200
import org.eclipse.ui.internal.texteditor.NLSUtility;
206
import org.eclipse.ui.internal.texteditor.TextEditorPlugin;
201
import org.eclipse.ui.internal.texteditor.TextEditorPlugin;
207
import org.eclipse.ui.internal.texteditor.rulers.StringSetSerializer;
202
import org.eclipse.ui.internal.texteditor.rulers.StringSetSerializer;
Lines 1844-1894 Link Here
1844
1839
1845
1840
1846
	/**
1841
	/**
1847
	 * Information provider used to present focusable information shells.
1848
	 *
1849
	 * @since 3.3
1850
	 */
1851
	private static final class InformationProvider implements IInformationProvider, IInformationProviderExtension, IInformationProviderExtension2 {
1852
1853
		private IRegion fHoverRegion;
1854
		private Object fHoverInfo;
1855
		private IInformationControlCreator fControlCreator;
1856
1857
		InformationProvider(IRegion hoverRegion, Object hoverInfo, IInformationControlCreator controlCreator) {
1858
			fHoverRegion= hoverRegion;
1859
			fHoverInfo= hoverInfo;
1860
			fControlCreator= controlCreator;
1861
		}
1862
		/*
1863
		 * @see org.eclipse.jface.text.information.IInformationProvider#getSubject(org.eclipse.jface.text.ITextViewer, int)
1864
		 */
1865
		public IRegion getSubject(ITextViewer textViewer, int invocationOffset) {
1866
			return fHoverRegion;
1867
		}
1868
		/**
1869
		 * {@inheritDoc}
1870
		 *
1871
		 * @deprecated As of 2.1, replaced by {@link IInformationProviderExtension#getInformation2(ITextViewer, IRegion)}
1872
		 */
1873
		public String getInformation(ITextViewer textViewer, IRegion subject) {
1874
			return fHoverInfo == null ? null : fHoverInfo.toString();
1875
		}
1876
		/*
1877
		 * @see org.eclipse.jface.text.information.IInformationProviderExtension#getInformation2(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
1878
		 * @since 3.2
1879
		 */
1880
		public Object getInformation2(ITextViewer textViewer, IRegion subject) {
1881
			return fHoverInfo;
1882
		}
1883
		/*
1884
		 * @see org.eclipse.jface.text.information.IInformationProviderExtension2#getInformationPresenterControlCreator()
1885
		 */
1886
		public IInformationControlCreator getInformationPresenterControlCreator() {
1887
			return fControlCreator;
1888
		}
1889
	}
1890
1891
	/**
1892
	 * This action behaves in two different ways: If there is no current text
1842
	 * This action behaves in two different ways: If there is no current text
1893
	 * hover, the javadoc is displayed using information presenter. If there is
1843
	 * hover, the javadoc is displayed using information presenter. If there is
1894
	 * a current text hover, it is converted into a information presenter in
1844
	 * a current text hover, it is converted into a information presenter in
Lines 1943-1949 Link Here
1943
			if (sourceViewer instanceof ISourceViewerExtension3) {
1893
			if (sourceViewer instanceof ISourceViewerExtension3) {
1944
				// does an annotation hover exist?
1894
				// does an annotation hover exist?
1945
				IAnnotationHover annotationHover= ((ISourceViewerExtension3) sourceViewer).getCurrentAnnotationHover();
1895
				IAnnotationHover annotationHover= ((ISourceViewerExtension3) sourceViewer).getCurrentAnnotationHover();
1946
				if (annotationHover != null && makeAnnotationHoverFocusable(sourceViewer, annotationHover))
1896
				if (annotationHover != null && makeAnnotationHoverFocusable(annotationHover))
1947
					return;
1897
					return;
1948
			}
1898
			}
1949
1899
Lines 1976-1982 Link Here
1976
				if (textHover instanceof IInformationProviderExtension2) // this is conceptually wrong, but left here for backwards compatibility
1926
				if (textHover instanceof IInformationProviderExtension2) // this is conceptually wrong, but left here for backwards compatibility
1977
					controlCreator= ((IInformationProviderExtension2)textHover).getInformationPresenterControlCreator();
1927
					controlCreator= ((IInformationProviderExtension2)textHover).getInformationPresenterControlCreator();
1978
1928
1979
				IInformationProvider informationProvider= new InformationProvider(hoverRegion, hoverInfo, controlCreator);
1929
				IInformationProvider informationProvider= new FocusedInformationPresenter.InformationProvider(hoverRegion, hoverInfo, controlCreator);
1980
1930
1981
				fInformationPresenter.setOffset(offset);
1931
				fInformationPresenter.setOffset(offset);
1982
				fInformationPresenter.setAnchor(AbstractInformationControlManager.ANCHOR_BOTTOM);
1932
				fInformationPresenter.setAnchor(AbstractInformationControlManager.ANCHOR_BOTTOM);
Lines 1995-2049 Link Here
1995
		/**
1945
		/**
1996
		 * Tries to make an annotation hover focusable (or "sticky").
1946
		 * Tries to make an annotation hover focusable (or "sticky").
1997
		 *
1947
		 *
1998
		 * @param sourceViewer the source viewer to display the hover over
1999
		 * @param annotationHover the hover to make focusable
1948
		 * @param annotationHover the hover to make focusable
2000
		 * @return <code>true</code> if successful, <code>false</code> otherwise
1949
		 * @return <code>true</code> if successful, <code>false</code> otherwise
2001
		 */
1950
		 */
2002
		private boolean makeAnnotationHoverFocusable(ISourceViewer sourceViewer, IAnnotationHover annotationHover) {
1951
		private boolean makeAnnotationHoverFocusable(IAnnotationHover annotationHover) {
2003
			IVerticalRulerInfo info= getVerticalRuler();
1952
			IVerticalRulerInfo info= getVerticalRuler();
2004
			int line= info.getLineOfLastMouseButtonActivity();
1953
			int line= info.getLineOfLastMouseButtonActivity();
2005
			if (line == -1)
1954
			if (line == -1)
2006
				return false;
1955
				return false;
2007
1956
2008
			try {
1957
			return fInformationPresenter.openFocusedAnnotationHover(annotationHover, line);
2009
2010
				// compute the hover information
2011
				Object hoverInfo;
2012
				if (annotationHover instanceof IAnnotationHoverExtension) {
2013
					IAnnotationHoverExtension extension= (IAnnotationHoverExtension) annotationHover;
2014
					ILineRange hoverLineRange= extension.getHoverLineRange(sourceViewer, line);
2015
					if (hoverLineRange == null)
2016
						return false;
2017
					final int maxVisibleLines= Integer.MAX_VALUE; // allow any number of lines being displayed, as we support scrolling
2018
					hoverInfo= extension.getHoverInfo(sourceViewer, hoverLineRange, maxVisibleLines);
2019
				} else {
2020
					hoverInfo= annotationHover.getHoverInfo(sourceViewer, line);
2021
				}
2022
2023
				// hover region: the beginning of the concerned line to place the control right over the line
2024
				IDocument document= sourceViewer.getDocument();
2025
				int offset= document.getLineOffset(line);
2026
				String contentType= TextUtilities.getContentType(document, getSourceViewerConfiguration().getConfiguredDocumentPartitioning(getSourceViewer()), offset, true);
2027
2028
				IInformationControlCreator controlCreator= null;
2029
				if (annotationHover instanceof IInformationProviderExtension2) // this is undocumented, but left here for backwards compatibility
2030
					controlCreator= ((IInformationProviderExtension2) annotationHover).getInformationPresenterControlCreator();
2031
				else if (annotationHover instanceof IAnnotationHoverExtension)
2032
					controlCreator= ((IAnnotationHoverExtension) annotationHover).getHoverControlCreator();
2033
2034
				IInformationProvider informationProvider= new InformationProvider(new Region(offset, 0), hoverInfo, controlCreator);
2035
2036
				fInformationPresenter.setOffset(offset);
2037
				fInformationPresenter.setAnchor(AbstractInformationControlManager.ANCHOR_RIGHT);
2038
				fInformationPresenter.setMargins(4, 0); // AnnotationBarHoverManager sets (5,0), minus SourceViewer.GAP_SIZE_1
2039
				fInformationPresenter.setInformationProvider(informationProvider, contentType);
2040
				fInformationPresenter.showInformation();
2041
2042
				return true;
2043
2044
			} catch (BadLocationException e) {
2045
				return false;
2046
			}
2047
        }
1958
        }
2048
1959
2049
		// modified version from TextViewer
1960
		// modified version from TextViewer
Lines 2590-2596 Link Here
2590
	 * The information presenter.
2501
	 * The information presenter.
2591
	 * @since 3.3
2502
	 * @since 3.3
2592
	 */
2503
	 */
2593
	private InformationPresenter fInformationPresenter;
2504
	private FocusedInformationPresenter fInformationPresenter;
2594
2505
2595
	/**
2506
	/**
2596
	 * Tells whether this editor has been activated at least once.
2507
	 * Tells whether this editor has been activated at least once.
Lines 3477-3494 Link Here
3477
		if (ruler instanceof CompositeRuler)
3388
		if (ruler instanceof CompositeRuler)
3478
			updateContributedRulerColumns((CompositeRuler) ruler);
3389
			updateContributedRulerColumns((CompositeRuler) ruler);
3479
3390
3480
		IInformationControlCreator informationControlCreator= new IInformationControlCreator() {
3391
		fInformationPresenter= new FocusedInformationPresenter(getSourceViewer(), getSourceViewerConfiguration());
3481
			public IInformationControl createInformationControl(Shell shell) {
3482
				return new DefaultInformationControl(shell, true);
3483
			}
3484
		};
3485
3486
		fInformationPresenter= new InformationPresenter(informationControlCreator);
3487
		// sizes: see org.eclipse.jface.text.TextViewer.TEXT_HOVER_*_CHARS
3488
		fInformationPresenter.setSizeConstraints(100, 12, true, true);
3489
		fInformationPresenter.install(getSourceViewer());
3490
		fInformationPresenter.setDocumentPartitioning(getSourceViewerConfiguration().getConfiguredDocumentPartitioning(getSourceViewer()));
3491
3492
	}
3392
	}
3493
3393
3494
	/**
3394
	/**
(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 9-15 Link Here
9
Bundle-Localization: plugin
9
Bundle-Localization: plugin
10
Export-Package: 
10
Export-Package: 
11
 org.eclipse.ui.contentassist,
11
 org.eclipse.ui.contentassist,
12
 org.eclipse.ui.internal.texteditor;x-internal:=true; texteditor="split"; mandatory:="texteditor",
12
 org.eclipse.ui.internal.texteditor; texteditor="split"; mandatory:="texteditor"; x-friends:="org.eclipse.ui.editors",
13
 org.eclipse.ui.internal.texteditor.quickdiff;x-internal:=true,
13
 org.eclipse.ui.internal.texteditor.quickdiff;x-internal:=true,
14
 org.eclipse.ui.internal.texteditor.quickdiff.compare.equivalence;x-internal:=true,
14
 org.eclipse.ui.internal.texteditor.quickdiff.compare.equivalence;x-internal:=true,
15
 org.eclipse.ui.internal.texteditor.rulers;x-internal:=true,
15
 org.eclipse.ui.internal.texteditor.rulers;x-internal:=true,
(-)src/org/eclipse/ui/internal/texteditor/FocusedInformationPresenter.java (+159 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.texteditor;
12
13
import org.eclipse.swt.widgets.Shell;
14
15
import org.eclipse.jface.text.AbstractInformationControlManager;
16
import org.eclipse.jface.text.BadLocationException;
17
import org.eclipse.jface.text.DefaultInformationControl;
18
import org.eclipse.jface.text.IDocument;
19
import org.eclipse.jface.text.IInformationControl;
20
import org.eclipse.jface.text.IInformationControlCreator;
21
import org.eclipse.jface.text.IRegion;
22
import org.eclipse.jface.text.ITextViewer;
23
import org.eclipse.jface.text.Region;
24
import org.eclipse.jface.text.TextUtilities;
25
import org.eclipse.jface.text.information.IInformationProvider;
26
import org.eclipse.jface.text.information.IInformationProviderExtension;
27
import org.eclipse.jface.text.information.IInformationProviderExtension2;
28
import org.eclipse.jface.text.information.InformationPresenter;
29
import org.eclipse.jface.text.source.IAnnotationHover;
30
import org.eclipse.jface.text.source.IAnnotationHoverExtension;
31
import org.eclipse.jface.text.source.ILineRange;
32
import org.eclipse.jface.text.source.ISourceViewer;
33
import org.eclipse.jface.text.source.SourceViewerConfiguration;
34
35
/**
36
 * Information presenter used to present focused ("sticky") information shells.
37
 * 
38
 * @since 3.5
39
 */
40
public class FocusedInformationPresenter extends InformationPresenter {
41
42
	/**
43
	 * Information provider used to present focused information shells.
44
	 */
45
	public final static class InformationProvider implements IInformationProvider, IInformationProviderExtension, IInformationProviderExtension2 {
46
47
		private IRegion fHoverRegion;
48
		private Object fHoverInfo;
49
		private IInformationControlCreator fControlCreator;
50
51
		public InformationProvider(IRegion hoverRegion, Object hoverInfo, IInformationControlCreator controlCreator) {
52
			fHoverRegion= hoverRegion;
53
			fHoverInfo= hoverInfo;
54
			fControlCreator= controlCreator;
55
		}
56
		/*
57
		 * @see org.eclipse.jface.text.information.IInformationProvider#getSubject(org.eclipse.jface.text.ITextViewer, int)
58
		 */
59
		public IRegion getSubject(ITextViewer textViewer, int invocationOffset) {
60
			return fHoverRegion;
61
		}
62
		/**
63
		 * {@inheritDoc}
64
		 *
65
		 * @deprecated As of 2.1, replaced by {@link IInformationProviderExtension#getInformation2(ITextViewer, IRegion)}
66
		 */
67
		public String getInformation(ITextViewer textViewer, IRegion subject) {
68
			return fHoverInfo == null ? null : fHoverInfo.toString();
69
		}
70
		/*
71
		 * @see org.eclipse.jface.text.information.IInformationProviderExtension#getInformation2(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
72
		 * @since 3.2
73
		 */
74
		public Object getInformation2(ITextViewer textViewer, IRegion subject) {
75
			return fHoverInfo;
76
		}
77
		/*
78
		 * @see org.eclipse.jface.text.information.IInformationProviderExtension2#getInformationPresenterControlCreator()
79
		 */
80
		public IInformationControlCreator getInformationPresenterControlCreator() {
81
			return fControlCreator;
82
		}
83
	}
84
	
85
	/**
86
	 * The default information control creator.
87
	 */
88
	private static class DefaultInformationControlCreator implements IInformationControlCreator {
89
		public IInformationControl createInformationControl(Shell shell) {
90
			return new DefaultInformationControl(shell, true);
91
		}
92
	}
93
	
94
	
95
	private final ISourceViewer fSourceViewer;
96
	private final SourceViewerConfiguration fSourceViewerConfiguration;
97
98
	public FocusedInformationPresenter(ISourceViewer sourceViewer, SourceViewerConfiguration sourceViewerConfiguration) {
99
		super(new DefaultInformationControlCreator());
100
		fSourceViewer= sourceViewer;
101
		fSourceViewerConfiguration= sourceViewerConfiguration;
102
		
103
		// sizes: see org.eclipse.jface.text.TextViewer.TEXT_HOVER_*_CHARS
104
		setSizeConstraints(100, 12, true, true);
105
		install(sourceViewer);
106
		setDocumentPartitioning(sourceViewerConfiguration.getConfiguredDocumentPartitioning(sourceViewer));
107
	}
108
109
	/**
110
	 * Tries show a focused ("sticky") annotation hover.
111
	 *
112
	 * @param annotationHover the annotation hover to show
113
	 * @param line the line for which to show the hover
114
	 * @return <code>true</code> if successful, <code>false</code> otherwise
115
	 */
116
	public boolean openFocusedAnnotationHover(IAnnotationHover annotationHover, int line) {
117
		
118
		try {
119
			// compute the hover information
120
			Object hoverInfo;
121
			if (annotationHover instanceof IAnnotationHoverExtension) {
122
				IAnnotationHoverExtension extension= (IAnnotationHoverExtension) annotationHover;
123
				ILineRange hoverLineRange= extension.getHoverLineRange(fSourceViewer, line);
124
				if (hoverLineRange == null)
125
					return false;
126
				final int maxVisibleLines= Integer.MAX_VALUE; // allow any number of lines being displayed, as we support scrolling
127
				hoverInfo= extension.getHoverInfo(fSourceViewer, hoverLineRange, maxVisibleLines);
128
			} else {
129
				hoverInfo= annotationHover.getHoverInfo(fSourceViewer, line);
130
			}
131
132
			// hover region: the beginning of the concerned line to place the control right over the line
133
			IDocument document= fSourceViewer.getDocument();
134
			int offset= document.getLineOffset(line);
135
			String contentType= TextUtilities.getContentType(document, fSourceViewerConfiguration.getConfiguredDocumentPartitioning(fSourceViewer), offset, true);
136
137
			IInformationControlCreator controlCreator= null;
138
			if (annotationHover instanceof IInformationProviderExtension2) // this is undocumented, but left here for backwards compatibility
139
				controlCreator= ((IInformationProviderExtension2) annotationHover).getInformationPresenterControlCreator();
140
			else if (annotationHover instanceof IAnnotationHoverExtension)
141
				controlCreator= ((IAnnotationHoverExtension) annotationHover).getHoverControlCreator();
142
143
			IInformationProvider informationProvider= new InformationProvider(new Region(offset, 0), hoverInfo, controlCreator);
144
145
			setOffset(offset);
146
			setAnchor(AbstractInformationControlManager.ANCHOR_RIGHT);
147
			setMargins(4, 0); // AnnotationBarHoverManager sets (5,0), minus SourceViewer.GAP_SIZE_1
148
			setInformationProvider(informationProvider, contentType);
149
			showInformation();
150
151
			return true;
152
153
		} catch (BadLocationException e) {
154
			return false;
155
		}
156
	}
157
}
158
159

Return to bug 275890