1 11 12 package org.eclipse.ui.texteditor; 13 14 15 import java.util.ResourceBundle ; 16 17 import org.eclipse.jface.text.IFindReplaceTarget; 18 import org.eclipse.jface.text.IFindReplaceTargetExtension; 19 import org.eclipse.ui.IWorkbenchPart; 20 import org.eclipse.ui.IWorkbenchWindow; 21 22 23 30 public class IncrementalFindAction extends ResourceAction implements IUpdate { 31 32 33 private IFindReplaceTarget fTarget; 34 35 private IWorkbenchPart fWorkbenchPart; 36 37 private IWorkbenchWindow fWorkbenchWindow; 38 42 private boolean fForward; 43 44 58 public IncrementalFindAction(ResourceBundle bundle, String prefix, IWorkbenchPart workbenchPart, boolean forward) { 59 super(bundle, prefix); 60 fWorkbenchPart= workbenchPart; 61 fForward= forward; 62 update(); 63 } 64 65 81 public IncrementalFindAction(ResourceBundle bundle, String prefix, IWorkbenchWindow workbenchWindow, boolean forward) { 82 super(bundle, prefix); 83 fWorkbenchWindow= workbenchWindow; 84 fForward= forward; 85 update(); 86 } 87 88 91 public void run() { 92 93 if (fTarget == null) 94 return; 95 96 if (fTarget instanceof IncrementalFindTarget) 97 ((IncrementalFindTarget) fTarget).setDirection(fForward); 98 99 if (fTarget instanceof IFindReplaceTargetExtension) 100 ((IFindReplaceTargetExtension) fTarget).beginSession(); 101 } 102 103 106 public void update() { 107 108 if (fWorkbenchPart == null && fWorkbenchWindow != null) 109 fWorkbenchPart= fWorkbenchWindow.getPartService().getActivePart(); 110 111 if (fWorkbenchPart != null) 112 fTarget= (IFindReplaceTarget) fWorkbenchPart.getAdapter(IncrementalFindTarget.class); 113 else 114 fTarget= null; 115 116 setEnabled(fTarget != null && fTarget.canPerformFind()); 117 } 118 119 } 120 | Popular Tags |