KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > texteditor > IncrementalFindTarget


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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  * Felix Pahl (fpahl@web.de) - fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=51820
11  *******************************************************************************/

12
13 package org.eclipse.ui.texteditor;
14
15 import java.util.Stack JavaDoc;
16
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.custom.StyledText;
19 import org.eclipse.swt.custom.VerifyKeyListener;
20 import org.eclipse.swt.events.FocusEvent;
21 import org.eclipse.swt.events.FocusListener;
22 import org.eclipse.swt.events.MouseEvent;
23 import org.eclipse.swt.events.MouseListener;
24 import org.eclipse.swt.events.VerifyEvent;
25 import org.eclipse.swt.graphics.Color;
26 import org.eclipse.swt.graphics.Point;
27
28 import org.eclipse.core.commands.ExecutionEvent;
29 import org.eclipse.core.commands.ExecutionException;
30 import org.eclipse.core.commands.IExecutionListener;
31 import org.eclipse.core.commands.NotHandledException;
32
33 import org.eclipse.core.runtime.Assert;
34
35 import org.eclipse.jface.action.IStatusLineManager;
36 import org.eclipse.jface.viewers.ISelection;
37 import org.eclipse.jface.viewers.ISelectionChangedListener;
38 import org.eclipse.jface.viewers.ISelectionProvider;
39 import org.eclipse.jface.viewers.SelectionChangedEvent;
40
41 import org.eclipse.jface.text.IFindReplaceTarget;
42 import org.eclipse.jface.text.IFindReplaceTargetExtension;
43 import org.eclipse.jface.text.IRegion;
44 import org.eclipse.jface.text.ITextListener;
45 import org.eclipse.jface.text.ITextSelection;
46 import org.eclipse.jface.text.ITextViewer;
47 import org.eclipse.jface.text.ITextViewerExtension;
48 import org.eclipse.jface.text.TextEvent;
49
50 import org.eclipse.ui.PlatformUI;
51 import org.eclipse.ui.commands.ICommandService;
52 import org.eclipse.ui.internal.texteditor.NLSUtility;
53
54 /**
55  * An incremental find target. Replace is always disabled.
56  * @since 2.0
57  */

