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/AbstractDecoratedTextEditor.java (-20 / +3 lines)
Lines 126-131 Link Here
126
import org.eclipse.ui.internal.editors.text.RefreshEditorAction;
126
import org.eclipse.ui.internal.editors.text.RefreshEditorAction;
127
import org.eclipse.ui.internal.texteditor.AnnotationColumn;
127
import org.eclipse.ui.internal.texteditor.AnnotationColumn;
128
import org.eclipse.ui.internal.texteditor.BooleanPreferenceToggleAction;
128
import org.eclipse.ui.internal.texteditor.BooleanPreferenceToggleAction;
129
import org.eclipse.ui.internal.texteditor.FocusedInformationPresenter;
129
import org.eclipse.ui.internal.texteditor.LineNumberColumn;
130
import org.eclipse.ui.internal.texteditor.LineNumberColumn;
130
import org.eclipse.ui.internal.texteditor.TextChangeHover;
131
import org.eclipse.ui.internal.texteditor.TextChangeHover;
131
import org.eclipse.ui.keys.IBindingService;
132
import org.eclipse.ui.keys.IBindingService;
Lines 157-180 Link Here
157
public abstract class AbstractDecoratedTextEditor extends StatusTextEditor {
158
public abstract class AbstractDecoratedTextEditor extends StatusTextEditor {
158
159
159
	/**
160
	/**
160
	 * Command ID of the command to display a sticky ruler hover for the current caret location.
161
	 * Value <code>"org.eclipse.ui.edit.text.showChangeRulerInformation"</code>).
162
	 * 
163
	 * @since 3.5
164
	 */
165
	//TODO: move to ITextEditorActionDefinitionIds and make API
166
	private static final String SHOW_CHANGE_RULER_INFORMATION_ID= "org.eclipse.ui.edit.text.showChangeRulerInformation"; //$NON-NLS-1$
167
	
168
	/**
169
	 * Name of the action displaying a sticky ruler hover for the current caret location.
170
	 *
171
	 * Value: <code>"ShowChangeRulerInformation"</code>
172
	 * @since 3.5
173
	 */
174
	//TODO: move to ITextEditorActionConstants and make API
175
	private static final String SHOW_CHANGE_RULER_INFORMATION= "ShowChangeRulerInformation"; //$NON-NLS-1$
176
	
177
	/**
178
	 * Preference key for showing the line number ruler.
161
	 * Preference key for showing the line number ruler.
179
	 */
162
	 */
180
	private final static String LINE_NUMBER_RULER= AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER;
163
	private final static String LINE_NUMBER_RULER= AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER;
Lines 1252-1259 Link Here
1252
				showChangeRulerInformation();
1235
				showChangeRulerInformation();
1253
			}
1236
			}
1254
		};
1237
		};
1255
		action.setActionDefinitionId(SHOW_CHANGE_RULER_INFORMATION_ID);
1238
		action.setActionDefinitionId(ITextEditorActionDefinitionIds.SHOW_CHANGE_RULER_INFORMATION_ID);
1256
		setAction(SHOW_CHANGE_RULER_INFORMATION, action);
1239
		setAction(ITextEditorActionConstants.SHOW_CHANGE_RULER_INFORMATION, action);
1257
	}
1240
	}
1258
1241
1259
	/**
1242
	/**
(-)src/org/eclipse/ui/texteditor/FocusedInformationPresenter.java (-170 lines)
Removed 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.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
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
	 * The source viewer.
96
	 */
97
	private final ISourceViewer fSourceViewer;
98
	/**
99
	 * The source viewer configuration.
100
	 */
101
	private final SourceViewerConfiguration fSourceViewerConfiguration;
102
103
	/**
104
	 * Creates a new focused information presenter and installs it on the given source viewer
105
	 * 
106
	 * @param sourceViewer the source viewer
107
	 * @param sourceViewerConfiguration the viewer configuration
108
	 */
