View | Details | Raw Unified | Return to bug 191432
Collapse All | Expand All

(-)search/org/eclipse/search/internal/ui/text/FileSearchQuery.java (-2 / +8 lines)
Lines 29-42 Link Here
29
import org.eclipse.search.internal.core.text.PatternConstructor;
29
import org.eclipse.search.internal.core.text.PatternConstructor;
30
import org.eclipse.search.internal.ui.Messages;
30
import org.eclipse.search.internal.ui.Messages;
31
import org.eclipse.search.internal.ui.SearchMessages;
31
import org.eclipse.search.internal.ui.SearchMessages;
32
import org.eclipse.search.ui.ISearchQuery;
33
import org.eclipse.search.ui.ISearchResult;
32
import org.eclipse.search.ui.ISearchResult;
34
import org.eclipse.search.ui.text.AbstractTextSearchResult;
33
import org.eclipse.search.ui.text.AbstractTextSearchResult;
35
import org.eclipse.search.ui.text.FileTextSearchScope;
34
import org.eclipse.search.ui.text.FileTextSearchScope;
36
import org.eclipse.search.ui.text.Match;
35
import org.eclipse.search.ui.text.Match;
37
36
38
37
39
public class FileSearchQuery implements ISearchQuery {
38
public class FileSearchQuery implements IFileSearchQuery {
40
39
41
	private final static class TextSearchResultCollector extends TextSearchRequestor {
40
	private final static class TextSearchResultCollector extends TextSearchRequestor {
42
41
Lines 275-278 Link Here
275
		}
274
		}
276
		return fResult;
275
		return fResult;
277
	}
276
	}
277
	
278
	/** 
279
	 * {@inheritDoc}
280
	 */
281
	public boolean isShowLineMatches() {
282
		return !isFileNameSearch();
283
	}
