Lines 7-12
Link Here
|
7 |
* |
7 |
* |
8 |
* Contributors: |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
|
|
10 |
* Cagatay Calli - https://bugs.eclipse.org/bugs/show_bug.cgi?id=29692 |
10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
11 |
package org.eclipse.jface.text; |
12 |
package org.eclipse.jface.text; |
12 |
|
13 |
|
Lines 74-79
Link Here
|
74 |
import org.eclipse.jface.text.hyperlink.IHyperlinkPresenter; |
75 |
import org.eclipse.jface.text.hyperlink.IHyperlinkPresenter; |
75 |
import org.eclipse.jface.text.projection.ChildDocument; |
76 |
import org.eclipse.jface.text.projection.ChildDocument; |
76 |
import org.eclipse.jface.text.projection.ChildDocumentManager; |
77 |
import org.eclipse.jface.text.projection.ChildDocumentManager; |
|
|
78 |
import org.eclipse.jface.text.source.Annotation; |
79 |
import org.eclipse.jface.text.source.AnnotationModel; |
80 |
import org.eclipse.jface.text.source.ISourceViewer; |
81 |
import org.eclipse.jface.text.source.SourceViewer; |
77 |
|
82 |
|
78 |
|
83 |
|
79 |
/** |
84 |
/** |
Lines 754-760
Link Here
|
754 |
/** |
759 |
/** |
755 |
* This viewer's find/replace target. |
760 |
* This viewer's find/replace target. |
756 |
*/ |
761 |
*/ |
757 |
class FindReplaceTarget implements IFindReplaceTarget, IFindReplaceTargetExtension, IFindReplaceTargetExtension3 { |
762 |
class FindReplaceTarget implements IFindReplaceTarget, IFindReplaceTargetExtension, IFindReplaceTargetExtension3, IFindReplaceTargetExtension4 { |
758 |
|
763 |
|
759 |
/** The range for this target. */ |
764 |
/** The range for this target. */ |
760 |
private FindReplaceRange fRange; |
765 |
private FindReplaceRange fRange; |
Lines 997-1003
Link Here
|
997 |
} |
1002 |
} |
998 |
} |
1003 |
} |
999 |
} |
1004 |
} |
|
|
1005 |
|
1006 |
/* |
1007 |
* @see IFindReplaceTargetExtension4#highlightAll(String, boolean, boolean, boolean) |
1008 |
* @since 3.4 |
1009 |
*/ |
1010 |
public int highlightAll(String findString, boolean caseSensitive, |
1011 |
boolean wholeWord, boolean regExSearch) { |
1012 |
int matchCount; |
1013 |
|
1014 |
if (fRange != null) { |
1015 |
IRegion range= fRange.getRange(); |
1016 |
matchCount = TextViewer.this.highlightAllInRange(findString, caseSensitive, wholeWord, range.getOffset(), range.getLength(), regExSearch); |
1017 |
} else { |
1018 |
matchCount = TextViewer.this.highlightAll(findString, caseSensitive, wholeWord, regExSearch); |
1019 |
} |
1020 |
|
1021 |
return matchCount; |
1022 |
} |
1023 |
|
1024 |
/* |
1025 |
* @see IFindReplaceTargetExtension4#clearHighlights() |
1026 |
* @since 3.4 |
1027 |
*/ |
1028 |
public void clearHighlights() { |
1029 |
// TODO This removes annotations if target supports it. Remove highlights from non-supporting targets. |
1030 |
if(TextViewer.this instanceof SourceViewer){ |
1031 |
AnnotationModel model = (AnnotationModel) ((SourceViewer) TextViewer.this).getAnnotationModel(); |
1032 |
Iterator iter = model.getAnnotationIterator(); |
1033 |
while(iter.hasNext()){ |
1034 |
Annotation currentAnnotation = (Annotation) iter.next(); |
1035 |
if(currentAnnotation.getType().equals("org.eclipse.jface.text.find")){ //$NON-NLS-1$ |
1036 |
model.removeAnnotation(currentAnnotation); |
1037 |
} |
1038 |
} |
1039 |
} |
1040 |
} |
1041 |
|
1000 |
} |
1042 |
} |
|
|
1043 |
|
1044 |
|
1045 |
|
1001 |
|
1046 |
|
1002 |
|
1047 |
|
1003 |
/** |
1048 |
/** |
Lines 5331-5335
Link Here
|
5331 |
public void setTabsToSpacesConverter(IAutoEditStrategy converter) { |
5376 |
public void setTabsToSpacesConverter(IAutoEditStrategy converter) { |
5332 |
fTabsToSpacesConverter= converter; |
5377 |
fTabsToSpacesConverter= converter; |
5333 |
} |
5378 |
} |
|
|
5379 |
|
5380 |
/** |
5381 |
* Returns whether this TextViewer is annotatible. |
5382 |
* @return whether this TextViewer is annotatible |
5383 |
* @since 3.4 |
5384 |
*/ |
5385 |
public boolean isAnnotatible(){ |
5386 |
return (this instanceof ISourceViewer); |
5387 |
} |
5388 |
|
5389 |
/** |
5390 |
* Adheres to the contract of {@link org.eclipse.jface.text.IFindReplaceTargetExtension4#highlightAll(String, boolean, boolean, boolean)}. |
5391 |
* |
5392 |
* @param findString the find string specification |
5393 |
* @param caseSensitive <code>true</code> if case sensitive, <code>false</code> otherwise |
5394 |
* @param wholeWord <code>true</code> if matches must be whole words, <code>false</code> otherwise |
5395 |
* @param regExSearch <code>true</code> if <code>findString</code> is a regular expression, <code>false</code> otherwise |
5396 |
* @return number of occurrences in range |
5397 |
* @since 3.4 |
5398 |
*/ |
5399 |
protected int highlightAll(String findString, boolean caseSensitive, |
5400 |
boolean wholeWord, boolean regExSearch) { |
5401 |
int matchCounter = 0; |
5402 |
|
5403 |
try { |
5404 |
|
5405 |
int widgetOffset= 0; |
5406 |
int firstMatch = -1; |
5407 |
IRegion matchRegion; |
5408 |
FindReplaceDocumentAdapter adapter= getFindReplaceDocumentAdapter(); |
5409 |
|
5410 |
while((matchRegion= adapter.find(widgetOffset, findString, true, caseSensitive, wholeWord, regExSearch))!=null){ |
5411 |
int widgetPos= matchRegion.getOffset(); |
5412 |
int length= matchRegion.getLength(); |
5413 |
|
5414 |
if(matchCounter == 0) firstMatch = widgetPos; |
5415 |
else { |
5416 |
if(firstMatch == widgetPos) |
5417 |
return matchCounter; |
5418 |
} |
5419 |
|
5420 |
if(isAnnotatible()){ |
5421 |
AnnotationModel model = (AnnotationModel) ((ISourceViewer) TextViewer.this).getAnnotationModel(); |
5422 |
Annotation findAnnotation = new Annotation("org.eclipse.jface.text.find",true,adapter.subSequence(widgetPos, widgetPos+length).toString()); //$NON-NLS-1$ |
5423 |
Position position = new Position(widgetPos,length); |
5424 |
model.addAnnotation(findAnnotation, position); |
5425 |
} |
5426 |
else { |
5427 |
// TODO Add raw highlighing for targets that don't support annotations |
5428 |
// Color highlight = new Color(getTextWidget().getDisplay(),255,0,0); |
5429 |
// setTextColor(highlight, widgetPos, length, false); |
5430 |
return 0; |
5431 |
} |
5432 |
|
5433 |
matchCounter++; |
5434 |
widgetOffset = widgetPos + length; |
5435 |
} |
5436 |
|
5437 |
} catch (BadLocationException x) { |
5438 |
if (TRACE_ERRORS) |
5439 |
System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.findAndSelect")); //$NON-NLS-1$ |
5440 |
} |
5441 |
|
5442 |
return matchCounter; |
5443 |
|
5444 |
} |
5445 |
|
5446 |
/** |
5447 |
* Adheres to the contract of {@link org.eclipse.jface.text.IFindReplaceTargetExtension4#highlightAll(String, boolean, boolean, boolean)}. |
5448 |
* |
5449 |
* @param findString the find string specification |
5450 |
* @param caseSensitive <code>true</code> if case sensitive, <code>false</code> otherwise |
5451 |
* @param wholeWord <code>true</code> if matches must be whole words, <code>false</code> otherwise |
5452 |
* @param rangeOffset the search scope offset |
5453 |
* @param rangeLength the search scope length |
5454 |
* @param regExSearch <code>true</code> if <code>findString</code> is a regular expression, <code>false</code> otherwise |
5455 |
* @return number of occurrences in range |
5456 |
* @since 3.4 |
5457 |
*/ |
5458 |
protected int highlightAllInRange(String findString, boolean caseSensitive, |
5459 |
boolean wholeWord, int rangeOffset, int rangeLength, boolean regExSearch){ |
5460 |
int matchCounter = 0; |
5461 |
|
5462 |
try { |
5463 |
|
5464 |
int firstMatch = -1; |
5465 |
int widgetOffset= modelOffset2WidgetOffset(rangeOffset); |
5466 |
if (widgetOffset == -1) |
5467 |
return -1; |
5468 |
|
5469 |
FindReplaceDocumentAdapter adapter= getFindReplaceDocumentAdapter(); |
5470 |
IRegion matchRegion; |
5471 |
int widgetPos= -1; |
5472 |
int length= 0; |
5473 |
while((matchRegion= adapter.find(widgetOffset, findString, true, caseSensitive, wholeWord, regExSearch)) != null) { |
5474 |
widgetPos= matchRegion.getOffset(); |
5475 |
length= matchRegion.getLength(); |
5476 |
|
5477 |
if(matchCounter == 0) firstMatch = widgetPos; |
5478 |
else { |
5479 |
if(firstMatch == widgetPos) |
5480 |
return matchCounter; |
5481 |
} |
5482 |
|
5483 |
int modelPos= widgetPos == -1 ? -1 : widgetOffset2ModelOffset(widgetPos); |
5484 |
|
5485 |
if (widgetPos != -1 && (modelPos < rangeOffset || modelPos + length > rangeOffset + rangeLength)) |
5486 |
widgetPos= -1; |
5487 |
|
5488 |
if (widgetPos > -1) { |
5489 |
|
5490 |
if(isAnnotatible()){ |
5491 |
AnnotationModel model = (AnnotationModel) ((ISourceViewer) TextViewer.this).getAnnotationModel(); |
5492 |
Annotation findAnnotation = new Annotation("org.eclipse.jface.text.find",true,adapter.subSequence(widgetPos, widgetPos+length).toString()); //$NON-NLS-1$ |
5493 |
Position position = new Position(widgetPos,length); |
5494 |
model.addAnnotation(findAnnotation, position); |
5495 |
} |
5496 |
else { |
5497 |
// TODO Add raw highlighing for targets that don't support annotations |
5498 |
// Color highlight = new Color(getTextWidget().getDisplay(),255,0,0); |
5499 |
// setTextColor(highlight, widgetPos, length, false); |
5500 |
return 0; |
5501 |
} |
5502 |
|
5503 |
matchCounter++; |
5504 |
|
5505 |
widgetOffset = widgetPos + length; |
5506 |
} |
5507 |
|
5508 |
else break; |
5509 |
} |
5510 |
|
5511 |
|
5512 |
} catch (BadLocationException x) { |
5513 |
if (TRACE_ERRORS) |
5514 |
System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.findAndSelect")); //$NON-NLS-1$ |
5515 |
} |
5516 |
|
5517 |
return matchCounter; |
5518 |
} |
5334 |
|
5519 |
|
5335 |
} |
5520 |
} |