109
	public FocusedInformationPresenter(ISourceViewer sourceViewer, SourceViewerConfiguration sourceViewerConfiguration) {
110
		super(new DefaultInformationControlCreator());
111
		fSourceViewer= sourceViewer;
112
		fSourceViewerConfiguration= sourceViewerConfiguration;
113
		
114
		// sizes: see org.eclipse.jface.text.TextViewer.TEXT_HOVER_*_CHARS
115
		setSizeConstraints(100, 12, true, true);
116
		install(sourceViewer);
117
		setDocumentPartitioning(sourceViewerConfiguration.getConfiguredDocumentPartitioning(sourceViewer));
118
	}
119
120
	/**
121
	 * Tries to show a focused ("sticky") annotation hover.
122
	 *
123
	 * @param annotationHover the annotation hover to show
124
	 * @param line the line for which to show the hover
125
	 * @return <code>true</code> if successful, <code>false</code> otherwise
126
	 */
127
	public boolean openFocusedAnnotationHover(IAnnotationHover annotationHover, int line) {
128
		
129
		try {
130
			// compute the hover information
131
			Object hoverInfo;
132
			if (annotationHover instanceof IAnnotationHoverExtension) {
133
				IAnnotationHoverExtension extension= (IAnnotationHoverExtension) annotationHover;
134
				ILineRange hoverLineRange= extension.getHoverLineRange(fSourceViewer, line);
135
				if (hoverLineRange == null)
136
					return false;
137
				final int maxVisibleLines= Integer.MAX_VALUE; // allow any number of lines being displayed, as we support scrolling
138
				hoverInfo= extension.getHoverInfo(fSourceViewer, hoverLineRange, maxVisibleLines);
139
			} else {
140
				hoverInfo= annotationHover.getHoverInfo(fSourceViewer, line);
141
			}
142
143
			// hover region: the beginning of the concerned line to place the control right over the line
144
			IDocument document= fSourceViewer.getDocument();
145
			int offset= document.getLineOffset(line);
146
			String contentType= TextUtilities.getContentType(document, fSourceViewerConfiguration.getConfiguredDocumentPartitioning(fSourceViewer), offset, true);
147
148
			IInformationControlCreator controlCreator= null;
149
			if (annotationHover instanceof IInformationProviderExtension2) // this is undocumented, but left here for backwards compatibility
150
				controlCreator= ((IInformationProviderExtension2) annotationHover).getInformationPresenterControlCreator();
151
			else if (annotationHover instanceof IAnnotationHoverExtension)
152
				controlCreator= ((IAnnotationHoverExtension) annotationHover).getHoverControlCreator();
153
154
			IInformationProvider informationProvider= new InformationProvider(new Region(offset, 0), hoverInfo, controlCreator);
155
156
			setOffset(offset);
157
			setAnchor(AbstractInformationControlManager.ANCHOR_RIGHT);
158
			setMargins(4, 0); // AnnotationBarHoverManager sets (5,0), minus SourceViewer.GAP_SIZE_1
159
			setInformationProvider(informationProvider, contentType);
160
			showInformation();
161
162
			return true;
163
164
		} catch (BadLocationException e) {
165
			return false;
166
		}
167
	}
