001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jface.text;
011:
012: import org.eclipse.swt.graphics.Point;
013:
014: /**
015: * Defines the target for finding and replacing strings.
016: * <p>
017: * The two main methods are <code>findAndSelect</code> and
018: * <code>replaceSelection</code>. The target does not provide any way to
019: * modify the content other than replacing the selection.
020: * <p>
021: *
022: * In order to provide backward compatibility for clients of
023: * <code>IFindReplaceTarget</code>, extension interfaces are used as a means
024: * of evolution. The following extension interfaces exist:
025: * <ul>
026: * <li>{@link org.eclipse.jface.text.IFindReplaceTargetExtension} since version
027: * 2.0 introducing the notion of find/replace session and of a find/replace
028: * scope. In additions, in allows clients to replace all occurrences of a given
029: * find query.</li>
030: * <li>{@link org.eclipse.jface.text.IFindReplaceTargetExtension3} since
031: * version 3.0 allowing clients to specify search queries as regular
032: * expressions.</li>
033: * </ul>
034: * <p>
035: * Clients of a <code>IFindReplaceTarget</code> that also implements the
036: * <code>IFindReplaceTargetExtension</code> have to indicate the start of a find/replace
037: * session before using the target and to indicate the end of the session when the
038: * target is no longer used.
039: *
040: * @see org.eclipse.jface.text.IFindReplaceTargetExtension
041: * @see org.eclipse.jface.text.IFindReplaceTargetExtension3
042: */
043: public interface IFindReplaceTarget {
044:
045: /**
046: * Returns whether a find operation can be performed.
047: *
048: * @return whether a find operation can be performed
049: */
050: boolean canPerformFind();
051:
052: /**
053: * Searches for a string starting at the given widget offset and using the specified search
054: * directives. If a string has been found it is selected and its start offset is
055: * returned.
056: * <p>
057: * Replaced by {@link IFindReplaceTargetExtension3#findAndSelect(int, String, boolean, boolean, boolean, boolean)}.
058: *
059: * @param widgetOffset the widget offset at which searching starts
060: * @param findString the string which should be found
061: * @param searchForward <code>true</code> searches forward, <code>false</code> backwards
062: * @param caseSensitive <code>true</code> performs a case sensitive search, <code>false</code> an insensitive search
063: * @param wholeWord if <code>true</code> only occurrences are reported in which the findString stands as a word by itself
064: * @return the position of the specified string, or -1 if the string has not been found
065: */
066: int findAndSelect(int widgetOffset, String findString,
067: boolean searchForward, boolean caseSensitive,
068: boolean wholeWord);
069:
070: /**
071: * Returns the currently selected range of characters as a offset and length in widget coordinates.
072: *
073: * @return the currently selected character range in widget coordinates
074: */
075: Point getSelection();
076:
077: /**
078: * Returns the currently selected characters as a string.
079: *
080: * @return the currently selected characters
081: */
082: String getSelectionText();
083:
084: /**
085: * Returns whether this target can be modified.
086: *
087: * @return <code>true</code> if target can be modified
088: */
089: boolean isEditable();
090:
091: /**
092: * Replaces the currently selected range of characters with the given text.
093: * This target must be editable. Otherwise nothing happens.
094: * <p>
095: * Replaced by {@link IFindReplaceTargetExtension3#replaceSelection(String, boolean)}.
096: *
097: * @param text the substitution text
098: */
099: void replaceSelection(String text);
100: }
|