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.ui.texteditor;
011:
012: import java.util.ResourceBundle;
013:
014: import org.eclipse.jface.text.IFindReplaceTarget;
015: import org.eclipse.jface.text.IFindReplaceTargetExtension;
016: import org.eclipse.ui.IWorkbenchPart;
017: import org.eclipse.ui.IWorkbenchWindow;
018:
019: /**
020: * An action which enters the incremental find mode like in emacs.
021: * <p>
022: * This class may be instantiated; it is not intended to be subclassed.
023: * </p>
024: * @since 2.0
025: */
026: public class IncrementalFindAction extends ResourceAction implements
027: IUpdate {
028:
029: /** The action's target */
030: private IFindReplaceTarget fTarget;
031: /** The part the action is bound to */
032: private IWorkbenchPart fWorkbenchPart;
033: /** The workbench window */
034: private IWorkbenchWindow fWorkbenchWindow;
035: /**
036: * The direction to run the incremental find
037: * @since 2.1
038: */
039: private boolean fForward;
040:
041: /**
042: * Creates a new incremental find action for the given workbench part.
043: * The action configures its visual representation from the given
044: * resource bundle.
045: *
046: * @param bundle the resource bundle
047: * @param prefix a prefix to be prepended to the various resource keys
048: * (described in <code>ResourceAction</code> constructor), or
049: * <code>null</code> if none
050: * @param workbenchPart the workbench part
051: * @param forward <code>true</code> if the search direction is forward
052: * @see ResourceAction#ResourceAction(ResourceBundle, String)
053: * @since 2.1
054: */
055: public IncrementalFindAction(ResourceBundle bundle, String prefix,
056: IWorkbenchPart workbenchPart, boolean forward) {
057: super (bundle, prefix);
058: fWorkbenchPart = workbenchPart;
059: fForward = forward;
060: update();
061: }
062:
063: /**
064: * Creates a new incremental find action for the given workbench window.
065: * The action configures its visual representation from the given
066: * resource bundle.
067: *
068: * @param bundle the resource bundle
069: * @param prefix a prefix to be prepended to the various resource keys
070: * (described in <code>ResourceAction</code> constructor), or
071: * <code>null</code> if none
072: * @param workbenchWindow the workbench window
073: * @param forward <code>true</code> if the search direction is forward
074: * @see ResourceAction#ResourceAction(ResourceBundle, String)
075: *
076: * @deprecated use FindReplaceAction(ResourceBundle, String, IWorkbenchPart, boolean) instead
077: * @since 2.1
078: */
079: public IncrementalFindAction(ResourceBundle bundle, String prefix,
080: IWorkbenchWindow workbenchWindow, boolean forward) {
081: super (bundle, prefix);
082: fWorkbenchWindow = workbenchWindow;
083: fForward = forward;
084: update();
085: }
086:
087: /*
088: * @see IAction#run()
089: */
090: public void run() {
091:
092: if (fTarget == null)
093: return;
094:
095: if (fTarget instanceof IncrementalFindTarget)
096: ((IncrementalFindTarget) fTarget).setDirection(fForward);
097:
098: if (fTarget instanceof IFindReplaceTargetExtension)
099: ((IFindReplaceTargetExtension) fTarget).beginSession();
100: }
101:
102: /*
103: * @see IUpdate#update()
104: */
105: public void update() {
106:
107: if (fWorkbenchPart == null && fWorkbenchWindow != null)
108: fWorkbenchPart = fWorkbenchWindow.getPartService()
109: .getActivePart();
110:
111: if (fWorkbenchPart != null)
112: fTarget = (IFindReplaceTarget) fWorkbenchPart
113: .getAdapter(IncrementalFindTarget.class);
114: else
115: fTarget = null;
116:
117: setEnabled(fTarget != null && fTarget.canPerformFind());
118: }
119:
120: }
|