278
}
284
}
(-)search/org/eclipse/search/internal/ui/text/FileTreeContentProvider.java (-1 / +1 lines)
Lines 71-77 Link Here
71
	private synchronized void initialize(AbstractTextSearchResult result) {
71
	private synchronized void initialize(AbstractTextSearchResult result) {
72
		fResult= result;
72
		fResult= result;
73
		fChildrenMap= new HashMap();
73
		fChildrenMap= new HashMap();
74
		boolean showLineMatches= !((FileSearchQuery) fResult.getQuery()).isFileNameSearch();
74
		boolean showLineMatches= ((IFileSearchQuery) fResult.getQuery()).isShowLineMatches();
75
		
75
		
76
		if (result != null) {
76
		if (result != null) {
77
			Object[] elements= result.getElements();
77
			Object[] elements= result.getElements();
(-)search/org/eclipse/search/internal/ui/text/FileSearchPage.java (-3 / +4 lines)
Lines 51-56 Link Here
51
import org.eclipse.search.internal.ui.Messages;
51
import org.eclipse.search.internal.ui.Messages;
52
import org.eclipse.search.internal.ui.SearchMessages;
52
import org.eclipse.search.internal.ui.SearchMessages;
53
import org.eclipse.search.ui.IContextMenuConstants;
53
import org.eclipse.search.ui.IContextMenuConstants;
54
import org.eclipse.search.ui.ISearchQuery;
54
import org.eclipse.search.ui.ISearchResultViewPart;
55
import org.eclipse.search.ui.ISearchResultViewPart;
55
import org.eclipse.search.ui.text.AbstractTextSearchResult;
56
import org.eclipse.search.ui.text.AbstractTextSearchResult;
56
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
57
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
Lines 198-205 Link Here
198
		addSortActions(mgr);
199
		addSortActions(mgr);
199
		fActionGroup.setContext(new ActionContext(getSite().getSelectionProvider().getSelection()));
200
		fActionGroup.setContext(new ActionContext(getSite().getSelectionProvider().getSelection()));
200
		fActionGroup.fillContextMenu(mgr);
201
		fActionGroup.fillContextMenu(mgr);
201
		FileSearchQuery query= (FileSearchQuery) getInput().getQuery();
202
		ISearchQuery query= getInput().getQuery();
202
		if (query.getSearchString().length() > 0) {
203
		if (query instanceof FileSearchQuery && ((FileSearchQuery) query).getSearchString().length() > 0) {
203
			IStructuredSelection selection= (IStructuredSelection) getViewer().getSelection();
204
			IStructuredSelection selection= (IStructuredSelection) getViewer().getSelection();
204
			if (!selection.isEmpty()) {
205
			if (!selection.isEmpty()) {
205
				ReplaceAction replaceSelection= new ReplaceAction(getSite().getShell(), (FileSearchResult) getInput(), selection.toArray(), true);
206
				ReplaceAction replaceSelection= new ReplaceAction(getSite().getShell(), (FileSearchResult) getInput(), selection.toArray(), true);
Lines 355-361 Link Here
355
356
356
	private boolean showLineMatches() {
357
	private boolean showLineMatches() {
357
		AbstractTextSearchResult input= getInput();
358
		AbstractTextSearchResult input= getInput();
358
		return getLayout() == FLAG_LAYOUT_TREE && input != null && !((FileSearchQuery) input.getQuery()).isFileNameSearch();
359
		return getLayout() == FLAG_LAYOUT_TREE && input != null && ((IFileSearchQuery) input.getQuery()).isShowLineMatches();
359
	}
360
	}
360
361
361
}
362
}
(-)search/org/eclipse/search/internal/ui/text/TextSearchPage.java (-142 / +28 lines)
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);
(-)search/org/eclipse/search/internal/ui/text/FileSearchResult.java (-2 / +2 lines)
Lines 28-36 Link Here
28
public class FileSearchResult extends AbstractTextSearchResult implements IEditorMatchAdapter, IFileMatchAdapter {
28
public class FileSearchResult extends AbstractTextSearchResult implements IEditorMatchAdapter, IFileMatchAdapter {
29
	private final Match[] EMPTY_ARR= new Match[0];
29
	private final Match[] EMPTY_ARR= new Match[0];
30
30
31
	private FileSearchQuery fQuery;
31
	private IFileSearchQuery fQuery;
32
32
33
	public FileSearchResult(FileSearchQuery job) {
33
	public FileSearchResult(IFileSearchQuery job) {
34
		fQuery= job;
34
		fQuery= job;
35
	}
35
	}
36
	public ImageDescriptor getImageDescriptor() {
36
	public ImageDescriptor getImageDescriptor() {
(-)search/org/eclipse/search/internal/ui/SearchMessages.properties (+9 lines)
Lines 230-235 Link Here
230
SelectAllAction_label= Select A&ll
230
SelectAllAction_label= Select A&ll
231
SelectAllAction_tooltip= Select All
231
SelectAllAction_tooltip= Select All
232
232
233
SpellingSearchPage_spellingEngineDropDown_label=Spelling Engine:
234
SpellingSearchPage_spellingEnginePreferencePage_link=Configure the spelling engines on the <a>Spelling Preference Page</a>.
235
SpellingSearchQuery_query_label=Spelling Problems Search
236
SpellingSearchQuery_result11_label=1 spelling problem in 1 file
237
SpellingSearchQuery_result1n_label={0} spelling problem in {1} files
238
SpellingSearchQuery_resultn1_label={0} spelling problems in 1 file
239
SpellingSearchQuery_resultnn_label={0} spelling problems in {1} files
240
SpellingSearchResultPage_fixProblemMenu_label=Fix Spelling Problem
241
233
RemovePotentialMatchesAction_removePotentialMatch_text= Remove Potential Match
242
RemovePotentialMatchesAction_removePotentialMatch_text= Remove Potential Match
234
RemovePotentialMatchesAction_removePotentialMatch_tooltip= Remove Potential Match
243
RemovePotentialMatchesAction_removePotentialMatch_tooltip= Remove Potential Match
235
RemovePotentialMatchesAction_removePotentialMatches_text= Remove potential Matches
244
RemovePotentialMatchesAction_removePotentialMatches_text= Remove potential Matches
(-)search/org/eclipse/search/internal/ui/SearchMessages.java (+11 lines)
Lines 196-201 Link Here
196
	public static String RemovePotentialMatchesAction_dialog_title;
196
	public static String RemovePotentialMatchesAction_dialog_title;
197
	public static String RemovePotentialMatchesAction_dialog_message;
197
	public static String RemovePotentialMatchesAction_dialog_message;
198
	public static String OpenWithMenu_label;
198
	public static String OpenWithMenu_label;
199
	
200
	public static String SpellingSearchPage_spellingEngineDropDown_label;
201
	public static String SpellingSearchPage_spellingEnginePreferencePage_link;
202
	public static String SpellingSearchQuery_query_label;
203
	public static String SpellingSearchQuery_result11_label;
204
	public static String SpellingSearchQuery_result1n_label;
205
	public static String SpellingSearchQuery_resultn1_label;
206
	public static String SpellingSearchQuery_resultnn_label;
207
	public static String SpellingSearchResultPage_fixProblemMenu_label;
208
	
209
	
199
	static {
210
	static {
200
		NLS.initializeMessages(BUNDLE_NAME, SearchMessages.class);
211
		NLS.initializeMessages(BUNDLE_NAME, SearchMessages.class);
201
	}
212
	}
(-)plugin.xml (+26 lines)
Lines 394-397 Link Here
394
       point="org.eclipse.core.runtime.preferences">
394
       point="org.eclipse.core.runtime.preferences">
395
    <initializer class="org.eclipse.search.internal.ui.SearchPreferenceInitializer"/>
395
    <initializer class="org.eclipse.search.internal.ui.SearchPreferenceInitializer"/>
396
 </extension>
396
 </extension>
397
 
398
 <!--
399
 			Spelling Problem Search
400
 -->
401
 
402
    <extension
403
         point="org.eclipse.search.searchPages">
404
      <page
405
            canSearchEnclosingProjects="true"
406
            class="org.eclipse.search.internal.ui.spelling.SpellingSearchPage"
407
            enabled="true"
408
            id="org.eclipse.ui.workbench.texteditor.spelling.searchPage"
409
            label="Spelling Problems"
410
            showScopeSection="true">
411
      </page>
412
   </extension>
413
   
414
   <extension
415
         point="org.eclipse.search.searchResultViewPages">
416
      <viewPage
417
            class="org.eclipse.search.internal.ui.spelling.SpellingSearchResultPage"
418
            id="org.eclipse.ui.workbench.texteditor.spelling.searchResultPage"
419
            searchResultClass="org.eclipse.search.internal.ui.spelling.SpellingSearchResult">
420
      </viewPage>
421
   </extension>
422
   
397
</plugin>
423
</plugin>
(-)search/org/eclipse/search/internal/ui/spelling/SpellingSearchPage.java (+138 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.search.internal.ui.spelling;
12
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.events.SelectionAdapter;
15
import org.eclipse.swt.events.SelectionEvent;
16
import org.eclipse.swt.layout.GridData;
17
import org.eclipse.swt.layout.GridLayout;
18
import org.eclipse.swt.widgets.Combo;
19
import org.eclipse.swt.widgets.Composite;
20
import org.eclipse.swt.widgets.Label;
21
import org.eclipse.swt.widgets.Link;
22
23
import org.eclipse.jface.dialogs.DialogPage;
24
import org.eclipse.jface.preference.PreferenceDialog;
25
import org.eclipse.jface.preference.PreferenceStore;
26
27
import org.eclipse.ui.dialogs.PreferencesUtil;
28
29
import org.eclipse.ui.texteditor.spelling.SpellingEngineDescriptor;
30
import org.eclipse.ui.texteditor.spelling.SpellingService;
31
32
import org.eclipse.search.internal.ui.SearchMessages;
33
import org.eclipse.search.internal.ui.text.FileSearchScopeConfigurationBlock;
34
import org.eclipse.search.internal.ui.text.FileSearchScopeConfigurationBlock.FileSearchScopeConfigurationBlockListener;
35
import org.eclipse.search.ui.ISearchPage;
36
import org.eclipse.search.ui.ISearchPageContainer;
37
import org.eclipse.search.ui.NewSearchUI;
38
39
public class SpellingSearchPage extends DialogPage implements ISearchPage {
40
	
41
	private final SpellingEngineDescriptor[] fSpellingEngines;
42
43
	private SpellingEngineDescriptor fSelectedEngine;
44
	private FileSearchScopeConfigurationBlock fScopeConfigurationBlock;
45
	private ISearchPageContainer fContainer;
46
47
	public SpellingSearchPage() {
48
		fScopeConfigurationBlock= new FileSearchScopeConfigurationBlock(new FileSearchScopeConfigurationBlockListener() {
49
			public void extensionsTextChanged() {
50
				boolean hasFilePattern= fScopeConfigurationBlock.getExtensionsText().length() > 0;
51
				fContainer.setPerformActionEnabled(hasFilePattern);
52
			}
53
54
			public void derivedSelectionChanged() {
55
			}
56
		});
57
58
		SpellingService spellingService= new SpellingService(new PreferenceStore());
59
		fSpellingEngines= spellingService.getSpellingEngineDescriptors();
60
		fSelectedEngine= spellingService.getDefaultSpellingEngineDescriptor();
61
	}
62
63
	/** 
64
	 * {@inheritDoc}
65
	 */
66
	public boolean performAction() {
67
		SpellingSearchQuery query= new SpellingSearchQuery(fScopeConfigurationBlock.createTextSearchScope(), fSelectedEngine.getId());
68
		NewSearchUI.runQueryInBackground(query);
69
		return true;
70
	}
71
72
	/** 
73
	 * {@inheritDoc}
74
	 */
75
	public void setContainer(ISearchPageContainer container) {
76
		fContainer= container;
77
		fScopeConfigurationBlock.setContainer(container);
78
	}
79
	
80
	/** 
81
	 * {@inheritDoc}
82
	 */
83
	public void createControl(Composite parent) {
84
		initializeDialogUnits(parent);
85
86
		Composite control= new Composite(parent, SWT.NONE);
87
		control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
88
		control.setLayout(new GridLayout(2, false));
89
90
		if (fSpellingEngines.length > 1) {
91
			Label label= new Label(control, SWT.NONE);
92
			label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 2, 1));
93
			label.setText(SearchMessages.SpellingSearchPage_spellingEngineDropDown_label);
94
95
			final Combo combo= new Combo(control, SWT.DROP_DOWN | SWT.READ_ONLY);
96
			combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
97
98
			int index= 0;
99
			String[] items= new String[fSpellingEngines.length];
100
			for (int i= 0; i < items.length; i++) {
101
				items[i]= fSpellingEngines[i].getLabel();
102
				if (fSpellingEngines[i] == fSelectedEngine)
103
					index= i;
104
			}
105
			combo.setItems(items);
106
			combo.select(index);
107
			combo.addSelectionListener(new SelectionAdapter() {
108
				/**
109
				 * {@inheritDoc}
110
				 */
111
				public void widgetSelected(SelectionEvent e) {
112
					fSelectedEngine= fSpellingEngines[combo.getSelectionIndex()];
113
				}
114
			});
115
		}
116
117
		fScopeConfigurationBlock.createControl(control);
118
		fScopeConfigurationBlock.setExtensionsText("*"); //$NON-NLS-1$
119
120
		Link link= new Link(control, SWT.NONE);
121
		GridData layoutData= new GridData(SWT.END, SWT.CENTER, false, false, 2, 1);
122
		layoutData.verticalIndent= 15;
123
		link.setLayoutData(layoutData);
124
		link.setText(SearchMessages.SpellingSearchPage_spellingEnginePreferencePage_link);
125
		link.addSelectionListener(new SelectionAdapter() {
126
			/**
127
			 * {@inheritDoc}
128
			 */
129
			public void widgetSelected(SelectionEvent e) {
130
				PreferenceDialog dialog= PreferencesUtil.createPreferenceDialogOn(getShell(), "org.eclipse.ui.editors.preferencePages.Spelling", new String[0], null); //$NON-NLS-1$
131
				dialog.open();
132
			}
133
		});
134
135
		setControl(control);
136
	}
137
138
}
(-)search/org/eclipse/search/internal/ui/spelling/SpellingSearchResult.java (+21 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.search.internal.ui.spelling;
12
13
import org.eclipse.search.internal.ui.text.FileSearchResult;
14
15
public class SpellingSearchResult extends FileSearchResult {
16
17
	public SpellingSearchResult(SpellingSearchQuery query) {
18
		super(query);
19
	}
20
	
21
}
(-)search/org/eclipse/search/internal/ui/text/IFileSearchQuery.java (+19 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.search.internal.ui.text;
12
13
import org.eclipse.search.ui.ISearchQuery;
14
15
public interface IFileSearchQuery extends ISearchQuery {
16
	public String getResultLabel(int nMatches);
17
	
18
	public boolean isShowLineMatches();
19
}
(-)search/org/eclipse/search/internal/ui/spelling/SpellingLineElement.java (+30 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.search.internal.ui.spelling;
12
13
import org.eclipse.core.resources.IFile;
14
15
import org.eclipse.ui.texteditor.spelling.SpellingProblem;
16
17
import org.eclipse.search.internal.ui.text.LineElement;
18
19
public class SpellingLineElement extends LineElement {
20
	private final SpellingProblem fProblem;
21
	
22
	public SpellingLineElement(IFile parent, int lineNumber, int lineStartOffset, String lineContent, SpellingProblem problem) {
23
		super(parent, lineNumber, lineStartOffset, lineContent);
24
		fProblem= problem;
25
	}
26
	
27
	public SpellingProblem getProblem() {
28
		return fProblem;
29
	}
30
}
(-)search/org/eclipse/search/internal/ui/spelling/SpellingSearchQuery.java (+189 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.search.internal.ui.spelling;
12
13
import java.util.regex.Pattern;
14
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.NullProgressMonitor;
19
import org.eclipse.core.runtime.OperationCanceledException;
20
import org.eclipse.core.runtime.Status;
21
22
import org.eclipse.core.resources.IFile;
23
24
import org.eclipse.core.filebuffers.FileBuffers;
25
import org.eclipse.core.filebuffers.ITextFileBuffer;
26
import org.eclipse.core.filebuffers.ITextFileBufferManager;
27
import org.eclipse.core.filebuffers.LocationKind;
28
29
import org.eclipse.jface.preference.PreferenceStore;
30
31
import org.eclipse.jface.text.BadLocationException;
32
import org.eclipse.jface.text.IDocument;
33
34
import org.eclipse.ui.texteditor.spelling.ISpellingProblemCollector;
35
import org.eclipse.ui.texteditor.spelling.SpellingContext;
36
import org.eclipse.ui.texteditor.spelling.SpellingProblem;
37
import org.eclipse.ui.texteditor.spelling.SpellingService;
38
39
import org.eclipse.search.core.text.TextSearchEngine;
40
import org.eclipse.search.core.text.TextSearchRequestor;
41
import org.eclipse.search.internal.ui.Messages;
42
import org.eclipse.search.internal.ui.SearchMessages;
43
import org.eclipse.search.internal.ui.SearchPlugin;
44
import org.eclipse.search.internal.ui.text.IFileSearchQuery;
45
import org.eclipse.search.internal.ui.text.LineElement;
46
import org.eclipse.search.internal.ui.text.SearchResultUpdater;
47
import org.eclipse.search.ui.ISearchResult;
48
import org.eclipse.search.ui.text.FileTextSearchScope;
49
50
public class SpellingSearchQuery implements IFileSearchQuery {
51
	
52
	private static class SpellingSearchRequestor extends TextSearchRequestor {
53
		
54
		private final SpellingSearchResult fResult;
55
		private SpellingService fSpellingService;
56
		
57
		public SpellingSearchRequestor(SpellingSearchResult result, SpellingService spellingService) {
58
			fResult= result;
59
			fSpellingService= spellingService;
60
		}
61
		
62
		/** 
63
		 * {@inheritDoc}
64
		 */
65
		public boolean acceptFile(final IFile file) throws CoreException {
66
			ITextFileBufferManager bufferManager= FileBuffers.getTextFileBufferManager();
67
			bufferManager.connect(file.getFullPath(), LocationKind.IFILE, new NullProgressMonitor());
68
			try {
69
				ITextFileBuffer buffer= bufferManager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
70
71
				SpellingContext context= new SpellingContext();
72
				context.setContentType(buffer.getContentType());
73
74
				final IDocument document= buffer.getDocument();
75
				fSpellingService.check(document, context, new ISpellingProblemCollector() {
76
					
77
					public void endCollecting() {
78
					}
79
					
80
					public void beginCollecting() {
81
					}
82
					
83
					public void accept(SpellingProblem problem) {
84
						try {
85
							int lineNumber= document.getLineOfOffset(problem.getOffset());
86
							int lineStartOffset= document.getLineOffset(lineNumber);
87
							int lineLength= document.getLineLength(lineNumber);
88
							LineElement lineElement= new SpellingLineElement(file, lineNumber, lineStartOffset, document.get(lineStartOffset, lineLength), problem);
89
							fResult.addMatch(new SpellingSearchMatch(file, problem, lineElement));
90
						} catch (BadLocationException e) {
91
							SearchPlugin.log(e);
92
						}
93
					}
94
					
95
				}, new NullProgressMonitor());
96
			} finally {
97
				bufferManager.disconnect(file.getFullPath(), LocationKind.IFILE, new NullProgressMonitor());
98
			}
99
			return true;
100
		}
101
	}
102
103
	private final FileTextSearchScope fScope;
104
105
	private final String fSpellingEngineId;
106
	private SpellingSearchResult fResult;
107
	
108
	public SpellingSearchQuery(FileTextSearchScope scope, String spellingEngineId) {
109
		fScope= scope;
110
		fSpellingEngineId= spellingEngineId;
111
	}
112
113
	/**
114
	 * {@inheritDoc}
115
	 */
116
	public ISearchResult getSearchResult() {
117
		if (fResult == null) {
118
			fResult= new SpellingSearchResult(this);
119
			new SearchResultUpdater(fResult);
120
		}
121
		return fResult;
122
	}
123
124
	/** 
125
	 * {@inheritDoc}
126
	 */
127
	public boolean canRerun() {
128
		return true;
129
	}
130
	
131
	/** 
132
	 * {@inheritDoc}
133
	 */
134
	public boolean canRunInBackground() {
135
		return true;
136
	}
137
	
138
	/** 
139
	 * {@inheritDoc}
140
	 */
141
	public String getLabel() {
142
		return SearchMessages.SpellingSearchQuery_query_label;
143
	}
144
	
145
	/** 
146
	 * {@inheritDoc}
147
	 */
148
	public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
149
		SpellingSearchResult searchResult= (SpellingSearchResult)getSearchResult();
150
		searchResult.removeAll();
151
152
		PreferenceStore store= new PreferenceStore();
153
		store.setValue(SpellingService.PREFERENCE_SPELLING_ENABLED, true);
154
		store.setValue(SpellingService.PREFERENCE_SPELLING_ENGINE, fSpellingEngineId);
155
156
		SpellingService spellingService= new SpellingService(store);
157
158
		TextSearchEngine engine= TextSearchEngine.create();
159
		engine.search(fScope, new SpellingSearchRequestor(searchResult, spellingService), Pattern.compile(""), monitor); //$NON-NLS-1$
160
161
		return Status.OK_STATUS;
162
	}
163
	
164
	/** 
165
	 * {@inheritDoc}
166
	 */
167
	public String getResultLabel(int matchesCount) {
168
		int fileCount= fResult.getElements().length;
169
170
		Object[] args= new Object[] { new Integer(matchesCount), new Integer(fileCount) };
171
		if (fileCount == 1 && matchesCount == 1) {
172
			return SearchMessages.SpellingSearchQuery_result11_label;
173
		} else if (fileCount == 1) {
174
			return Messages.format(SearchMessages.SpellingSearchQuery_resultn1_label, args);
175
		} else if (matchesCount == 1) {
176
			return Messages.format(SearchMessages.SpellingSearchQuery_result1n_label, args);
177
		} else {
178
			return Messages.format(SearchMessages.SpellingSearchQuery_resultnn_label, args);
179
		}
180
	}
181
	
182
	/** 
183
	 * {@inheritDoc}
184
	 */
185
	public boolean isShowLineMatches() {
186
		return true;
187
	}
188
	
189
}
(-)search/org/eclipse/search/internal/ui/spelling/SpellingSearchResultPage.java (+125 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.search.internal.ui.spelling;
12
13
import org.eclipse.swt.graphics.ImageData;
14
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.NullProgressMonitor;
17
18
import org.eclipse.core.resources.IResource;
19
20
import org.eclipse.core.filebuffers.FileBuffers;
21
import org.eclipse.core.filebuffers.ITextFileBuffer;
22
import org.eclipse.core.filebuffers.ITextFileBufferManager;
23
import org.eclipse.core.filebuffers.LocationKind;
24
25
import org.eclipse.jface.action.Action;
26
import org.eclipse.jface.action.IMenuManager;
27
import org.eclipse.jface.action.MenuManager;
28
import org.eclipse.jface.resource.ImageDescriptor;
29
import org.eclipse.jface.viewers.ISelection;
30
import org.eclipse.jface.viewers.IStructuredSelection;
31
32
import org.eclipse.jface.text.contentassist.ICompletionProposal;
33
34
import org.eclipse.search.internal.ui.SearchMessages;
35
import org.eclipse.search.internal.ui.SearchPlugin;
36
import org.eclipse.search.internal.ui.text.FileSearchPage;
37
import org.eclipse.search.ui.IContextMenuConstants;
38
import org.eclipse.search.ui.text.AbstractTextSearchResult;
39
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
40
import org.eclipse.search.ui.text.Match;
41
42
public class SpellingSearchResultPage extends FileSearchPage {
43
44
	private static final class ResolveSpellingProblemAction extends Action {
45
46
		private final SpellingLineElement fElement;
47
		private final ICompletionProposal fProposal;
48
49
		private final AbstractTextSearchViewPage fPage;
50
51
		public ResolveSpellingProblemAction(SpellingLineElement element, final ICompletionProposal proposal, AbstractTextSearchViewPage page) {
52
			super(proposal.getDisplayString());
53
			
54
			fElement= element;
55
			fProposal= proposal;
56
			fPage= page;
57
			
58
			setImageDescriptor(new ImageDescriptor() {
59
				public ImageData getImageData() {
60
					return proposal.getImage().getImageData();
61
				}
62
			});
63
		}
64
		
65
		/** 
66
		 * {@inheritDoc}
67
		 */
68
		public void run() {
69
			try {
70
				IResource file= fElement.getParent();
71
				
72
				ITextFileBufferManager bufferManager= FileBuffers.getTextFileBufferManager();
73
				bufferManager.connect(file.getFullPath(), LocationKind.IFILE, new NullProgressMonitor());
74
				try {
75
					ITextFileBuffer buffer= bufferManager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
76
					
77
					fProposal.apply(buffer.getDocument());
78
79
					AbstractTextSearchResult input= fPage.getInput();
80
					if (input != null) {
81
						Match[] matches= input.getMatches(file);
82
						for (int i= 0; i < matches.length; i++) {
83
							Match match= matches[i];
84
							if (match instanceof SpellingSearchMatch && ((SpellingSearchMatch)match).getLineElement() == fElement) {
85
								input.removeMatch(match);
86
							}
87
						}
88
					}
89
				} finally {
90
					bufferManager.disconnect(file.getFullPath(), LocationKind.IFILE, new NullProgressMonitor());
91
				}
92
			} catch (CoreException e) {
93
				SearchPlugin.log(e);
94
			}
95
		}
96
	}
97
98
	/** 
99
	 * {@inheritDoc}
100
	 */
101
	protected void fillContextMenu(IMenuManager mgr) {
102
		super.fillContextMenu(mgr);
103
104
		ISelection selection= getSite().getSelectionProvider().getSelection();
105
		if (selection instanceof IStructuredSelection) {
106
			IStructuredSelection sselection= (IStructuredSelection) selection;
107
			if (sselection.size() == 1 && sselection.getFirstElement() instanceof SpellingLineElement) {
108
				SpellingLineElement element= (SpellingLineElement) sselection.getFirstElement();
109
110
				ICompletionProposal[] proposals= element.getProblem().getProposals();
111
112
				if (proposals.length > 0) {
113
					MenuManager replaceMenu= new MenuManager(SearchMessages.SpellingSearchResultPage_fixProblemMenu_label);
114
115
					for (int i= 0; i < proposals.length; i++) {
116
						replaceMenu.add(new ResolveSpellingProblemAction(element, proposals[i], this));
117
					}
118
119
					mgr.appendToGroup(IContextMenuConstants.GROUP_EDIT, replaceMenu);
120
				}
121
			}
122
		}
123
	}
124
125
}
(-)search/org/eclipse/search/internal/ui/spelling/SpellingSearchMatch.java (+40 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.search.internal.ui.spelling;
12
13
import org.eclipse.core.resources.IFile;
14
15
import org.eclipse.ui.texteditor.spelling.SpellingProblem;
16
17
import org.eclipse.search.internal.ui.text.FileMatch;
18
import org.eclipse.search.internal.ui.text.LineElement;
19
20
public class SpellingSearchMatch extends FileMatch {
21
	
22
	private final SpellingProblem fProblem;
23
	private final IFile fFile;
24
25
	public SpellingSearchMatch(IFile file, SpellingProblem problem, LineElement element) {
26
		super(file, problem.getOffset(), problem.getLength(), element);
27
		
28
		fFile= file;
29
		fProblem= problem;
30
	}
31
32
	public SpellingProblem getProblem() {
33
		return fProblem;
34
	}
35
	
36
	public IFile getFile() {
37
		return fFile;
38
	}
39
40
}
(-)search/org/eclipse/search/internal/ui/text/FileSearchScopeConfigurationBlock.java (+226 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.search.internal.ui.text;
12
13
import java.util.HashSet;
14
import java.util.Iterator;
15
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.events.ModifyEvent;
18
import org.eclipse.swt.events.ModifyListener;
19
import org.eclipse.swt.events.SelectionAdapter;
20
import org.eclipse.swt.events.SelectionEvent;
21
import org.eclipse.swt.layout.GridData;
22
import org.eclipse.swt.widgets.Button;
23
import org.eclipse.swt.widgets.Combo;
24
import org.eclipse.swt.widgets.Composite;
25
import org.eclipse.swt.widgets.Label;
26
27
import org.eclipse.core.runtime.IAdaptable;
28
29
import org.eclipse.core.resources.IResource;
30
import org.eclipse.core.resources.IWorkspaceRoot;
31
import org.eclipse.core.resources.ResourcesPlugin;
32
33
import org.eclipse.jface.layout.PixelConverter;
34
import org.eclipse.jface.viewers.ISelection;
35
import org.eclipse.jface.viewers.IStructuredSelection;
36
37
import org.eclipse.ui.IWorkingSet;
38
39
import org.eclipse.search.internal.ui.SearchMessages;
40
import org.eclipse.search.internal.ui.util.FileTypeEditor;
41
import org.eclipse.search.internal.ui.util.SWTUtil;
42
import org.eclipse.search.ui.ISearchPageContainer;
43
import org.eclipse.search.ui.text.FileTextSearchScope;
44
45
public class FileSearchScopeConfigurationBlock {
46
47
	public static abstract class FileSearchScopeConfigurationBlockListener {
48
		public abstract void extensionsTextChanged();
49
50
		public abstract void derivedSelectionChanged();
51
	}
52
53
	private final FileSearchScopeConfigurationBlockListener fListener;
54
55
	private ISearchPageContainer fContainer;
56
	private Combo fExtensions;
57
	private Button fSearchDerivedCheckbox;
58
	private FileTypeEditor fFileTypeEditor;
59
	private boolean fSearchDerived;
60
	private Composite fControl;
61
62
	public FileSearchScopeConfigurationBlock(FileSearchScopeConfigurationBlockListener listener) {
63
		fListener= listener;
64
	}
65
66
	public void setContainer(ISearchPageContainer container) {
67
		fContainer= container;
68
	}
69
70
	public String[] getExtensions() {
71
		return fFileTypeEditor.getFileTypes();
72
	}
73
74
	public String getExtensionsText() {
75
		return fExtensions.getText();
76
	}
77
78
	public void setExtensionsText(String text) {
79
		fExtensions.setText(text);
80
	}
81
82
	public void setExtensions(String[] extensions) {
83
		fExtensions.setItems(extensions);
84
	}
85
86
	public void setSearchDerived(boolean enabled) {
87
		fSearchDerived= enabled;
88
	}
89
90
	public boolean getSearchDerived() {
91
		return fSearchDerived;
92
	}
93
94
	public void setFileTypes(String[] types) {
95
		fFileTypeEditor.setFileTypes(types);
96
	}
97
98
	public void createControl(Composite parent) {
99
		fControl= parent;
100
101
		addFileNameControls(parent);
102
	}
103
104
	public FileTextSearchScope createTextSearchScope() {
105
		// Setup search scope
106
		switch (getContainer().getSelectedScope()) {
107
			case ISearchPageContainer.WORKSPACE_SCOPE:
108
				return FileTextSearchScope.newWorkspaceScope(getExtensions(), fSearchDerived);
109
			case ISearchPageContainer.SELECTION_SCOPE:
110
				return getSelectedResourcesScope();
111
			case ISearchPageContainer.SELECTED_PROJECTS_SCOPE:
112
				return getEnclosingProjectScope();
113
			case ISearchPageContainer.WORKING_SET_SCOPE:
114
				IWorkingSet[] workingSets= getContainer().getSelectedWorkingSets();
115
				return FileTextSearchScope.newSearchScope(workingSets, getExtensions(), fSearchDerived);
116
			default:
117
				// unknown scope
118
				return FileTextSearchScope.newWorkspaceScope(getExtensions(), fSearchDerived);
119
		}
120
	}
121
122
	private FileTextSearchScope getSelectedResourcesScope() {
123
		HashSet resources= new HashSet();
124
		ISelection sel= getContainer().getSelection();
125
		if (sel instanceof IStructuredSelection && !sel.isEmpty()) {
126
			Iterator iter= ((IStructuredSelection)sel).iterator();
127
			while (iter.hasNext()) {
128
				Object curr= iter.next();
129
				if (curr instanceof IWorkingSet) {
130
					IWorkingSet workingSet= (IWorkingSet)curr;
131
					if (workingSet.isAggregateWorkingSet() && workingSet.isEmpty()) {
132
						return FileTextSearchScope.newWorkspaceScope(getExtensions(), fSearchDerived);
133
					}
134
					IAdaptable[] elements= workingSet.getElements();
135
					for (int i= 0; i < elements.length; i++) {
136
						IResource resource= (IResource)elements[i].getAdapter(IResource.class);
137
						if (resource != null && resource.isAccessible()) {
138
							resources.add(resource);
139
						}
140
					}
141
				} else if (curr instanceof IAdaptable) {
142
					IResource resource= (IResource)((IAdaptable)curr).getAdapter(IResource.class);
143
					if (resource != null && resource.isAccessible()) {
144
						resources.add(resource);
145
					}
146
				}
147
			}
148
		}
149
		IResource[] arr= (IResource[])resources.toArray(new IResource[resources.size()]);
150
		return FileTextSearchScope.newSearchScope(arr, getExtensions(), fSearchDerived);
151
	}
152
153
	private FileTextSearchScope getEnclosingProjectScope() {
154
		String[] enclosingProjectName= getContainer().getSelectedProjectNames();
155
		if (enclosingProjectName == null) {
156
			return FileTextSearchScope.newWorkspaceScope(getExtensions(), fSearchDerived);
157
		}
158
159
		IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
160
		IResource[] res= new IResource[enclosingProjectName.length];
161
		for (int i= 0; i < res.length; i++) {
162
			res[i]= root.getProject(enclosingProjectName[i]);
163
		}
164
165
		return FileTextSearchScope.newSearchScope(res, getExtensions(), fSearchDerived);
166
	}
167
168
169
	private ISearchPageContainer getContainer() {
170
		return fContainer;
171
	}
172
173
	private void addFileNameControls(Composite group) {
174
		// grid layout with 2 columns
175
176
		// Line with label, combo and button
177
		Label label= new Label(group, SWT.LEAD);
178
		label.setText(SearchMessages.SearchPage_fileNamePatterns_text);
179
		label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
180
		label.setFont(group.getFont());
181
182
		fExtensions= new Combo(group, SWT.SINGLE | SWT.BORDER);
183
		fExtensions.addModifyListener(new ModifyListener() {
184
			public void modifyText(ModifyEvent e) {
185
				fListener.extensionsTextChanged();
186
			}
187
		});
188
		GridData data= new GridData(GridData.FILL, GridData.FILL, true, false, 1, 1);
189
		data.widthHint= convertWidthInCharsToPixels(50);
190
		fExtensions.setLayoutData(data);
191
		fExtensions.setFont(group.getFont());
192
193
		Button button= new Button(group, SWT.PUSH);
194
		button.setText(SearchMessages.SearchPage_browse);
195
		GridData gridData= new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 1, 1);
196
		gridData.widthHint= SWTUtil.getButtonWidthHint(button);
197
		button.setLayoutData(gridData);
198
		button.setFont(group.getFont());
199
200
		fFileTypeEditor= new FileTypeEditor(fExtensions, button);
201
202
		// Text line which explains the special characters
203
		Label description= new Label(group, SWT.LEAD);
204
		description.setText(SearchMessages.SearchPage_fileNamePatterns_hint);
205
		description.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
206
		description.setFont(group.getFont());
207
208
		fSearchDerivedCheckbox= new Button(group, SWT.CHECK);
209
		fSearchDerivedCheckbox.setText(SearchMessages.TextSearchPage_searchDerived_label);
210
211
		fSearchDerivedCheckbox.setSelection(fSearchDerived);
212
		fSearchDerivedCheckbox.addSelectionListener(new SelectionAdapter() {
213
			public void widgetSelected(SelectionEvent e) {
214
				fSearchDerived= fSearchDerivedCheckbox.getSelection();
215
				fListener.derivedSelectionChanged();
216
			}
217
		});
218
		fSearchDerivedCheckbox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
219
		fSearchDerivedCheckbox.setFont(group.getFont());
220
	}
221
222
	private int convertWidthInCharsToPixels(int width) {
223
		return new PixelConverter(fControl).convertWidthInCharsToPixels(width);
224
	}
225
226
}

Return to bug 191432