168
}
169
170
(-)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 (+165 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
	/**
99
	 * Creates a focused information presenter and installs it on the source viewer.
100
	 * 
101
	 * @param sourceViewer the source viewer
102
	 * @param sourceViewerConfiguration the configuration
103
	 */
104
	public FocusedInformationPresenter(ISourceViewer sourceViewer, SourceViewerConfiguration sourceViewerConfiguration) {
105
		super(new DefaultInformationControlCreator());
106
		fSourceViewer= sourceViewer;
107
		fSourceViewerConfiguration= sourceViewerConfiguration;
108
		
109
		// sizes: see org.eclipse.jface.text.TextViewer.TEXT_HOVER_*_CHARS
110
		setSizeConstraints(100, 12, true, true);
111
		install(sourceViewer);
112
		setDocumentPartitioning(sourceViewerConfiguration.getConfiguredDocumentPartitioning(sourceViewer));
113
	}
114
115
	/**
116
	 * Tries show a focused ("sticky") annotation hover.
117
	 *
118
	 * @param annotationHover the annotation hover to show
119
	 * @param line the line for which to show the hover
120
	 * @return <code>true</code> if successful, <code>false</code> otherwise
121
	 */
122
	public boolean openFocusedAnnotationHover(IAnnotationHover annotationHover, int line) {
123
		
124
		try {
125
			// compute the hover information
126
			Object hoverInfo;
127
			if (annotationHover instanceof IAnnotationHoverExtension) {
128
				IAnnotationHoverExtension extension= (IAnnotationHoverExtension) annotationHover;
129
				ILineRange hoverLineRange= extension.getHoverLineRange(fSourceViewer, line);
130
				if (hoverLineRange == null)
131
					return false;
132
				final int maxVisibleLines= Integer.MAX_VALUE; // allow any number of lines being displayed, as we support scrolling
133
				hoverInfo= extension.getHoverInfo(fSourceViewer, hoverLineRange, maxVisibleLines);
134
			} else {
135
				hoverInfo= annotationHover.getHoverInfo(fSourceViewer, line);
136
			}
137
138
			// hover region: the beginning of the concerned line to place the control right over the line
139
			IDocument document= fSourceViewer.getDocument();
140
			int offset= document.getLineOffset(line);
141
			String contentType= TextUtilities.getContentType(document, fSourceViewerConfiguration.getConfiguredDocumentPartitioning(fSourceViewer), offset, true);
142
143
			IInformationControlCreator controlCreator= null;
144
			if (annotationHover instanceof IInformationProviderExtension2) // this is undocumented, but left here for backwards compatibility
145
				controlCreator= ((IInformationProviderExtension2) annotationHover).getInformationPresenterControlCreator();
146
			else if (annotationHover instanceof IAnnotationHoverExtension)
147
				controlCreator= ((IAnnotationHoverExtension) annotationHover).getHoverControlCreator();
148
149
			IInformationProvider informationProvider= new InformationProvider(new Region(offset, 0), hoverInfo, controlCreator);
150
151
			setOffset(offset);
152
			setAnchor(AbstractInformationControlManager.ANCHOR_RIGHT);
153
			setMargins(4, 0); // AnnotationBarHoverManager sets (5,0), minus SourceViewer.GAP_SIZE_1
154
			setInformationProvider(informationProvider, contentType);
155
			showInformation();
156
157
			return true;
158
159
		} catch (BadLocationException e) {
160
			return false;
161
		}
162
	}
163
}
164
165
(-)src/org/eclipse/ui/texteditor/AbstractTextEditor.java (-121 / +36 lines)
Lines 109-122 Link Here
109
109
110
import org.eclipse.jface.text.AbstractInformationControlManager;
110
import org.eclipse.jface.text.AbstractInformationControlManager;
111
import org.eclipse.jface.text.BadLocationException;
111
import org.eclipse.jface.text.BadLocationException;
112
import org.eclipse.jface.text.DefaultInformationControl;
113
import org.eclipse.jface.text.DefaultLineTracker;
112
import org.eclipse.jface.text.DefaultLineTracker;
114
import org.eclipse.jface.text.DocumentEvent;
113
import org.eclipse.jface.text.DocumentEvent;
115
import org.eclipse.jface.text.IDocument;
114
import org.eclipse.jface.text.IDocument;
116
import org.eclipse.jface.text.IDocumentListener;
115
import org.eclipse.jface.text.IDocumentListener;
117
import org.eclipse.jface.text.IFindReplaceTarget;
116
import org.eclipse.jface.text.IFindReplaceTarget;
118
import org.eclipse.jface.text.IFindReplaceTargetExtension;
117
import org.eclipse.jface.text.IFindReplaceTargetExtension;
119
import org.eclipse.jface.text.IInformationControl;
120
import org.eclipse.jface.text.IInformationControlCreator;
118
import org.eclipse.jface.text.IInformationControlCreator;
121
import org.eclipse.jface.text.IMarkRegionTarget;
119
import org.eclipse.jface.text.IMarkRegionTarget;
122
import org.eclipse.jface.text.IRegion;
120
import org.eclipse.jface.text.IRegion;
Lines 130-136 Link Here
130
import org.eclipse.jface.text.ITextViewer;
128
import org.eclipse.jface.text.ITextViewer;
131
import org.eclipse.jface.text.ITextViewerExtension;
129
import org.eclipse.jface.text.ITextViewerExtension;
132
import org.eclipse.jface.text.ITextViewerExtension2;
130
import org.eclipse.jface.text.ITextViewerExtension2;
133
import org.eclipse.jface.text.ITextViewerExtension4;
134
import org.eclipse.jface.text.ITextViewerExtension5;
131
import org.eclipse.jface.text.ITextViewerExtension5;
135
import org.eclipse.jface.text.ITextViewerExtension6;
132
import org.eclipse.jface.text.ITextViewerExtension6;
136
import org.eclipse.jface.text.ITextViewerExtension7;
133
import org.eclipse.jface.text.ITextViewerExtension7;
Lines 146-154 Link Here
146
import org.eclipse.jface.text.ITextViewerExtension8.EnrichMode;
143
import org.eclipse.jface.text.ITextViewerExtension8.EnrichMode;
147
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
144
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
148
import org.eclipse.jface.text.information.IInformationProvider;
145
import org.eclipse.jface.text.information.IInformationProvider;
149
import org.eclipse.jface.text.information.IInformationProviderExtension;
150
import org.eclipse.jface.text.information.IInformationProviderExtension2;
146
import org.eclipse.jface.text.information.IInformationProviderExtension2;
151
import org.eclipse.jface.text.information.InformationPresenter;
152
import org.eclipse.jface.text.link.LinkedModeModel;
147
import org.eclipse.jface.text.link.LinkedModeModel;
153
import org.eclipse.jface.text.link.LinkedPosition;
148
import org.eclipse.jface.text.link.LinkedPosition;
154
import org.eclipse.jface.text.quickassist.IQuickAssistAssistant;
149
import org.eclipse.jface.text.quickassist.IQuickAssistAssistant;
Lines 156-164 Link Here
156
import org.eclipse.jface.text.source.Annotation;
151
import org.eclipse.jface.text.source.Annotation;
157
import org.eclipse.jface.text.source.CompositeRuler;
152
import org.eclipse.jface.text.source.CompositeRuler;
158
import org.eclipse.jface.text.source.IAnnotationHover;
153
import org.eclipse.jface.text.source.IAnnotationHover;
159
import org.eclipse.jface.text.source.IAnnotationHoverExtension;
160
import org.eclipse.jface.text.source.IAnnotationModel;
154
import org.eclipse.jface.text.source.IAnnotationModel;
161
import org.eclipse.jface.text.source.ILineRange;
162
import org.eclipse.jface.text.source.ISourceViewer;
155
import org.eclipse.jface.text.source.ISourceViewer;
163
import org.eclipse.jface.text.source.ISourceViewerExtension3;
156
import org.eclipse.jface.text.source.ISourceViewerExtension3;
164
import org.eclipse.jface.text.source.ISourceViewerExtension4;
157
import org.eclipse.jface.text.source.ISourceViewerExtension4;
Lines 201-206 Link Here
201
import org.eclipse.ui.dialogs.PropertyDialogAction;
194
import org.eclipse.ui.dialogs.PropertyDialogAction;
202
import org.eclipse.ui.dnd.IDragAndDropService;
195
import org.eclipse.ui.dnd.IDragAndDropService;
203
import org.eclipse.ui.internal.texteditor.EditPosition;
196
import org.eclipse.ui.internal.texteditor.EditPosition;
197
import org.eclipse.ui.internal.texteditor.FocusedInformationPresenter;
204
import org.eclipse.ui.internal.texteditor.NLSUtility;
198
import org.eclipse.ui.internal.texteditor.NLSUtility;
205
import org.eclipse.ui.internal.texteditor.TextEditorPlugin;
199
import org.eclipse.ui.internal.texteditor.TextEditorPlugin;
206
import org.eclipse.ui.internal.texteditor.rulers.StringSetSerializer;
200
import org.eclipse.ui.internal.texteditor.rulers.StringSetSerializer;
Lines 1840-1890 Link Here
1840
1834
1841
1835
1842
	/**
1836
	/**
1843
	 * Information provider used to present focusable information shells.
1844
	 *
1845
	 * @since 3.3
1846
	 */