58 class IncrementalFindTarget implements IFindReplaceTarget, IFindReplaceTargetExtension, VerifyKeyListener, MouseListener, FocusListener, ISelectionChangedListener, ITextListener, IExecutionListener {
59
60     /** The string representing rendered tab */
61     private final static String JavaDoc TAB= EditorMessages.Editor_FindIncremental_render_tab;
62     /**
63      * The string representing "Reverse Incremental Find"
64      * @since 3.0
65      */

66     private final static String JavaDoc FIELD_NAME= EditorMessages.Editor_FindIncremental_name;
67     /**
68      * The string representing "Incremental Find"
69      * @since 3.0
70      */

71     private final static String JavaDoc REVERSE_FIELD_NAME= EditorMessages.Editor_FindIncremental_reverse_name;
72     /**
73      * The string representing reverse
74      * @since 2.1
75      */

76     private final static String JavaDoc REVERSE= EditorMessages.Editor_FindIncremental_reverse;
77     /**
78      * The string representing wrapped
79      * @since 2.1
80      */

81     private final static String JavaDoc WRAPPED= EditorMessages.Editor_FindIncremental_wrapped;
82     /** The text viewer to operate on */
83     private final ITextViewer fTextViewer;
84     /** The status line manager for output */
85     private final IStatusLineManager fStatusLine;
86     /** The find replace target to delegate find requests */
87     private final IFindReplaceTarget fTarget;
88     /** The current find string */
89     private StringBuffer JavaDoc fFindString= new StringBuffer JavaDoc();
90     /** The position of the first upper case character, -1 if none */
91     private int fCasePosition;
92     /**
93      * The position in the stack of the first wrap search, -1 if none
94      * @since 2.1
95      */

96     private int fWrapPosition;
97     /** The position of the last successful find */
98     private int fCurrentIndex;
99     /** A flag indicating if last find was successful */
100     private boolean fFound;
101     /**
102      * A flag indicating if the last search was forward
103      * @since 2.1
104      */

105     private boolean fForward= true;
106     /** A flag indicating listeners are installed. */
107     private boolean fInstalled;
108     /**
109      * A flag indicating that a search is currently active.
110      * Used to ignore selection callbacks generated by the incremental search itself.
111      * @since 2.1
112      */

113     private boolean fSearching;
114     /** The current find stack */
115     private Stack JavaDoc fSessionStack;
116     /**
117      * The previous search string
118      * @since 2.1
119      */

120     private String JavaDoc fPrevFindString= ""; //$NON-NLS-1$
121
/**
122      * The previous position of the first upper case character, -1 if none
123      * @since 3.0
124      */

125     private int fPrevCasePosition= -1;
126     /**
127      * The find status field.
128      * @since 3.0
129      */

130     private IStatusField fStatusField;
131     /**
132      * Tells whether the status field implements
133      * <code>IStatusFieldExtension</code>.
134      * @see IStatusFieldExtension
135      * @since 3.0
136      */

137     private boolean fIsStatusFieldExtension;
138
139     /**
140      * Data structure for a search result.
141      * @since 2.1
142      */

143     private class SearchResult {
144         int selection, length, index, findLength;
145         boolean found, forward;
146
147         /**
148          * Creates a new search result data object and fills
149          * it with the current values of this target.
150          */

151         public SearchResult() {
152             Point p= fTarget.getSelection();
153             selection= p.x;
154             length= p.y;
155             index= fCurrentIndex;
156             findLength= fFindString.length();
157             found= fFound;
158             forward= fForward;
159         }
160
161     }
162
163     /**
164      * Stores the search result.
165      */

166     private void saveState() {
167         fSessionStack.push(new SearchResult());
168     }
169
170     /**
171      * Restores the search result.
172      *
173      * @since 2.1
174      */

175     private void restoreState() {
176
177         StyledText text= fTextViewer.getTextWidget();
178         if (text == null || text.isDisposed())
179             return;
180
181         SearchResult searchResult= null;
182         if (!fSessionStack.empty())
183             searchResult= (SearchResult) fSessionStack.pop();
184
185         if (searchResult == null) {
186             text.getDisplay().beep();
187             return;
188         }
189
190         text.setSelectionRange(searchResult.selection, searchResult.length);
191         text.showSelection();
192
193         // relies on the contents of the StringBuffer
194
fFindString.setLength(searchResult.findLength);
195         fCurrentIndex= searchResult.index;
196         fFound= searchResult.found;
197         fForward= searchResult.forward;
198
199         // Recalculate the indices
200
if (fFindString.length() <= fCasePosition)
201             fCasePosition= -1;
202         if (fSessionStack.size() < fWrapPosition)
203             fWrapPosition= -1;
204     }
205
206     /**
207      * Sets the direction for the next search.
208      * This can be called before <code>beginSession</code> to set the initial search direction.
209      * @param forward <code>true</code> if the next search should be forward
210      * @see #beginSession()
211      * @since 2.1
212      */

213     public void setDirection(boolean forward) {
214         fForward= forward;
215     }
216
217     /**
218      * Creates an instance of an incremental find target.
219      * @param viewer the text viewer to operate on
220      * @param manager the status line manager for output
221      */

222     public IncrementalFindTarget(ITextViewer viewer, IStatusLineManager manager) {
223         Assert.isNotNull(viewer);
224         Assert.isNotNull(manager);
225         fTextViewer= viewer;
226         fStatusLine= manager;
227         fTarget= viewer.getFindReplaceTarget();
228     }
229
230     /*
231      * @see IFindReplaceTarget#canPerformFind()
232      */

233     public boolean canPerformFind() {
234         return fTarget.canPerformFind();
235     }
236
237     /*
238      * @see IFindReplaceTarget#findAndSelect(int, String, boolean, boolean, boolean)
239      */

240     public int findAndSelect(int offset, String JavaDoc findString, boolean searchForward, boolean caseSensitive, boolean wholeWord) {
241         return fTarget.findAndSelect(offset, findString, searchForward, caseSensitive, wholeWord);
242     }
243
244     /*
245      * @see IFindReplaceTarget#getSelection()
246      */

247     public Point getSelection() {
248         return fTarget.getSelection();
249     }
250
251     /*
252      * @see IFindReplaceTarget#getSelectionText()
253      */

254     public String JavaDoc getSelectionText() {
255         return fTarget.getSelectionText();
256     }
257
258     /*
259      * @see IFindReplaceTarget#isEditable()
260      */

261     public boolean isEditable() {
262         return false;
263     }
264
265     /*
266      * @see IFindReplaceTarget#replaceSelection(String)
267      */

268     public void replaceSelection(String JavaDoc text) {
269     }
270
271     /*
272      * @see IFindReplaceTargetExtension#beginSession()
273      */

274     public void beginSession() {
275         fSearching= true;
276
277         // Workaround since some accelerators get handled directly by the OS
278
if (fInstalled) {
279             saveState();
280             repeatSearch(fForward);
281             updateStatus();
282             fSearching= false;
283             return;
284         }
285
286         fFindString.setLength(0);
287         fSessionStack= new Stack JavaDoc();
288         fCasePosition= -1;
289         fWrapPosition= -1;
290         fFound= true;
291
292         // clear initial selection
293
StyledText text= fTextViewer.getTextWidget();
294         if (text != null && !text.isDisposed()) {
295             fCurrentIndex= text.getCaretOffset();
296             text.setSelection(fCurrentIndex);
297         } else {
298             fCurrentIndex= 0;
299         }
300
301         install();
302
303         // Set the mark
304
if (fTextViewer instanceof ITextViewerExtension)
305             ((ITextViewerExtension) fTextViewer).setMark(fCurrentIndex);
306
307         updateStatus();
308
309         if (fTarget instanceof IFindReplaceTargetExtension)
310             ((IFindReplaceTargetExtension) fTarget).beginSession();
311
312         fSearching= false;
313     }
314
315     /*
316      * @see IFindReplaceTargetExtension#endSession()
317      */

318     public void endSession() {
319         if (fTarget instanceof IFindReplaceTargetExtension)
320             ((IFindReplaceTargetExtension) fTarget).endSession();
321
322         // will uninstall itself
323
}
324
325     /*
326      * @see IFindReplaceTargetExtension#getScope()
327      */

328     public IRegion getScope() {
329         return null;
330     }
331
332     /*
333      * @see IFindReplaceTargetExtension#setGlobal(boolean)
334      */

335     public void setGlobal(boolean global) {
336     }
337
338     /*
339      * @see IFindReplaceTargetExtension#setScope(IRegion)
340      */

341     public void setScope(IRegion scope) {
342     }
343
344     /*
345      * @see IFindReplaceTargetExtension#setReplaceAllMode(boolean)
346      */

347     public void setReplaceAllMode(boolean replaceAll) {
348     }
349
350     /**
351      * Installs this target. I.e. adds all required listeners.
352      */

353     private void install() {
354
355         if (fInstalled)
356             return;
357
358         StyledText text= fTextViewer.getTextWidget();
359         if (text == null)
360             return;
361
362         text.addMouseListener(this);
363         text.addFocusListener(this);
364         fTextViewer.addTextListener(this);
365
366         ISelectionProvider selectionProvider= fTextViewer.getSelectionProvider();
367         if (selectionProvider != null)
368             selectionProvider.addSelectionChangedListener(this);
369
370         if (fTextViewer instanceof ITextViewerExtension)
371             ((ITextViewerExtension) fTextViewer).prependVerifyKeyListener(this);
372         else
373             text.addVerifyKeyListener(this);
374         
375         ICommandService commandService= (ICommandService)PlatformUI.getWorkbench().getAdapter(ICommandService.class);
376         if (commandService != null)
377             commandService.addExecutionListener(this);
378
379         fInstalled= true;
380     }
381
382     /**
383      * Uninstalls itself. I.e. removes all listeners installed in <code>install</code>.
384      */

385     private void uninstall() {
386
387         fTextViewer.removeTextListener(this);
388
389         ISelectionProvider selectionProvider= fTextViewer.getSelectionProvider();
390         if (selectionProvider != null)
391             selectionProvider.removeSelectionChangedListener(this);
392
393         StyledText text= fTextViewer.getTextWidget();
394         if (text != null) {
395             text.removeMouseListener(this);
396             text.removeFocusListener(this);
397         }
398
399         if (fTextViewer instanceof ITextViewerExtension) {
400             ((ITextViewerExtension) fTextViewer).removeVerifyKeyListener(this);
401
402         } else {
403             if (text != null)
404                 text.removeVerifyKeyListener(this);
405         }
406
407         ICommandService commandService= (ICommandService)PlatformUI.getWorkbench().getAdapter(ICommandService.class);
408         if (commandService != null)
409             commandService.removeExecutionListener(this);
410
411         fInstalled= false;
412     }
413
414     /**
415      * Updates the status line.
416      * @since 2.1
417      */

418     private void updateStatus() {
419
420         if (!fInstalled)
421             return;
422
423         String JavaDoc string= fFindString.toString();
424         String JavaDoc wrapPrefix= fWrapPosition == -1 ? "" : WRAPPED; //$NON-NLS-1$
425
String JavaDoc reversePrefix= fForward ? "" : REVERSE; //$NON-NLS-1$
426

427         if (!fFound) {
428             String JavaDoc pattern= EditorMessages.Editor_FindIncremental_not_found_pattern;
429             statusError(NLSUtility.format(pattern, new Object JavaDoc[] { reversePrefix, wrapPrefix, string }));
430
431         } else if (string.length() == 0) {
432             if (fForward)
433                 statusMessage(FIELD_NAME);
434             else
435                 statusMessage(REVERSE_FIELD_NAME);
436         } else if (!fForward || fWrapPosition > -1) {
437             String JavaDoc pattern= EditorMessages.Editor_FindIncremental_found_pattern;
438             statusMessage(NLSUtility.format(pattern, new Object JavaDoc[] { reversePrefix, wrapPrefix, string }));
439         } else {
440             statusMessage(string);
441         }
442     }
443
444     /*
445      * @see VerifyKeyListener#verifyKey(VerifyEvent)
446      */

447     public void verifyKey(VerifyEvent event) {
448
449         if (!event.doit)
450             return;
451
452         fSearching= true;
453         if (event.character == 0) {
454
455             switch (event.keyCode) {
456
457             // ALT, CTRL, ARROW_LEFT, ARROW_RIGHT == leave
458
case SWT.ARROW_LEFT:
459             case SWT.ARROW_RIGHT:
460             case SWT.HOME:
461             case SWT.END:
462             case SWT.PAGE_DOWN:
463             case SWT.PAGE_UP:
464                 leave();
465                 break;
466
467             case SWT.ARROW_DOWN:
468                 saveState();
469                 setDirection(true);
470                 repeatSearch(fForward);
471                 event.doit= false;
472                 break;
473
474             case SWT.ARROW_UP:
475                 saveState();
476                 setDirection(false);
477                 repeatSearch(fForward);
478                 event.doit= false;
479                 break;
480             }
481
482         // event.character != 0
483
} else {
484
485             switch (event.character) {
486
487             // ESC, CR = quit
488
case 0x1B:
489             case 0x0D:
490                 leave();
491                 event.doit= false;
492                 break;
493
494             // backspace and delete
495
case 0x08:
496             case 0x7F:
497                 restoreState();
498                 event.doit= false;
499                 break;
500
501             default:
502                 if (event.stateMask == 0 || event.stateMask == SWT.SHIFT || event.stateMask == (SWT.ALT | SWT.CTRL)) { // SWT.ALT | SWT.CTRL covers AltGr (see bug 43049)
503
saveState();
504                     addCharSearch(event.character);
505                     event.doit= false;
506                 }
507                 break;
508             }
509         }
510         updateStatus();
511         fSearching= false;
512     }
513
514     /**
515      * Repeats the last search while possibly changing the direction.
516      *
517      * @param forward <code>true</code> iff the next search should be forward
518      * @return if the search was successful
519      * @since 2.1
520      */

521     private boolean repeatSearch(boolean forward) {
522         if (fFindString.length() == 0) {
523             fFindString= new StringBuffer JavaDoc(fPrevFindString);
524             fCasePosition= fPrevCasePosition;
525         }
526
527         String JavaDoc string= fFindString.toString();
528         if (string.length() == 0) {
529             fFound= true;
530             return true;
531         }
532
533         StyledText text= fTextViewer.getTextWidget();
534         // Cannot use fTarget.getSelection since that does not return which side of the
535
// selection the caret is on.
536
int startIndex= text.getCaretOffset();
537         if (!forward)
538             startIndex -= 1;
539
540         // Check to see if a wrap is necessary
541
if (!fFound && (fForward == forward)) {
542             startIndex= -1;
543             if (fWrapPosition == -1)
544                 fWrapPosition= fSessionStack.size();
545         }
546         fForward = forward;
547
548         // Find the string
549
text.setRedraw(false);
550         int index= fTarget.findAndSelect(startIndex, string, fForward, fCasePosition != -1, false);
551
552         // Set the caret on the left if the search is reversed
553
if (!forward) {
554             Point p= fTarget.getSelection();
555             text.setSelectionRange(p.x + p.y, -p.y);
556             p= null;
557         }
558         text.setRedraw(true);
559
560         // Take appropriate action
561
boolean found = (index != -1);
562         if (!found && fFound) {
563             text= fTextViewer.getTextWidget();
564             if (text != null && !text.isDisposed())
565                 text.getDisplay().beep();
566         }
567
568         if (found)
569             fCurrentIndex= startIndex;
570
571         fFound= found;
572         return found;
573     }
574
575     /**
576      * Adds the given character to the search string and repeats the search with the last parameters.
577      *
578      * @param c the character to append to the search pattern
579      * @return <code>true</code> the search found a match
580      * @since 2.1
581      */

582     private boolean addCharSearch(char c) {
583         // Add char to pattern
584
if (fCasePosition == -1 && Character.isUpperCase(c) && Character.toLowerCase(c) != c)
585             fCasePosition= fFindString.length();
586
587         fFindString.append(c);
588         String JavaDoc string= fFindString.toString();
589         StyledText text= fTextViewer.getTextWidget();
590
591         text.setRedraw(false);
592         int index= fTarget.findAndSelect(fCurrentIndex, string, fForward, fCasePosition != -1, false);
593
594         // Set the caret on the left if the search is reversed
595
if (!fForward) {
596             Point p= fTarget.getSelection();
597             text.setSelectionRange(p.x + p.y, -p.y);
598         }
599         text.setRedraw(true);
600
601         // Take appropriate action
602
boolean found = (index != -1);
603         if (!found && fFound) {
604             text= fTextViewer.getTextWidget();
605             if (text != null && !text.isDisposed())
606                 text.getDisplay().beep();
607         }
608
609         fFound= found;
610         return found;
611     }
612
613     /**
614      * Leaves this incremental search session.
615      */

616     private void leave() {
617         if (fFindString.length() != 0) {
618             fPrevFindString= fFindString.toString();
619             fPrevCasePosition= fCasePosition;
620         }
621         statusClear();
622         uninstall();
623         fSessionStack = null;
624     }
625
626     /*
627      * @see ITextListener#textChanged(TextEvent)
628      */

629     public void textChanged(TextEvent event) {
630         if (event.getDocumentEvent() != null)
631             leave();
632     }
633
634     /*
635      * @see MouseListener##mouseDoubleClick(MouseEvent)
636      */

637     public void mouseDoubleClick(MouseEvent e) {
638         leave();
639     }
640
641     /*
642      * @see MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
643      */

644     public void mouseDown(MouseEvent e) {
645         leave();
646     }
647
648     /*
649      * @see MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
650      */

651     public void mouseUp(MouseEvent e) {
652         leave();
653     }
654
655     /*
656      * @see FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
657      */

658     public void focusGained(FocusEvent e) {
659         leave();
660     }
661
662     /*
663      * @see FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
664      */

665     public void focusLost(FocusEvent e) {
666         leave();
667     }
668
669     /**
670      * Sets the given string as status message, clears the status error message.
671      * @param string the status message
672      */

673     private void statusMessage(String JavaDoc string) {
674         if (fStatusField != null) {
675             if (fIsStatusFieldExtension) {
676                 ((IStatusFieldExtension)fStatusField).setErrorText(null);
677                 fStatusField.setText(escapeTabs(string));
678                 ((IStatusFieldExtension)fStatusField).setVisible(true);
679                 fStatusLine.update(true);
680             } else {
681                 fStatusLine.setErrorMessage(null);
682                 fStatusField.setText(escapeTabs(string));
683             }
684         } else {
685             fStatusLine.setErrorMessage(null);
686             fStatusLine.setMessage(escapeTabs(string));
687         }
688     }
689
690     /**
691      * Sets the status error message, clears the status message.
692      * @param string the status error message
693      */

694     private void statusError(String JavaDoc string) {
695         if (fStatusField != null) {
696             if (fIsStatusFieldExtension) {
697                 ((IStatusFieldExtension)fStatusField).setErrorText(escapeTabs(string));
698                 fStatusField.setText(""); //$NON-NLS-1$
699
((IStatusFieldExtension)fStatusField).setVisible(true);
700                 fStatusLine.update(true);
701             } else {
702                 fStatusLine.setErrorMessage(escapeTabs(string));
703                 fStatusField.setText(""); //$NON-NLS-1$
704
}
705         } else {
706             fStatusLine.setErrorMessage(escapeTabs(string));
707             fStatusLine.setMessage(null);
708         }
709     }
710
711     /**
712      * Clears the status message and the status error message.
713      */

714     private void statusClear() {
715         if (fStatusField != null) {
716             if (fIsStatusFieldExtension) {
717                 fStatusField.setText(""); //$NON-NLS-1$
718
((IStatusFieldExtension)fStatusField).setErrorText(null);
719                 ((IStatusFieldExtension)fStatusField).setVisible(false);
720                 fStatusLine.update(true);
721             } else {
722                 fStatusField.setText(""); //$NON-NLS-1$
723
fStatusLine.setErrorMessage(null);
724             }
725         } else {
726             fStatusLine.setErrorMessage(null);
727             fStatusLine.setMessage(null);
728         }
729     }
730
731     /**
732      * Translates all tab characters into a proper status line presentation.
733      * @param string the string in which to translate the tabs
734      * @return the given string with all tab characters replace with a proper status line presentation
735      */

736     private String JavaDoc escapeTabs(String JavaDoc string) {
737         StringBuffer JavaDoc buffer= new StringBuffer JavaDoc();
738
739         int begin= 0;
740         int end= string.indexOf('\t', begin);
741
742         while (end >= 0) {
743             buffer.append(string.substring(begin, end));
744             buffer.append(TAB);
745             begin= end + 1;
746             end= string.indexOf('\t', begin);
747         }
748         buffer.append(string.substring(begin));
749
750         return buffer.toString();
751     }
752
753     /*
754      * @see IFindReplaceTargetExtension#getLineSelection()
755      */

756     public Point getLineSelection() {
757         if (fTarget instanceof IFindReplaceTargetExtension)
758             return ((IFindReplaceTargetExtension) fTarget).getLineSelection();
759
760         return null; // XXX should not return null
761
}
762
763     /*
764      * @see IFindReplaceTargetExtension#setSelection(int, int)
765      */

766     public void setSelection(int offset, int length) {
767         if (fTarget instanceof IFindReplaceTargetExtension)
768             ((IFindReplaceTargetExtension) fTarget).setSelection(offset, length);
769     }
770
771     /*
772      * @see IFindReplaceTargetExtension#setScopeHighlightColor(Color)
773      */

774     public void setScopeHighlightColor(Color color) {
775     }
776
777     /*
778      * @see ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
779      * @since 2.1
780      */

781     public void selectionChanged(SelectionChangedEvent e) {
782         boolean ignore= false;
783         ISelection selection= e.getSelection();
784         if (selection instanceof ITextSelection) {
785             ITextSelection textSelection= (ITextSelection)selection;
786             Point range= getSelection();
787             ignore= textSelection.getOffset() + textSelection.getLength() == range.x + range.y;
788         }
789         if (!fSearching && !ignore)
790             leave();
791     }
792
793     /**
794      * Sets the find status field for this incremental find target.
795      *
796      * @param statusField the status field
797      * @since 3.0
798      */

799     void setStatusField(IStatusField statusField) {
800         fStatusField= statusField;
801         fIsStatusFieldExtension= fStatusField instanceof IStatusFieldExtension;
802     }
803
804     /*
805      * @see org.eclipse.core.commands.IExecutionListener#notHandled(java.lang.String, org.eclipse.core.commands.NotHandledException)
806      * @since 3.2
807      */

808     public void notHandled(String JavaDoc commandId, NotHandledException exception) {
809     }
810
811     /*
812      * @see org.eclipse.core.commands.IExecutionListener#postExecuteFailure(java.lang.String, org.eclipse.core.commands.ExecutionException)
813      * @since 3.2
814      */

815     public void postExecuteFailure(String JavaDoc commandId, ExecutionException exception) {
816     }
817
818     /*
819      * @see org.eclipse.core.commands.IExecutionListener#postExecuteSuccess(java.lang.String, java.lang.Object)
820      * @since 3.2
821      */

822     public void postExecuteSuccess(String JavaDoc commandId, Object JavaDoc returnValue) {
823     }
824
825     /*
826      * @see org.eclipse.core.commands.IExecutionListener#preExecute(java.lang.String, org.eclipse.core.commands.ExecutionEvent)
827      * @since 3.2
828      */

829     public void preExecute(String JavaDoc commandId, ExecutionEvent event) {
830         if (IWorkbenchActionDefinitionIds.FIND_INCREMENTAL.equals(commandId)
831                 || IWorkbenchActionDefinitionIds.FIND_INCREMENTAL_REVERSE.equals(commandId))
832             return;
833         leave();
834     }
835 }
836
Popular Tags