|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2002, 2008 QNX Software Systems and others. |
2 |
* Copyright (c) 2002, 2009 QNX Software Systems 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 8-24
Link Here
|
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* QNX Software Systems - Initial API and implementation |
9 |
* QNX Software Systems - Initial API and implementation |
| 10 |
* Anton Leherbauer (Wind River Systems) |
10 |
* Anton Leherbauer (Wind River Systems) |
|
|
11 |
* Ericsson - Fix improper hover order (Bug 294812) |
| 11 |
*******************************************************************************/ |
12 |
*******************************************************************************/ |
| 12 |
|
13 |
|
| 13 |
package org.eclipse.cdt.internal.ui.text.c.hover; |
14 |
package org.eclipse.cdt.internal.ui.text.c.hover; |
| 14 |
|
15 |
|
| 15 |
import java.util.ArrayList; |
16 |
import java.util.ArrayList; |
| 16 |
import java.util.Iterator; |
|
|
| 17 |
import java.util.List; |
17 |
import java.util.List; |
| 18 |
|
18 |
|
| 19 |
import org.eclipse.cdt.ui.CUIPlugin; |
|
|
| 20 |
import org.eclipse.cdt.ui.PreferenceConstants; |
| 21 |
import org.eclipse.cdt.ui.text.c.hover.ICEditorTextHover; |
| 22 |
import org.eclipse.jface.text.IInformationControlCreator; |
19 |
import org.eclipse.jface.text.IInformationControlCreator; |
| 23 |
import org.eclipse.jface.text.IRegion; |
20 |
import org.eclipse.jface.text.IRegion; |
| 24 |
import org.eclipse.jface.text.ITextHover; |
21 |
import org.eclipse.jface.text.ITextHover; |
|
Lines 28-35
Link Here
|
| 28 |
import org.eclipse.jface.text.information.IInformationProviderExtension2; |
25 |
import org.eclipse.jface.text.information.IInformationProviderExtension2; |
| 29 |
import org.eclipse.ui.IEditorPart; |
26 |
import org.eclipse.ui.IEditorPart; |
| 30 |
|
27 |
|
|
|
28 |
import org.eclipse.cdt.ui.CUIPlugin; |
| 29 |
import org.eclipse.cdt.ui.PreferenceConstants; |
| 30 |
import org.eclipse.cdt.ui.text.c.hover.ICEditorTextHover; |
| 31 |
|
| 31 |
/** |
32 |
/** |
| 32 |
* BestMatchHover |
33 |
* BestMatchHover. |
|
|
34 |
* This is not a real hover, but instead, it is always the first hover used |
| 35 |
* and it will choose the best of the real hovers. To choose the best hover, |
| 36 |
* we simply find the first hover that returns some text. This implies |
| 37 |
* that the order of hovers is important and must be preserved. (Bug 294812) |
| 33 |
*/ |
38 |
*/ |
| 34 |
public class BestMatchHover extends AbstractCEditorTextHover { |
39 |
public class BestMatchHover extends AbstractCEditorTextHover { |
| 35 |
|
40 |
|
|
Lines 59-83
Link Here
|
| 59 |
CEditorTextHoverDescriptor[] hoverDescs= CUIPlugin.getDefault().getCEditorTextHoverDescriptors(); |
64 |
CEditorTextHoverDescriptor[] hoverDescs= CUIPlugin.getDefault().getCEditorTextHoverDescriptors(); |
| 60 |
for (int i= 0; i < hoverDescs.length; i++) { |
65 |
for (int i= 0; i < hoverDescs.length; i++) { |
| 61 |
// ensure that we don't add ourselves to the list |
66 |
// ensure that we don't add ourselves to the list |
| 62 |
if (!PreferenceConstants.ID_BESTMATCH_HOVER.equals(hoverDescs[i].getId())) |
67 |
if (!PreferenceConstants.ID_BESTMATCH_HOVER.equals(hoverDescs[i].getId())) { |
| 63 |
fTextHoverSpecifications.add(hoverDescs[i]); |
68 |
fTextHoverSpecifications.add(hoverDescs[i]); |
|
|
69 |
// add place-holder for hover instance |
| 70 |
fInstantiatedTextHovers.add(null); |
| 71 |
} |
| 64 |
} |
72 |
} |
| 65 |
} |
73 |
} |
| 66 |
|
74 |
|
| 67 |
private void checkTextHovers() { |
75 |
private void checkTextHovers() { |
| 68 |
if (fTextHoverSpecifications.size() == 0) |
76 |
if (fTextHoverSpecifications == null) |
| 69 |
return; |
77 |
return; |
| 70 |
|
78 |
|
| 71 |
for (Iterator<CEditorTextHoverDescriptor> iterator= new ArrayList<CEditorTextHoverDescriptor>(fTextHoverSpecifications).iterator(); iterator.hasNext(); ) { |
79 |
boolean allCreated = true; |
| 72 |
CEditorTextHoverDescriptor spec= iterator.next(); |
80 |
for (int i= 0; i < fTextHoverSpecifications.size(); ++i) { |
| 73 |
|
81 |
CEditorTextHoverDescriptor spec= fTextHoverSpecifications.get(i); |
|
|
82 |
if (spec == null) continue; |
| 83 |
|
| 74 |
ICEditorTextHover hover= spec.createTextHover(); |
84 |
ICEditorTextHover hover= spec.createTextHover(); |
| 75 |
if (hover != null) { |
85 |
if (hover != null) { |
| 76 |
hover.setEditor(getEditor()); |
86 |
hover.setEditor(getEditor()); |
| 77 |
addTextHover(hover); |
87 |
// remember instance and mark as created |
| 78 |
fTextHoverSpecifications.remove(spec); |
88 |
fInstantiatedTextHovers.set(i, hover); |
|
|
89 |
fTextHoverSpecifications.set(i, null); |
| 90 |
} else { |
| 91 |
allCreated = false; |
| 79 |
} |
92 |
} |
| 80 |
} |
93 |
} |
|
|
94 |
|
| 95 |
if (allCreated) { |
| 96 |
fTextHoverSpecifications = null; |
| 97 |
} |
| 81 |
} |
98 |
} |
| 82 |
|
99 |
|
| 83 |
protected void addTextHover(ITextHover hover) { |
100 |
protected void addTextHover(ITextHover hover) { |
|
Lines 98-105
Link Here
|
| 98 |
if (fInstantiatedTextHovers == null) |
115 |
if (fInstantiatedTextHovers == null) |
| 99 |
return null; |
116 |
return null; |
| 100 |
|
117 |
|
| 101 |
for (Iterator<ITextHover> iterator= fInstantiatedTextHovers.iterator(); iterator.hasNext(); ) { |
118 |
for (ITextHover hover : fInstantiatedTextHovers) { |
| 102 |
ITextHover hover= iterator.next(); |
119 |
if (hover == null) continue; |
| 103 |
|
120 |
|
| 104 |
String s= hover.getHoverInfo(textViewer, hoverRegion); |
121 |
String s= hover.getHoverInfo(textViewer, hoverRegion); |
| 105 |
if (s != null && s.trim().length() > 0) { |
122 |
if (s != null && s.trim().length() > 0) { |
|
Lines 124-132
Link Here
|
| 124 |
if (fInstantiatedTextHovers == null) |
141 |
if (fInstantiatedTextHovers == null) |
| 125 |
return null; |
142 |
return null; |
| 126 |
|
143 |
|
| 127 |
for (Iterator<ITextHover> iterator= fInstantiatedTextHovers.iterator(); iterator.hasNext(); ) { |
144 |
for (ITextHover hover : fInstantiatedTextHovers) { |
| 128 |
ITextHover hover= iterator.next(); |
145 |
if (hover == null) continue; |
| 129 |
|
146 |
|
| 130 |
if (hover instanceof ITextHoverExtension2) { |
147 |
if (hover instanceof ITextHoverExtension2) { |
| 131 |
Object info= ((ITextHoverExtension2) hover).getHoverInfo2(textViewer, hoverRegion); |
148 |
Object info= ((ITextHoverExtension2) hover).getHoverInfo2(textViewer, hoverRegion); |
| 132 |
if (info != null) { |
149 |
if (info != null) { |