1847
	private static final class InformationProvider implements IInformationProvider, IInformationProviderExtension, IInformationProviderExtension2 {
1848
1849
		private IRegion fHoverRegion;
1850
		private Object fHoverInfo;
1851
		private IInformationControlCreator fControlCreator;
1852
1853
		InformationProvider(IRegion hoverRegion, Object hoverInfo, IInformationControlCreator controlCreator) {
1854
			fHoverRegion= hoverRegion;
1855
			fHoverInfo= hoverInfo;
1856
			fControlCreator= controlCreator;
1857
		}
1858
		/*
1859
		 * @see org.eclipse.jface.text.information.IInformationProvider#getSubject(org.eclipse.jface.text.ITextViewer, int)
1860
		 */
1861
		public IRegion getSubject(ITextViewer textViewer, int invocationOffset) {
1862
			return fHoverRegion;
1863
		}
1864
		/**
1865
		 * {@inheritDoc}
1866
		 *
1867
		 * @deprecated As of 2.1, replaced by {@link IInformationProviderExtension#getInformation2(ITextViewer, IRegion)}
1868
		 */
1869
		public String getInformation(ITextViewer textViewer, IRegion subject) {
1870
			return fHoverInfo == null ? null : fHoverInfo.toString();
1871
		}
1872
		/*
1873
		 * @see org.eclipse.jface.text.information.IInformationProviderExtension#getInformation2(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
1874
		 * @since 3.2
1875
		 */
1876
		public Object getInformation2(ITextViewer textViewer, IRegion subject) {
1877
			return fHoverInfo;
1878
		}
1879
		/*
1880
		 * @see org.eclipse.jface.text.information.IInformationProviderExtension2#getInformationPresenterControlCreator()
1881
		 */
1882
		public IInformationControlCreator getInformationPresenterControlCreator() {
1883
			return fControlCreator;
1884
		}
1885
	}
