|
Lines 7-18
Link Here
|
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
|
|
10 |
* Florian Albrecht <florian.albrecht@clintworld.de> - make NLSKeyHyperlink work with non-text editors - https://bugs.eclipse.org/bugs/show_bug.cgi?id=97228 |
| 10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
| 11 |
package org.eclipse.jdt.internal.ui.javaeditor; |
12 |
package org.eclipse.jdt.internal.ui.javaeditor; |
| 12 |
|
13 |
|
| 13 |
import org.eclipse.swt.widgets.Display; |
14 |
import org.eclipse.swt.widgets.Display; |
| 14 |
|
15 |
|
| 15 |
import org.eclipse.core.runtime.Assert; |
16 |
import org.eclipse.core.runtime.Assert; |
|
|
17 |
import org.eclipse.core.runtime.IPath; |
| 18 |
|
| 19 |
import org.eclipse.core.filebuffers.FileBuffers; |
| 20 |
import org.eclipse.core.filebuffers.ITextFileBuffer; |
| 21 |
import org.eclipse.core.filebuffers.LocationKind; |
| 16 |
|
22 |
|
| 17 |
import org.eclipse.core.resources.IStorage; |
23 |
import org.eclipse.core.resources.IStorage; |
| 18 |
|
24 |
|
|
Lines 27-36
Link Here
|
| 27 |
|
33 |
|
| 28 |
import org.eclipse.ui.IEditorInput; |
34 |
import org.eclipse.ui.IEditorInput; |
| 29 |
import org.eclipse.ui.IEditorPart; |
35 |
import org.eclipse.ui.IEditorPart; |
|
|
36 |
import org.eclipse.ui.IFileEditorInput; |
| 30 |
import org.eclipse.ui.PartInitException; |
37 |
import org.eclipse.ui.PartInitException; |
| 31 |
|
38 |
|
| 32 |
import org.eclipse.ui.texteditor.IEditorStatusLine; |
39 |
import org.eclipse.ui.texteditor.IEditorStatusLine; |
| 33 |
import org.eclipse.ui.texteditor.ITextEditor; |
|
|
| 34 |
|
40 |
|
| 35 |
import org.eclipse.jdt.core.JavaModelException; |
41 |
import org.eclipse.jdt.core.JavaModelException; |
| 36 |
import org.eclipse.jdt.core.dom.ITypeBinding; |
42 |
import org.eclipse.jdt.core.dom.ITypeBinding; |
|
Lines 121-178
Link Here
|
| 121 |
return; |
127 |
return; |
| 122 |
} |
128 |
} |
| 123 |
|
129 |
|
| 124 |
// Reveal the key in the properties file |
130 |
// Reveal the key in the editor |
| 125 |
if (editor instanceof ITextEditor) { |
131 |
IEditorInput input = editor.getEditorInput(); |
| 126 |
IRegion region= null; |
132 |
if (input instanceof IFileEditorInput) { |
| 127 |
boolean found= false; |
133 |
IPath path= ((IFileEditorInput)input).getFile().getFullPath(); |
| 128 |
|
134 |
ITextFileBuffer buffer= FileBuffers.getTextFileBufferManager().getTextFileBuffer( |
| 129 |
// Find key in document |
135 |
path, LocationKind.IFILE); |
| 130 |
IEditorInput editorInput= editor.getEditorInput(); |
136 |
if (buffer != null) { |
| 131 |
IDocument document= ((ITextEditor)editor).getDocumentProvider().getDocument(editorInput); |
137 |
// Find key in document |
| 132 |
if (document != null) { |
138 |
IDocument document= buffer.getDocument(); |
| 133 |
FindReplaceDocumentAdapter finder= new FindReplaceDocumentAdapter(document); |
139 |
boolean found= false; |
| 134 |
PropertyKeyHyperlinkDetector detector= new PropertyKeyHyperlinkDetector(); |
140 |
IRegion region= null; |
| 135 |
detector.setContext(editor); |
141 |
if (document != null) { |
| 136 |
String key= PropertyFileDocumentModel.unwindEscapeChars(keyName); |
142 |
FindReplaceDocumentAdapter finder= new FindReplaceDocumentAdapter(document); |
| 137 |
int offset= document.getLength() - 1; |
143 |
PropertyKeyHyperlinkDetector detector= new PropertyKeyHyperlinkDetector(); |
| 138 |
try { |
144 |
detector.setContext(editor); |
| 139 |
while (!found && offset >= 0) { |
145 |
String key= PropertyFileDocumentModel.unwindEscapeChars(keyName); |
| 140 |
region= finder.find(offset, key, false, true, false, false); |
146 |
int offset= document.getLength() - 1; |
| 141 |
if (region == null) |
147 |
try { |
| 142 |
offset= -1; |
148 |
while (!found && offset >= 0) { |
| 143 |
else { |
149 |
region= finder.find(offset, key, false, true, false, false); |
| 144 |
// test whether it's the key |
150 |
if (region == null) |
| 145 |
IHyperlink[] hyperlinks= detector.detectHyperlinks(null, region, false); |
151 |
offset= -1; |
| 146 |
if (hyperlinks != null) { |
152 |
else { |
| 147 |
for (int i= 0; i < hyperlinks.length; i++) { |
153 |
// test whether it's the key |
| 148 |
IRegion hyperlinkRegion= hyperlinks[i].getHyperlinkRegion(); |
154 |
IHyperlink[] hyperlinks= detector.detectHyperlinks(null, region, false); |
| 149 |
found= key.equals(document.get(hyperlinkRegion.getOffset(), hyperlinkRegion.getLength())); |
155 |
if (hyperlinks != null) { |
|
|
156 |
for (int i= 0; i < hyperlinks.length; i++) { |
| 157 |
IRegion hyperlinkRegion= hyperlinks[i].getHyperlinkRegion(); |
| 158 |
found= key.equals(document.get(hyperlinkRegion.getOffset(), hyperlinkRegion.getLength())); |
| 159 |
} |
| 160 |
} else if (document instanceof IDocumentExtension3) { |
| 161 |
// test using properties file partitioning |
| 162 |
ITypedRegion partition= null; |
| 163 |
partition= ((IDocumentExtension3)document).getPartition(IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING, region.getOffset(), false); |
| 164 |
found= IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType()) |
| 165 |
&& key.equals(document.get(partition.getOffset(), partition.getLength()).trim()); |
| 150 |
} |
166 |
} |
| 151 |
} else if (document instanceof IDocumentExtension3) { |
167 |
// Prevent endless loop (panic code, shouldn't be needed) |
| 152 |
// Fall back: test using properties file partitioning |
168 |
if (offset == region.getOffset()) |
| 153 |
ITypedRegion partition= null; |
169 |
offset= -1; |
| 154 |
partition= ((IDocumentExtension3)document).getPartition(IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING, region.getOffset(), false); |
170 |
else |
| 155 |
found= IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType()) |
171 |
offset= region.getOffset(); |
| 156 |
&& key.equals(document.get(partition.getOffset(), partition.getLength()).trim()); |
|
|
| 157 |
} |
172 |
} |
| 158 |
// Prevent endless loop (panic code, shouldn't be needed) |
|
|
| 159 |
if (offset == region.getOffset()) |
| 160 |
offset= -1; |
| 161 |
else |
| 162 |
offset= region.getOffset(); |
| 163 |
} |
173 |
} |
|
|
174 |
} catch (BadLocationException ex) { |
| 175 |
found= false; |
| 176 |
} catch (BadPartitioningException e1) { |
| 177 |
found= false; |
| 164 |
} |
178 |
} |
| 165 |
} catch (BadLocationException ex) { |
|
|
| 166 |
found= false; |
| 167 |
} catch (BadPartitioningException e1) { |
| 168 |
found= false; |
| 169 |
} |
179 |
} |
| 170 |
} |
180 |
if (found) |
| 171 |
if (found) |
181 |
EditorUtility.revealInEditor(editor, region); |
| 172 |
EditorUtility.revealInEditor(editor, region); |
182 |
else { |
| 173 |
else { |
183 |
EditorUtility.revealInEditor(editor, 0, 0); |
| 174 |
EditorUtility.revealInEditor(editor, 0, 0); |
184 |
showErrorInStatusLine(editor, Messages.format(JavaEditorMessages.Editor_OpenPropertiesFile_error_keyNotFound, keyName)); |
| 175 |
showErrorInStatusLine(editor, Messages.format(JavaEditorMessages.Editor_OpenPropertiesFile_error_keyNotFound, keyName)); |
185 |
} |
| 176 |
} |
186 |
} |
| 177 |
} |
187 |
} |
| 178 |
} |
188 |
} |