1 11 package org.eclipse.search.internal.ui.text; 12 13 import org.eclipse.core.resources.IFile; 14 import org.eclipse.core.resources.IWorkspace; 15 import org.eclipse.core.runtime.IProgressMonitor; 16 import org.eclipse.core.runtime.IStatus; 17 18 import org.eclipse.jface.resource.ImageDescriptor; 19 import org.eclipse.jface.util.Assert; 20 21 import org.eclipse.ui.actions.WorkspaceModifyOperation; 22 23 import org.eclipse.search.internal.core.ISearchScope; 24 import org.eclipse.search.internal.core.text.ITextSearchResultCollector; 25 import org.eclipse.search.internal.core.text.MatchLocator; 26 import org.eclipse.search.internal.core.text.TextSearchEngine; 27 import org.eclipse.search.internal.core.text.TextSearchScope; 28 import org.eclipse.search.internal.ui.SearchMessages; 29 import org.eclipse.search.internal.ui.SearchPluginImages; 30 31 34 public class TextSearchOperation extends WorkspaceModifyOperation { 35 36 public static final int NO_PRIORITY_CHANGE= -1; 37 38 private IWorkspace fWorkspace; 39 private MatchLocator fMatchLocator; 40 private ISearchScope fScope; 41 private TextSearchResultCollector fCollector; 42 private IStatus fStatus; 43 44 47 public TextSearchOperation(IWorkspace workspace, String pattern, boolean isCaseSensitive, boolean isRegexSearch, 48 ISearchScope scope, TextSearchResultCollector collector) { 49 super(null); 50 Assert.isNotNull(collector); 51 fWorkspace= workspace; 52 fMatchLocator= new MatchLocator(pattern, isCaseSensitive, isRegexSearch); 53 fScope= scope; 54 fCollector= collector; 55 fCollector.setOperation(this); 56 } 57 58 61 protected void execute(IProgressMonitor monitor) { 62 fCollector.setProgressMonitor(monitor); 63 TextSearchEngine engine= new TextSearchEngine(); 64 fStatus= engine.search(fWorkspace, fScope, false, fCollector, fMatchLocator); 65 } 66 67 void searchInFile(IFile file, ITextSearchResultCollector collector) { 68 TextSearchEngine engine= new TextSearchEngine(); 69 TextSearchScope scope= new TextSearchScope(""); scope.add(file); 71 scope.addExtension("*"); fStatus= engine.search(fWorkspace, scope, false, collector, fMatchLocator); 73 } 74 75 String getSingularLabel() { 76 String pattern= fMatchLocator.getPattern(); 77 if (pattern == null || pattern.length() < 1) 78 return SearchMessages.getFormattedString("FileSearchOperation.singularLabelPostfix", new String [] {fScope.getDescription()}); else 80 return SearchMessages.getFormattedString("TextSearchOperation.singularLabelPostfix", new String [] {fMatchLocator.getPattern(), fScope.getDescription()}); } 82 83 String getPluralLabelPattern() { 84 String pattern= fMatchLocator.getPattern(); 85 if (pattern == null || pattern.length() < 1) 86 return SearchMessages.getFormattedString("FileSearchOperation.pluralLabelPatternPostfix", new String [] {"{0}", fScope.getDescription()}); else 88 return SearchMessages.getFormattedString("TextSearchOperation.pluralLabelPatternPostfix", new String [] {fMatchLocator.getPattern(), "{0}", fScope.getDescription()}); } 90 91 ImageDescriptor getImageDescriptor() { 92 return SearchPluginImages.DESC_OBJ_TSEARCH_DPDN; 93 } 94 95 IStatus getStatus() { 96 return fStatus; 97 } 98 99 String getPattern() { 100 return fMatchLocator.getPattern(); 101 } 102 } 103 | Popular Tags |