1886
1887
	/**
1888
	 * This action behaves in two different ways: If there is no current text
1837
	 * This action behaves in two different ways: If there is no current text
1889
	 * hover, the javadoc is displayed using information presenter. If there is
1838
	 * hover, the javadoc is displayed using information presenter. If there is
1890
	 * a current text hover, it is converted into a information presenter in
1839
	 * a current text hover, it is converted into a information presenter in
Lines 1923-1933 Link Here
1923
				return;
1872
				return;
1924
			}
1873
			}
1925
1874
1926
			if (sourceViewer instanceof ITextViewerExtension4)  {
1875
//			if (sourceViewer instanceof ITextViewerExtension4)  {
1927
				ITextViewerExtension4 extension4= (ITextViewerExtension4) sourceViewer;
1876
//				ITextViewerExtension4 extension4= (ITextViewerExtension4) sourceViewer;
1928
				if (extension4.moveFocusToWidgetToken())
1877
//				if (extension4.moveFocusToWidgetToken())
1929
					return;
1878
//					return;
1930
			}
1879
//			}
1931
1880
1932
			if (sourceViewer instanceof ITextViewerExtension2) {
1881
			if (sourceViewer instanceof ITextViewerExtension2) {
1933
				// does a text hover exist?
1882
				// does a text hover exist?
Lines 1939-1945 Link Here
1939
			if (sourceViewer instanceof ISourceViewerExtension3) {
1888
			if (sourceViewer instanceof ISourceViewerExtension3) {
1940
				// does an annotation hover exist?
1889
				// does an annotation hover exist?
1941
				IAnnotationHover annotationHover= ((ISourceViewerExtension3) sourceViewer).getCurrentAnnotationHover();
1890
				IAnnotationHover annotationHover= ((ISourceViewerExtension3) sourceViewer).getCurrentAnnotationHover();
1942
				if (annotationHover != null && makeAnnotationHoverFocusable(sourceViewer, annotationHover))
1891
				if (annotationHover != null && makeAnnotationHoverFocusable(annotationHover))
1943
					return;
1892
					return;
1944
			}
1893
			}
1945
1894
Lines 1972-1985 Link Here
1972
				if (textHover instanceof IInformationProviderExtension2) // this is conceptually wrong, but left here for backwards compatibility
1921
				if (textHover instanceof IInformationProviderExtension2) // this is conceptually wrong, but left here for backwards compatibility
1973
					controlCreator= ((IInformationProviderExtension2)textHover).getInformationPresenterControlCreator();
1922
					controlCreator= ((IInformationProviderExtension2)textHover).getInformationPresenterControlCreator();
1974
1923
1975
				IInformationProvider informationProvider= new InformationProvider(hoverRegion, hoverInfo, controlCreator);
1924
				IInformationProvider informationProvider= new FocusedInformationPresenter.InformationProvider(hoverRegion, hoverInfo, controlCreator);
1976
1925
1977
				fInformationPresenter.setOffset(offset);
1926
				FocusedInformationPresenter informationPresenter= getInformationPresenter();
1978
				fInformationPresenter.setAnchor(AbstractInformationControlManager.ANCHOR_BOTTOM);
1927
				informationPresenter.setOffset(offset);
1979
				fInformationPresenter.setMargins(6, 6); // default values from AbstractInformationControlManager
1928
				informationPresenter.setAnchor(AbstractInformationControlManager.ANCHOR_BOTTOM);
1929
				informationPresenter.setMargins(6, 6); // default values from AbstractInformationControlManager
1980
				String contentType= TextUtilities.getContentType(sourceViewer.getDocument(), getSourceViewerConfiguration().getConfiguredDocumentPartitioning(getSourceViewer()), offset, true);
1930
				String contentType= TextUtilities.getContentType(sourceViewer.getDocument(), getSourceViewerConfiguration().getConfiguredDocumentPartitioning(getSourceViewer()), offset, true);
1981
				fInformationPresenter.setInformationProvider(informationProvider, contentType);
1931
				informationPresenter.setInformationProvider(informationProvider, contentType);
1982
				fInformationPresenter.showInformation();
1932
				informationPresenter.showInformation();
1983
1933
1984
				return true;
1934
				return true;
1985
1935
Lines 1991-2046 Link Here
1991
		/**
1941
		/**
1992
		 * Tries to make an annotation hover focusable (or "sticky").
1942
		 * Tries to make an annotation hover focusable (or "sticky").
1993
		 *
1943
		 *
1994
		 * @param sourceViewer the source viewer to display the hover over
1995
		 * @param annotationHover the hover to make focusable
1944
		 * @param annotationHover the hover to make focusable
1996
		 * @return <code>true</code> if successful, <code>false</code> otherwise
1945
		 * @return <code>true</code> if successful, <code>false</code> otherwise
1997
		 */
