Lines 17-23
Link Here
|
17 |
import java.io.IOException; |
17 |
import java.io.IOException; |
18 |
import java.io.StringReader; |
18 |
import java.io.StringReader; |
19 |
import java.util.ArrayList; |
19 |
import java.util.ArrayList; |
20 |
import java.util.HashSet; |
|
|
21 |
import java.util.Iterator; |
20 |
import java.util.Iterator; |
22 |
import java.util.List; |
21 |
import java.util.List; |
23 |
import java.util.regex.PatternSyntaxException; |
22 |
import java.util.regex.PatternSyntaxException; |
Lines 38-50
Link Here
|
38 |
|
37 |
|
39 |
import org.eclipse.core.runtime.Assert; |
38 |
import org.eclipse.core.runtime.Assert; |
40 |
import org.eclipse.core.runtime.CoreException; |
39 |
import org.eclipse.core.runtime.CoreException; |
41 |
import org.eclipse.core.runtime.IAdaptable; |
|
|
42 |
import org.eclipse.core.runtime.IStatus; |
40 |
import org.eclipse.core.runtime.IStatus; |
43 |
|
41 |
|
44 |
import org.eclipse.core.resources.IResource; |
|
|
45 |
import org.eclipse.core.resources.IWorkspaceRoot; |
46 |
import org.eclipse.core.resources.ResourcesPlugin; |
47 |
|
48 |
import org.eclipse.jface.dialogs.Dialog; |
42 |
import org.eclipse.jface.dialogs.Dialog; |
49 |
import org.eclipse.jface.dialogs.DialogPage; |
43 |
import org.eclipse.jface.dialogs.DialogPage; |
50 |
import org.eclipse.jface.dialogs.ErrorDialog; |
44 |
import org.eclipse.jface.dialogs.ErrorDialog; |
Lines 52-58
Link Here
|
52 |
import org.eclipse.jface.fieldassist.ComboContentAdapter; |
46 |
import org.eclipse.jface.fieldassist.ComboContentAdapter; |
53 |
import org.eclipse.jface.resource.JFaceColors; |
47 |
import org.eclipse.jface.resource.JFaceColors; |
54 |
import org.eclipse.jface.viewers.ISelection; |
48 |
import org.eclipse.jface.viewers.ISelection; |
55 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
|
56 |
|
49 |
|
57 |
import org.eclipse.jface.text.FindReplaceDocumentAdapter; |
50 |
import org.eclipse.jface.text.FindReplaceDocumentAdapter; |
58 |
import org.eclipse.jface.text.FindReplaceDocumentAdapterContentProposalProvider; |
51 |
import org.eclipse.jface.text.FindReplaceDocumentAdapterContentProposalProvider; |
Lines 71-78
Link Here
|
71 |
import org.eclipse.search.internal.ui.ISearchHelpContextIds; |
64 |
import org.eclipse.search.internal.ui.ISearchHelpContextIds; |
72 |
import org.eclipse.search.internal.ui.SearchMessages; |
65 |
import org.eclipse.search.internal.ui.SearchMessages; |
73 |
import org.eclipse.search.internal.ui.SearchPlugin; |
66 |
import org.eclipse.search.internal.ui.SearchPlugin; |
|
|
67 |
import org.eclipse.search.internal.ui.text.FileSearchScopeConfigurationBlock.FileSearchScopeConfigurationBlockListener; |
74 |
import org.eclipse.search.internal.ui.util.FileTypeEditor; |
68 |
import org.eclipse.search.internal.ui.util.FileTypeEditor; |
75 |
import org.eclipse.search.internal.ui.util.SWTUtil; |
|
|
76 |
import org.eclipse.search.ui.IReplacePage; |
69 |
import org.eclipse.search.ui.IReplacePage; |
77 |
import org.eclipse.search.ui.ISearchPage; |
70 |
import org.eclipse.search.ui.ISearchPage; |
78 |
import org.eclipse.search.ui.ISearchPageContainer; |
71 |
import org.eclipse.search.ui.ISearchPageContainer; |
Lines 103-122
Link Here
|
103 |
private boolean fFirstTime= true; |
96 |
private boolean fFirstTime= true; |
104 |
private boolean fIsCaseSensitive; |
97 |
private boolean fIsCaseSensitive; |
105 |
private boolean fIsRegExSearch; |
98 |
private boolean fIsRegExSearch; |
106 |
private boolean fSearchDerived; |
|
|
107 |
|
99 |
|
108 |
private Combo fPattern; |
100 |
private Combo fPattern; |
109 |
private Button fIsCaseSensitiveCheckbox; |
101 |
private Button fIsCaseSensitiveCheckbox; |
110 |
private Combo fExtensions; |
|
|
111 |
private Button fIsRegExCheckbox; |
102 |
private Button fIsRegExCheckbox; |
112 |
private CLabel fStatusLabel; |
103 |
private CLabel fStatusLabel; |
113 |
private Button fSearchDerivedCheckbox; |
|
|
114 |
|
104 |
|
115 |
private ISearchPageContainer fContainer; |
105 |
private ISearchPageContainer fContainer; |
116 |
private FileTypeEditor fFileTypeEditor; |
|
|
117 |
|
106 |
|
118 |
private ContentAssistCommandAdapter fPatterFieldContentAssist; |
107 |
private ContentAssistCommandAdapter fPatterFieldContentAssist; |
119 |
|
108 |
|
|
|
109 |
private FileSearchScopeConfigurationBlock fScopeConfigurationBlock; |
110 |
|
120 |
private static class SearchPatternData { |
111 |
private static class SearchPatternData { |
121 |
public final boolean isCaseSensitive; |
112 |
public final boolean isCaseSensitive; |
122 |
public final boolean isRegExSearch; |
113 |
public final boolean isRegExSearch; |
Lines 215-225
Link Here
|
215 |
} |
206 |
} |
216 |
} |
207 |
} |
217 |
|
208 |
|
|
|
209 |
public TextSearchPage() { |
210 |
fScopeConfigurationBlock= new FileSearchScopeConfigurationBlock(new FileSearchScopeConfigurationBlockListener() { |
211 |
public void extensionsTextChanged() { |
212 |
updateOKStatus(); |
213 |
} |
214 |
|
215 |
public void derivedSelectionChanged() { |
216 |
writeConfiguration(); |
217 |
} |
218 |
}); |
219 |
} |
220 |
|
218 |
//---- Action Handling ------------------------------------------------ |
221 |
//---- Action Handling ------------------------------------------------ |
219 |
|
222 |
|
220 |
private ISearchQuery newQuery() throws CoreException { |
223 |
private ISearchQuery newQuery() throws CoreException { |
221 |
SearchPatternData data= getPatternData(); |
224 |
SearchPatternData data= getPatternData(); |
222 |
TextSearchPageInput input= new TextSearchPageInput(data.textPattern, data.isCaseSensitive, data.isRegExSearch, createTextSearchScope()); |
225 |
TextSearchPageInput input= new TextSearchPageInput(data.textPattern, data.isCaseSensitive, data.isRegExSearch, fScopeConfigurationBlock.createTextSearchScope()); |
223 |
return TextSearchQueryProvider.getPreferred().createQuery(input); |
226 |
return TextSearchQueryProvider.getPreferred().createQuery(input); |
224 |
} |
227 |
} |
225 |
|
228 |
|
Lines 269-339
Link Here
|
269 |
return fPattern.getText(); |
272 |
return fPattern.getText(); |
270 |
} |
273 |
} |
271 |
|
274 |
|
272 |
public FileTextSearchScope createTextSearchScope() { |
|
|
273 |
// Setup search scope |
274 |
switch (getContainer().getSelectedScope()) { |
275 |
case ISearchPageContainer.WORKSPACE_SCOPE: |
276 |
return FileTextSearchScope.newWorkspaceScope(getExtensions(), fSearchDerived); |
277 |
case ISearchPageContainer.SELECTION_SCOPE: |
278 |
return getSelectedResourcesScope(); |
279 |
case ISearchPageContainer.SELECTED_PROJECTS_SCOPE: |
280 |
return getEnclosingProjectScope(); |
281 |
case ISearchPageContainer.WORKING_SET_SCOPE: |
282 |
IWorkingSet[] workingSets= getContainer().getSelectedWorkingSets(); |
283 |
return FileTextSearchScope.newSearchScope(workingSets, getExtensions(), fSearchDerived); |
284 |
default: |
285 |
// unknown scope |
286 |
return FileTextSearchScope.newWorkspaceScope(getExtensions(), fSearchDerived); |
287 |
} |
288 |
} |
289 |
|
290 |
private FileTextSearchScope getSelectedResourcesScope() { |
291 |
HashSet resources= new HashSet(); |
292 |
ISelection sel= getContainer().getSelection(); |
293 |
if (sel instanceof IStructuredSelection && !sel.isEmpty()) { |
294 |
Iterator iter= ((IStructuredSelection) sel).iterator(); |
295 |
while (iter.hasNext()) { |
296 |
Object curr= iter.next(); |
297 |
if (curr instanceof IWorkingSet) { |
298 |
IWorkingSet workingSet= (IWorkingSet) curr; |
299 |
if (workingSet.isAggregateWorkingSet() && workingSet.isEmpty()) { |
300 |
return FileTextSearchScope.newWorkspaceScope(getExtensions(), fSearchDerived); |
301 |
} |
302 |
IAdaptable[] elements= workingSet.getElements(); |
303 |
for (int i= 0; i < elements.length; i++) { |
304 |
IResource resource= (IResource)elements[i].getAdapter(IResource.class); |
305 |
if (resource != null && resource.isAccessible()) { |
306 |
resources.add(resource); |
307 |
} |
308 |
} |
309 |
} else if (curr instanceof IAdaptable) { |
310 |
IResource resource= (IResource) ((IAdaptable)curr).getAdapter(IResource.class); |
311 |
if (resource != null && resource.isAccessible()) { |
312 |
resources.add(resource); |
313 |
} |
314 |
} |
315 |
} |
316 |
} |
317 |
IResource[] arr= (IResource[]) resources.toArray(new IResource[resources.size()]); |
318 |
return FileTextSearchScope.newSearchScope(arr, getExtensions(), fSearchDerived); |
319 |
} |
320 |
|
321 |
private FileTextSearchScope getEnclosingProjectScope() { |
322 |
String[] enclosingProjectName= getContainer().getSelectedProjectNames(); |
323 |
if (enclosingProjectName == null) { |
324 |
return FileTextSearchScope.newWorkspaceScope(getExtensions(), fSearchDerived); |
325 |
} |
326 |
|
327 |
IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); |
328 |
IResource[] res= new IResource[enclosingProjectName.length]; |
329 |
for (int i= 0; i < res.length; i++) { |
330 |
res[i]= root.getProject(enclosingProjectName[i]); |
331 |
} |
332 |
|
333 |
return FileTextSearchScope.newSearchScope(res, getExtensions(), fSearchDerived); |
334 |
} |
335 |
|
336 |
|
337 |
private SearchPatternData findInPrevious(String pattern) { |
275 |
private SearchPatternData findInPrevious(String pattern) { |
338 |
for (Iterator iter= fPreviousSearchPatterns.iterator(); iter.hasNext();) { |
276 |
for (Iterator iter= fPreviousSearchPatterns.iterator(); iter.hasNext();) { |
339 |
SearchPatternData element= (SearchPatternData) iter.next(); |
277 |
SearchPatternData element= (SearchPatternData) iter.next(); |
Lines 358-364
Link Here
|
358 |
getPattern(), |
296 |
getPattern(), |
359 |
isCaseSensitive(), |
297 |
isCaseSensitive(), |
360 |
fIsRegExCheckbox.getSelection(), |
298 |
fIsRegExCheckbox.getSelection(), |
361 |
getExtensions(), |
299 |
fScopeConfigurationBlock.getExtensions(), |
362 |
getContainer().getSelectedScope(), |
300 |
getContainer().getSelectedScope(), |
363 |
getContainer().getSelectedWorkingSets()); |
301 |
getContainer().getSelectedWorkingSets()); |
364 |
fPreviousSearchPatterns.add(0, match); |
302 |
fPreviousSearchPatterns.add(0, match); |
Lines 385-394
Link Here
|
385 |
return patterns; |
323 |
return patterns; |
386 |
} |
324 |
} |
387 |
|
325 |
|
388 |
private String[] getExtensions() { |
|
|
389 |
return fFileTypeEditor.getFileTypes(); |
390 |
} |
391 |
|
392 |
private boolean isCaseSensitive() { |
326 |
private boolean isCaseSensitive() { |
393 |
return fIsCaseSensitiveCheckbox.getSelection(); |
327 |
return fIsCaseSensitiveCheckbox.getSelection(); |
394 |
} |
328 |
} |
Lines 402-414
Link Here
|
402 |
fFirstTime= false; |
336 |
fFirstTime= false; |
403 |
// Set item and text here to prevent page from resizing |
337 |
// Set item and text here to prevent page from resizing |
404 |
fPattern.setItems(getPreviousSearchPatterns()); |
338 |
fPattern.setItems(getPreviousSearchPatterns()); |
405 |
fExtensions.setItems(getPreviousExtensions()); |
339 |
fScopeConfigurationBlock.setExtensions(getPreviousExtensions()); |
406 |
// if (fExtensions.getItemCount() == 0) { |
340 |
// if (fExtensions.getItemCount() == 0) { |
407 |
// loadFilePatternDefaults(); |
341 |
// loadFilePatternDefaults(); |
408 |
// } |
342 |
// } |
409 |
if (!initializePatternControl()) { |
343 |
if (!initializePatternControl()) { |
410 |
fPattern.select(0); |
344 |
fPattern.select(0); |
411 |
fExtensions.setText("*"); //$NON-NLS-1$ |
345 |
fScopeConfigurationBlock.setExtensionsText("*"); //$NON-NLS-1$ |
412 |
handleWidgetSelected(); |
346 |
handleWidgetSelected(); |
413 |
} |
347 |
} |
414 |
} |
348 |
} |
Lines 420-426
Link Here
|
420 |
|
354 |
|
421 |
final void updateOKStatus() { |
355 |
final void updateOKStatus() { |
422 |
boolean regexStatus= validateRegex(); |
356 |
boolean regexStatus= validateRegex(); |
423 |
boolean hasFilePattern= fExtensions.getText().length() > 0; |
357 |
boolean hasFilePattern= fScopeConfigurationBlock.getExtensionsText().length() > 0; |
424 |
getContainer().setPerformActionEnabled(regexStatus && hasFilePattern); |
358 |
getContainer().setPerformActionEnabled(regexStatus && hasFilePattern); |
425 |
} |
359 |
} |
426 |
|
360 |
|
Lines 443-449
Link Here
|
443 |
data.heightHint= convertHeightInCharsToPixels(1) / 3; |
377 |
data.heightHint= convertHeightInCharsToPixels(1) / 3; |
444 |
separator.setLayoutData(data); |
378 |
separator.setLayoutData(data); |
445 |
|
379 |
|
446 |
addFileNameControls(result); |
380 |
fScopeConfigurationBlock.createControl(result); |
447 |
|
381 |
|
448 |
setControl(result); |
382 |
setControl(result); |
449 |
Dialog.applyDialogFont(result); |
383 |
Dialog.applyDialogFont(result); |
Lines 558-564
Link Here
|
558 |
fIsCaseSensitiveCheckbox.setSelection(patternData.isCaseSensitive); |
492 |
fIsCaseSensitiveCheckbox.setSelection(patternData.isCaseSensitive); |
559 |
fIsRegExCheckbox.setSelection(patternData.isRegExSearch); |
493 |
fIsRegExCheckbox.setSelection(patternData.isRegExSearch); |
560 |
fPattern.setText(patternData.textPattern); |
494 |
fPattern.setText(patternData.textPattern); |
561 |
fFileTypeEditor.setFileTypes(patternData.fileNamePatterns); |
495 |
fScopeConfigurationBlock.setFileTypes(patternData.fileNamePatterns); |
562 |
if (patternData.workingSets != null) |
496 |
if (patternData.workingSets != null) |
563 |
getContainer().setSelectedWorkingSets(patternData.workingSets); |
497 |
getContainer().setSelectedWorkingSets(patternData.workingSets); |
564 |
else |
498 |
else |
Lines 576-588
Link Here
|
576 |
fPattern.setText(insertEscapeChars(text)); |
510 |
fPattern.setText(insertEscapeChars(text)); |
577 |
|
511 |
|
578 |
if (getPreviousExtensions().length > 0) { |
512 |
if (getPreviousExtensions().length > 0) { |
579 |
fExtensions.setText(getPreviousExtensions()[0]); |
513 |
fScopeConfigurationBlock.setExtensionsText(getPreviousExtensions()[0]); |
580 |
} else { |
514 |
} else { |
581 |
String extension= getExtensionFromEditor(); |
515 |
String extension= getExtensionFromEditor(); |
582 |
if (extension != null) |
516 |
if (extension != null) |
583 |
fExtensions.setText(extension); |
517 |
fScopeConfigurationBlock.setExtensionsText(extension); |
584 |
else |
518 |
else |
585 |
fExtensions.setText("*"); //$NON-NLS-1$ |
519 |
fScopeConfigurationBlock.setExtensionsText("*"); //$NON-NLS-1$ |
586 |
} |
520 |
} |
587 |
return true; |
521 |
return true; |
588 |
} |
522 |
} |
Lines 634-694
Link Here
|
634 |
return null; |
568 |
return null; |
635 |
} |
569 |
} |
636 |
|
570 |
|
637 |
private void addFileNameControls(Composite group) { |
|
|
638 |
// grid layout with 2 columns |
639 |
|
640 |
// Line with label, combo and button |
641 |
Label label= new Label(group, SWT.LEAD); |
642 |
label.setText(SearchMessages.SearchPage_fileNamePatterns_text); |
643 |
label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1)); |
644 |
label.setFont(group.getFont()); |
645 |
|
646 |
fExtensions= new Combo(group, SWT.SINGLE | SWT.BORDER); |
647 |
fExtensions.addModifyListener(new ModifyListener() { |
648 |
public void modifyText(ModifyEvent e) { |
649 |
updateOKStatus(); |
650 |
} |
651 |
}); |
652 |
GridData data= new GridData(GridData.FILL, GridData.FILL, true, false, 1, 1); |
653 |
data.widthHint= convertWidthInCharsToPixels(50); |
654 |
fExtensions.setLayoutData(data); |
655 |
fExtensions.setFont(group.getFont()); |
656 |
|
657 |
Button button= new Button(group, SWT.PUSH); |
658 |
button.setText(SearchMessages.SearchPage_browse); |
659 |
GridData gridData= new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 1, 1); |
660 |
gridData.widthHint= SWTUtil.getButtonWidthHint(button); |
661 |
button.setLayoutData(gridData); |
662 |
button.setFont(group.getFont()); |
663 |
|
664 |
fFileTypeEditor= new FileTypeEditor(fExtensions, button); |
665 |
|
666 |
// Text line which explains the special characters |
667 |
Label description= new Label(group, SWT.LEAD); |
668 |
description.setText(SearchMessages.SearchPage_fileNamePatterns_hint); |
669 |
description.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1)); |
670 |
description.setFont(group.getFont()); |
671 |
|
672 |
fSearchDerivedCheckbox= new Button(group, SWT.CHECK); |
673 |
fSearchDerivedCheckbox.setText(SearchMessages.TextSearchPage_searchDerived_label); |
674 |
|
675 |
fSearchDerivedCheckbox.setSelection(fSearchDerived); |
676 |
fSearchDerivedCheckbox.addSelectionListener(new SelectionAdapter() { |
677 |
public void widgetSelected(SelectionEvent e) { |
678 |
fSearchDerived= fSearchDerivedCheckbox.getSelection(); |
679 |
writeConfiguration(); |
680 |
} |
681 |
}); |
682 |
fSearchDerivedCheckbox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1)); |
683 |
fSearchDerivedCheckbox.setFont(group.getFont()); |
684 |
} |
685 |
|
686 |
/** |
571 |
/** |
687 |
* Sets the search page's container. |
572 |
* Sets the search page's container. |
688 |
* @param container the container to set |
573 |
* @param container the container to set |
689 |
*/ |
574 |
*/ |
690 |
public void setContainer(ISearchPageContainer container) { |
575 |
public void setContainer(ISearchPageContainer container) { |
691 |
fContainer= container; |
576 |
fContainer= container; |
|
|
577 |
fScopeConfigurationBlock.setContainer(container); |
692 |
} |
578 |
} |
693 |
|
579 |
|
694 |
private ISearchPageContainer getContainer() { |
580 |
private ISearchPageContainer getContainer() { |
Lines 727-733
Link Here
|
727 |
IDialogSettings s= getDialogSettings(); |
613 |
IDialogSettings s= getDialogSettings(); |
728 |
fIsCaseSensitive= s.getBoolean(STORE_CASE_SENSITIVE); |
614 |
fIsCaseSensitive= s.getBoolean(STORE_CASE_SENSITIVE); |
729 |
fIsRegExSearch= s.getBoolean(STORE_IS_REG_EX_SEARCH); |
615 |
fIsRegExSearch= s.getBoolean(STORE_IS_REG_EX_SEARCH); |
730 |
fSearchDerived= s.getBoolean(STORE_SEARCH_DERIVED); |
616 |
fScopeConfigurationBlock.setSearchDerived(s.getBoolean(STORE_SEARCH_DERIVED)); |
731 |
|
617 |
|
732 |
try { |
618 |
try { |
733 |
int historySize= s.getInt(STORE_HISTORY_SIZE); |
619 |
int historySize= s.getInt(STORE_HISTORY_SIZE); |
Lines 752-758
Link Here
|
752 |
IDialogSettings s= getDialogSettings(); |
638 |
IDialogSettings s= getDialogSettings(); |
753 |
s.put(STORE_CASE_SENSITIVE, fIsCaseSensitive); |
639 |
s.put(STORE_CASE_SENSITIVE, fIsCaseSensitive); |
754 |
s.put(STORE_IS_REG_EX_SEARCH, fIsRegExSearch); |
640 |
s.put(STORE_IS_REG_EX_SEARCH, fIsRegExSearch); |
755 |
s.put(STORE_SEARCH_DERIVED, fSearchDerived); |
641 |
s.put(STORE_SEARCH_DERIVED, fScopeConfigurationBlock.getSearchDerived()); |
756 |
|
642 |
|
757 |
int historySize= Math.min(fPreviousSearchPatterns.size(), HISTORY_SIZE); |
643 |
int historySize= Math.min(fPreviousSearchPatterns.size(), HISTORY_SIZE); |
758 |
s.put(STORE_HISTORY_SIZE, historySize); |
644 |
s.put(STORE_HISTORY_SIZE, historySize); |