1946
		 */
1998
		private boolean makeAnnotationHoverFocusable(ISourceViewer sourceViewer, IAnnotationHover annotationHover) {
1947
		private boolean makeAnnotationHoverFocusable(IAnnotationHover annotationHover) {
1999
			IVerticalRulerInfo info= getVerticalRuler();
1948
			IVerticalRulerInfo info= getVerticalRuler();
2000
			int line= info.getLineOfLastMouseButtonActivity();
1949
			int line= info.getLineOfLastMouseButtonActivity();
2001
			if (line == -1)
1950
			if (line == -1)
2002
				return false;
1951
				return false;
2003
1952
2004
			try {
1953
			return getInformationPresenter().openFocusedAnnotationHover(annotationHover, line);
2005
2006
				// compute the hover information
2007
				Object hoverInfo;
2008
				if (annotationHover instanceof IAnnotationHoverExtension) {
2009
					IAnnotationHoverExtension extension= (IAnnotationHoverExtension) annotationHover;
2010
					ILineRange hoverLineRange= extension.getHoverLineRange(sourceViewer, line);
2011
					if (hoverLineRange == null)
2012
						return false;
2013
					final int maxVisibleLines= Integer.MAX_VALUE; // allow any number of lines being displayed, as we support scrolling
2014
					hoverInfo= extension.getHoverInfo(sourceViewer, hoverLineRange, maxVisibleLines);
2015
				} else {
2016
					hoverInfo= annotationHover.getHoverInfo(sourceViewer, line);
2017
				}
2018
2019
				// hover region: the beginning of the concerned line to place the control right over the line
2020
				IDocument document= sourceViewer.getDocument();
2021
				int offset= document.getLineOffset(line);
2022
				String contentType= TextUtilities.getContentType(document, getSourceViewerConfiguration().getConfiguredDocumentPartitioning(getSourceViewer()), offset, true);
2023
2024
				IInformationControlCreator controlCreator= null;
2025
				if (annotationHover instanceof IInformationProviderExtension2) // this is undocumented, but left here for backwards compatibility
2026
					controlCreator= ((IInformationProviderExtension2) annotationHover).getInformationPresenterControlCreator();
2027
				else if (annotationHover instanceof IAnnotationHoverExtension)
2028
					controlCreator= ((IAnnotationHoverExtension) annotationHover).getHoverControlCreator();
2029
2030
				IInformationProvider informationProvider= new InformationProvider(new Region(offset, 0), hoverInfo, controlCreator);
2031
2032
				fInformationPresenter.setOffset(offset);
2033
				fInformationPresenter.setAnchor(AbstractInformationControlManager.ANCHOR_RIGHT);
2034
				fInformationPresenter.setMargins(4, 0); // AnnotationBarHoverManager sets (5,0), minus SourceViewer.GAP_SIZE_1
2035
				fInformationPresenter.setInformationProvider(informationProvider, contentType);
2036
				fInformationPresenter.showInformation();
2037
2038
				return true;
2039
2040
			} catch (BadLocationException e) {
2041
				return false;
2042
			}
2043
        }
1954
        }
1955
		
1956
		/**
1957
		 * Returns the information presenter (creates it if necessary).
1958
		 * 
1959
		 * @return the information presenter
1960
		 * @since 3.6
1961
		 */
1962
		private FocusedInformationPresenter getInformationPresenter() {
1963
			if (fInformationPresenter == null) {
1964
				fInformationPresenter= new FocusedInformationPresenter(getSourceViewer(), getSourceViewerConfiguration());
1965
			}
1966
			return fInformationPresenter;
1967
		}
2044
1968
2045
		// modified version from TextViewer
1969
		// modified version from TextViewer
2046
		private int computeOffsetAtLocation(ITextViewer textViewer, int x, int y) {
1970
		private int computeOffsetAtLocation(ITextViewer textViewer, int x, int y) {
Lines 2066-2072 Link Here
2066
			} catch (IllegalArgumentException e) {
1990
			} catch (IllegalArgumentException e) {
2067
				return -1;
1991
				return -1;
2068
			}
1992
			}
2069
2070
		}
1993
		}
2071
	}
1994
	}
2072
1995
Lines 2583-2592 Link Here
2583
	 */
2506
	 */
2584
	private Object fTextDragAndDropToken;
2507
	private Object fTextDragAndDropToken;
2585
	/**
2508
	/**
2586
	 * The information presenter.
2509
	 * The information presenter, may be <code>null</code>.
2587
	 * @since 3.3
2510
	 * @since 3.3
2588
	 */
2511
	 */
2589
	private InformationPresenter fInformationPresenter;
2512
	private FocusedInformationPresenter fInformationPresenter;
2590
2513
2591
	/**
2514
	/**
2592
	 * Tells whether this editor has been activated at least once.
2515
	 * Tells whether this editor has been activated at least once.
Lines 3472-3490 Link Here
3472
		IVerticalRuler ruler= getVerticalRuler();
3395
		IVerticalRuler ruler= getVerticalRuler();
3473
		if (ruler instanceof CompositeRuler)
3396
		if (ruler instanceof CompositeRuler)
3474
			updateContributedRulerColumns((CompositeRuler) ruler);
3397
			updateContributedRulerColumns((CompositeRuler) ruler);
3475
3476
		IInformationControlCreator informationControlCreator= new IInformationControlCreator() {
3477
			public IInformationControl createInformationControl(Shell shell) {
3478
				return new DefaultInformationControl(shell, true);
3479
			}
3480
		};
3481
3482
		fInformationPresenter= new InformationPresenter(informationControlCreator);
3483
		// sizes: see org.eclipse.jface.text.TextViewer.TEXT_HOVER_*_CHARS
3484
		fInformationPresenter.setSizeConstraints(100, 12, true, true);
3485
		fInformationPresenter.install(getSourceViewer());
3486
		fInformationPresenter.setDocumentPartitioning(getSourceViewerConfiguration().getConfiguredDocumentPartitioning(getSourceViewer()));
3487
3488
	}
3398
	}
3489
3399
3490
	/**
3400
	/**
Lines 4406-4411 Link Here
4406
			fKeyBindingSupportForQuickAssistant.dispose();
4316
			fKeyBindingSupportForQuickAssistant.dispose();
4407
			fKeyBindingSupportForQuickAssistant= null;
4317
			fKeyBindingSupportForQuickAssistant= null;
4408
		}
4318
		}
4319
		
4320
		if (fInformationPresenter != null) {
4321
			fInformationPresenter.uninstall();
4322
			fInformationPresenter= null;
4323
		}
4409
4324
4410
		super.dispose();
4325
		super.dispose();
4411
	}
4326
	}
(-)src/org/eclipse/ui/texteditor/ITextEditorActionConstants.java (+8 lines)
Lines 672-675 Link Here
672
	 * @since 3.5
672
	 * @since 3.5
673
	 */
673
	 */
674
	String BLOCK_SELECTION_MODE= "BlockSelectionMode"; //$NON-NLS-1$
674
	String BLOCK_SELECTION_MODE= "BlockSelectionMode"; //$NON-NLS-1$
675
676
	/**
677
	 * Name of the action displaying a sticky ruler hover for the current caret location.
678
	 *
679
	 * Value: <code>"ShowChangeRulerInformation"</code>
680
	 * @since 3.6
681
	 */
682
	public static final String SHOW_CHANGE_RULER_INFORMATION= "ShowChangeRulerInformation"; //$NON-NLS-1$
675
}
683
}
(-)src/org/eclipse/ui/texteditor/ITextEditorActionDefinitionIds.java (+8 lines)
Lines 577-580 Link Here
577
	 * @since 3.5
577
	 * @since 3.5
578
	 */
578
	 */
579
	String BLOCK_SELECTION_MODE= "org.eclipse.ui.edit.text.toggleBlockSelectionMode"; //$NON-NLS-1$
579
	String BLOCK_SELECTION_MODE= "org.eclipse.ui.edit.text.toggleBlockSelectionMode"; //$NON-NLS-1$
580
581
	/**
582
	 * Command ID of the command to display a sticky ruler hover for the current caret location.
583
	 * Value <code>"org.eclipse.ui.edit.text.showChangeRulerInformation"</code>.
584
	 * 
585
	 * @since 3.6
586
	 */
587
	public static final String SHOW_CHANGE_RULER_INFORMATION_ID= "org.eclipse.ui.edit.text.showChangeRulerInformation"; //$NON-NLS-1$
580
}
588
}

Return to bug 275890