Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 18e9215f50b07bf80b744ffc575381cc785884a3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
/*******************************************************************************
 * Copyright (c) 2003 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v0.5 
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors:
 *     IBM Corp. - Rational Software - initial implementation
 ******************************************************************************/
/*
 * Created on Jun 10, 2003
 */
package org.eclipse.cdt.internal.ui.search;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.DialogPage;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.search.internal.ui.util.RowLayouter;
import org.eclipse.search.ui.ISearchPage;
import org.eclipse.search.ui.ISearchPageContainer;
import org.eclipse.search.ui.ISearchResultViewEntry;
import org.eclipse.search.ui.SearchUI;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.help.WorkbenchHelp;
import org.eclipse.ui.model.IWorkbenchAdapter;

/**
 * @author aniefer
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class CSearchPage extends DialogPage implements ISearchPage, ICSearchConstants {

	public static final String EXTENSION_POINT_ID= "org.eclipse.cdt.ui.CSearchPage"; //$NON-NLS-1$
	
	public boolean performAction() {
		SearchUI.activateSearchResultView();

		SearchPatternData data = getPatternData();
		IWorkspace workspace = CUIPlugin.getWorkspace();
		
		ICSearchScope scope = null;
		String scopeDescription = ""; //$NON-NLS-1$
		
		switch( getContainer().getSelectedScope() ) {
			case ISearchPageContainer.WORKSPACE_SCOPE:
				scopeDescription = CSearchMessages.getString("WorkspaceScope"); //$NON-NLS-1$
				scope = SearchEngine.createWorkspaceScope();
				break;
			case ISearchPageContainer.SELECTION_SCOPE:
				scopeDescription = CSearchMessages.getString("SelectionScope"); //$NON-NLS-1$
				scope = CSearchScopeFactory.getInstance().createCSearchScope(fStructuredSelection);
				break;
			case ISearchPageContainer.WORKING_SET_SCOPE:
				IWorkingSet[] workingSets= getContainer().getSelectedWorkingSets();
				// should not happen - just to be sure
				if (workingSets == null || workingSets.length < 1)
					return false;
				scopeDescription = CSearchMessages.getFormattedString("WorkingSetScope", CSearchUtil.toString(workingSets)); //$NON-NLS-1$
				scope= CSearchScopeFactory.getInstance().createCSearchScope(getContainer().getSelectedWorkingSets());
				CSearchUtil.updateLRUWorkingSets(getContainer().getSelectedWorkingSets());
		}
		
		data.cElement= null;
		
		CSearchResultCollector collector= new CSearchResultCollector();
		
		List searching = null;
		
		if( data.searchFor.contains( UNKNOWN_SEARCH_FOR ) ){
			//UNKNOWN_SEARCH_FOR means search for anything, make a list with everything
			searching = new LinkedList();
			for( int i = 0; i < fSearchFor.length - 1; i++ ){
				searching.add( fSearchForValues[ i ] );		
			}
			
			//include those items not represented in the UI
			searching.add( MACRO );
			searching.add( TYPEDEF );
		} else {
			searching = data.searchFor;
		}
		
		CSearchOperation op = new CSearchOperation(workspace, data.pattern, data.isCaseSensitive, searching, data.limitTo, scope, scopeDescription, collector);

		
		try {
			getContainer().getRunnableContext().run(true, true, op);
		} catch (InvocationTargetException ex) {
			Shell shell = getControl().getShell();
			//ExceptionHandler.handle(ex, shell, CSearchMessages.getString("Search.Error.search.title"), CSearchMessages.getString("Search.Error.search.message")); //$NON-NLS-2$ //$NON-NLS-1$
			return false;
		} catch (InterruptedException ex) {
			return false;
		}
		return true;
	}

	public void createControl(Composite parent) {
		initializeDialogUnits( parent );
		readConfiguration();
		
		GridData gd;
		Composite  result = new Composite( parent, SWT.NONE );
		GridLayout layout = new GridLayout( 2, false );
		layout.horizontalSpacing = 10;
		result.setLayout( layout );
		result.setLayoutData( new GridData(GridData.FILL_HORIZONTAL) );
		
		RowLayouter layouter = new RowLayouter( layout.numColumns );
		gd = new GridData();
		gd.horizontalAlignment = GridData.FILL;
		gd.verticalAlignment   = GridData.VERTICAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_FILL;
	
		layouter.setDefaultGridData( gd, 0 );
		layouter.setDefaultGridData( gd, 1 );
		layouter.setDefaultSpan();

		layouter.perform( createExpression(result) );
		layouter.perform( createSearchFor(result), createLimitTo(result), -1 );
		
		SelectionAdapter cElementInitializer = new SelectionAdapter() {
			public void widgetSelected( SelectionEvent event ) {
				if( getSearchFor() == fInitialData.searchFor )
					fCElement= fInitialData.cElement;
				else
					fCElement= null;
				handleAllElements( event );
				setLimitTo( getSearchFor() );
				updateCaseSensitiveCheckbox();
			}
		};

		for( int i = 0; i < fSearchFor.length; i++ ){
			fSearchFor[ i ].addSelectionListener( cElementInitializer );		
		}

		setControl( result );

		Dialog.applyDialogFont( result );
		WorkbenchHelp.setHelp(result, ICHelpContextIds.C_SEARCH_PAGE);	
	}
	
	private Control createExpression( Composite parent ) {
		Composite  result = new Composite(parent, SWT.NONE);
		GridLayout layout = new GridLayout(2, false);
		result.setLayout(layout);
		GridData gd = new GridData( GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL );
		gd.horizontalSpan = 2;
		gd.horizontalIndent = 0;
		result.setLayoutData( gd );

		// Pattern text + info
		Label label = new Label( result, SWT.LEFT );
		label.setText( CSearchMessages.getString( "CSearchPage.expression.label" ) ); //$NON-NLS-1$
		gd = new GridData( GridData.BEGINNING );
		gd.horizontalSpan = 2;
		label.setLayoutData( gd );

		// Pattern combo
		fPattern = new Combo( result, SWT.SINGLE | SWT.BORDER );
		fPattern.addSelectionListener( new SelectionAdapter() {
			public void widgetSelected( SelectionEvent e ) {
				handlePatternSelected();
			}
		});
		
		fPattern.addModifyListener( new ModifyListener() {
			public void modifyText( ModifyEvent e ) {
				getContainer().setPerformActionEnabled( getPattern().length() > 0 );
				updateCaseSensitiveCheckbox();
			}
		});
		
		gd = new GridData( GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL );
		gd.horizontalIndent = -gd.horizontalIndent;
		fPattern.setLayoutData( gd );


		// Ignore case checkbox		
		fCaseSensitive= new Button(result, SWT.CHECK);
		fCaseSensitive.setText(CSearchMessages.getString("CSearchPage.expression.caseSensitive")); //$NON-NLS-1$
		gd= new GridData();
		fCaseSensitive.setLayoutData(gd);
		fCaseSensitive.addSelectionListener( new SelectionAdapter() {
			public void widgetSelected( SelectionEvent e ) {
				fIsCaseSensitive= fCaseSensitive.getSelection();
				writeConfiguration();
			}
		});
	
		return result;
	}

	private void handleAllElements( SelectionEvent event ){
		Button allElements = fSearchFor[ fSearchFor.length - 1 ];
		if( event.widget == allElements ){
			for( int i = 0; i < fSearchFor.length - 1; i++ )
				fSearchFor[i].setEnabled( ! allElements.getSelection() );
		}
	}
	
	private void handlePatternSelected() {
		if( fPattern.getSelectionIndex() < 0 )
			return;
			
		int index = fgPreviousSearchPatterns.size() - 1 - fPattern.getSelectionIndex();
		fInitialData = (SearchPatternData) fgPreviousSearchPatterns.get( index );
		
		updateSelections();

		if( fInitialData.workingSets != null )
			getContainer().setSelectedWorkingSets( fInitialData.workingSets );
		else
			getContainer().setSelectedScope( fInitialData.scope );
	}
	
	private String getPattern() {
		return fPattern.getText();
	}
	
	private Control createLimitTo( Composite parent ) {
		Group result = new Group(parent, SWT.NONE);
		result.setText( CSearchMessages.getString("CSearchPage.limitTo.label") ); //$NON-NLS-1$
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		result.setLayout( layout );

		fLimitTo = new Button[fLimitToText.length];
		for( int i = 0; i < fLimitToText.length; i++ ){
			Button button = new Button(result, SWT.RADIO);
			button.setText( fLimitToText[i] );
			fLimitTo[i] = button;
		}

		// Fill with dummy radio buttons
		Button filler= new Button(result, SWT.RADIO);
		filler.setVisible(false);
		filler= new Button(result, SWT.RADIO);
		filler.setVisible(false);		
		
		return result;		
	}
	
	private LimitTo getLimitTo() {
		for (int i= 0; i < fLimitTo.length; i++) {
			if (fLimitTo[i].getSelection())
				return fLimitToValues[ i ];
		}
		return null;
	}
	
	private void setLimitTo( List searchFor ) {
		HashSet set = new HashSet();
		
		set.add( DECLARATIONS );
		set.add( REFERENCES );
		set.add( ALL_OCCURRENCES );
				
		for (Iterator iter = searchFor.iterator(); iter.hasNext();) {
			SearchFor element = (SearchFor) iter.next();
			if( element == FUNCTION || element == METHOD || element == VAR || element == FIELD || element == NAMESPACE ){
				set.add( DEFINITIONS );
				break;
			}
		}
		
		for( int i = 0; i < fLimitTo.length; i++ )
			fLimitTo[ i ].setEnabled( set.contains( fLimitToValues[ i ] ) );
	}
	
	private Control createSearchFor(Composite parent) {
		Group result= new Group(parent, SWT.NONE);
		result.setText(CSearchMessages.getString("CSearchPage.searchFor.label")); //$NON-NLS-1$
		GridLayout layout= new GridLayout();
		layout.numColumns= 3;
		result.setLayout(layout);

		fSearchFor= new Button[fSearchForText.length];
		for (int i= 0; i < fSearchForText.length; i++) {
			Button button= new Button(result, SWT.CHECK);
			button.setText(fSearchForText[i]);
			fSearchFor[i]= button;
		}

		return result;		
	}
	
	private List getSearchFor() {
		List search = new LinkedList( );
		
//		boolean all = fSearchFor[ fSearchFor.length - 1 ].getSelection();
		
		for (int i= 0; i < fSearchFor.length; i++) {
			if( fSearchFor[i].getSelection() /*|| all */)
				search.add( fSearchForValues[i] );
		}
		
		return search;
	}
	
	public void setContainer(ISearchPageContainer container) {
		fContainer = container;
	}
	
	private ISearchPageContainer getContainer() {
		return fContainer;
	}
	

	private IDialogSettings getDialogSettings() {
		IDialogSettings settings = CUIPlugin.getDefault().getDialogSettings();
		fDialogSettings = settings.getSection( PAGE_NAME );
		if( fDialogSettings == null )
			fDialogSettings = settings.addNewSection( PAGE_NAME );
			
		return fDialogSettings;
	}
		
	private void readConfiguration() {
		IDialogSettings s = getDialogSettings();
		fIsCaseSensitive = s.getBoolean( STORE_CASE_SENSITIVE );
	}

	private void writeConfiguration() {
		IDialogSettings s = getDialogSettings();
		s.put( STORE_CASE_SENSITIVE, fIsCaseSensitive );
	}

	public void setVisible(boolean visible) {
		if (visible && fPattern != null) {
			if (fFirstTime) {
				fFirstTime= false;
				// Set item and text here to prevent page from resizing
				fPattern.setItems(getPreviousSearchPatterns());
				initSelections();
			}
			fPattern.setFocus();
			getContainer().setPerformActionEnabled(fPattern.getText().length() > 0);
		}
		super.setVisible(visible);
	}
	
	private void updateCaseSensitiveCheckbox() {
		if (fInitialData != null && getPattern().equals(fInitialData.pattern) && fCElement != null) {
			fCaseSensitive.setEnabled(false);
			fCaseSensitive.setSelection(true);
		}
		else {
			fCaseSensitive.setEnabled(true);
			fCaseSensitive.setSelection(fIsCaseSensitive);
		}
	}
	
	private void initSelections() {
		fStructuredSelection = asStructuredSelection();
		fInitialData = tryStructuredSelection( fStructuredSelection );
		updateSelections();
	}
	
	private void updateSelections(){
		if (fInitialData == null)
			fInitialData = trySimpleTextSelection( getContainer().getSelection() );
		if (fInitialData == null)
			fInitialData = getDefaultInitValues();

		fCElement = fInitialData.cElement;
		fIsCaseSensitive = fInitialData.isCaseSensitive;
		fCaseSensitive.setSelection( fInitialData.isCaseSensitive );
		fCaseSensitive.setEnabled( fInitialData.cElement == null );
		
		HashSet set = new HashSet( fInitialData.searchFor );
		
		boolean enabled = ! set.contains( fSearchForValues[ fSearchFor.length - 1 ] );
		
		for (int i = 0; i < fSearchFor.length; i++){
			fSearchFor[i].setSelection( set.contains( fSearchForValues[i] ) );
			fSearchFor[i].setEnabled( enabled );			
		}
		
		if( !enabled )
			fSearchFor[ fSearchFor.length - 1 ].setEnabled( true );
			
		setLimitTo( fInitialData.searchFor );
			
		for (int i = 0; i < fLimitTo.length; i++)
			fLimitTo[i].setSelection( fLimitToValues[i] == fInitialData.limitTo );

		fPattern.setText( fInitialData.pattern );
	}
	
	private SearchPatternData tryStructuredSelection( IStructuredSelection selection ) {
		if( selection == null || selection.size() > 1 )
			return null;

		Object o = selection.getFirstElement();
		if( o instanceof ICElement ) {
			return determineInitValuesFrom( (ICElement)o );
		} else if( o instanceof ISearchResultViewEntry ) {
			ICElement element = CSearchUtil.getCElement( ((ISearchResultViewEntry)o).getSelectedMarker() );
			return determineInitValuesFrom( element );
		//} else if( o instanceof LogicalPackage ) {
		//	LogicalPackage lp = (LogicalPackage)o;
		//	return new SearchPatternData( PACKAGE, REFERENCES, fIsCaseSensitive, lp.getElementName(), null );
		} else if( o instanceof IAdaptable ) {
			ICElement element = (ICElement)((IAdaptable)o).getAdapter( ICElement.class );
			if( element != null ) {
				return determineInitValuesFrom( element );
			} else {
				IWorkbenchAdapter adapter= (IWorkbenchAdapter)((IAdaptable)o).getAdapter( IWorkbenchAdapter.class );
				if( adapter != null ){
					List searchFor = new LinkedList();
					searchFor.add( UNKNOWN_SEARCH_FOR );
					return new SearchPatternData( searchFor, DECLARATIONS, fIsCaseSensitive, adapter.getLabel(o), null );
				}
			}
		}
		return null;
	}
	
	/**
	 * try to initialize the Search pattern data based on the current text selection.
	 * @param selection
	 * @return
	 */
	private SearchPatternData trySimpleTextSelection(ISelection selection) {
		SearchPatternData result= null;
		if (selection instanceof ITextSelection) {
			BufferedReader reader= new BufferedReader(new StringReader(((ITextSelection)selection).getText()));
			String text;
			try {
				text= reader.readLine();
				if (text == null)
					text= ""; //$NON-NLS-1$
			} catch (IOException ex) {
				text= ""; //$NON-NLS-1$
			}
			
			List searchFor = new LinkedList();
			searchFor.add( UNKNOWN_SEARCH_FOR );
			result= new SearchPatternData( searchFor, DECLARATIONS, fIsCaseSensitive, text, null);
		}
		return result;
	}
	
	private SearchPatternData getDefaultInitValues() {
		List searchFor = new LinkedList();
		searchFor.add( CLASS_STRUCT );
		return new SearchPatternData( searchFor, DECLARATIONS, fIsCaseSensitive, "", null); //$NON-NLS-1$
	}
		
	private String[] getPreviousSearchPatterns() {
		// Search results are not persistent
		int patternCount= fgPreviousSearchPatterns.size();
		String [] patterns= new String[patternCount];
		for (int i= 0; i < patternCount; i++)
			patterns[i]= ((SearchPatternData) fgPreviousSearchPatterns.get(patternCount - 1 - i)).pattern;
		return patterns;
	}	
	
	private IStructuredSelection asStructuredSelection() {
		IWorkbenchWindow wbWindow= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		if (wbWindow != null) {
			IWorkbenchPage page= wbWindow.getActivePage();
			if (page != null) {
				IWorkbenchPart part= page.getActivePart();
				if (part != null){
					ISelectionProvider provider = part.getSite().getSelectionProvider();
					if( provider != null ){
						ISelection selection = provider.getSelection();
						if( selection instanceof IStructuredSelection ){
							return (IStructuredSelection)selection;
						}
					}
				}
			}
		}
		return StructuredSelection.EMPTY;
	}

	private SearchPatternData determineInitValuesFrom( ICElement element ) {
		if( element == null )
			return null;
		
		List searchFor = new LinkedList();
		
		//outliune view will confuse methods with functions, so if the 
		//name contains a "::", treat it as a method
		String pattern = element.getElementName();
		boolean forceMethod = ( pattern.indexOf("::") != -1 );
		
		switch ( element.getElementType() ){
			case ICElement.C_TEMPLATE_FUNCTION:	   /*fall through to function */
			case ICElement.C_FUNCTION_DECLARATION: /*fall through to function */
			case ICElement.C_FUNCTION:	if( forceMethod ) searchFor.add( METHOD ); 
										else 			  searchFor.add( FUNCTION );		
										break;
										
			case ICElement.C_VARIABLE:	searchFor.add( VAR );			break;
			
			case ICElement.C_TEMPLATE_CLASS:/*   fall through to CLASS   */ 
			case ICElement.C_STRUCT:		/*   fall through to CLASS   */	 
			case ICElement.C_CLASS:		searchFor.add( CLASS_STRUCT );	break;
			
			case ICElement.C_UNION:		searchFor.add( UNION );			break;
			
			case ICElement.C_ENUMERATOR: /* fall through to FIELD    */
			case ICElement.C_FIELD:		searchFor.add( FIELD );			break;
			
			case ICElement.C_TEMPLATE_METHOD : 	  /*fall through to METHOD */
			case ICElement.C_METHOD_DECLARATION : /*fall through to METHOD */
			case ICElement.C_METHOD:	searchFor.add( METHOD );		break;
			
			case ICElement.C_NAMESPACE: searchFor.add( NAMESPACE );		break;
			
			default: searchFor.add( UNKNOWN_SEARCH_FOR ); break;
		}

		LimitTo limitTo = ALL_OCCURRENCES;			
		
		return new SearchPatternData( searchFor, limitTo, true, pattern, element );
	}

	private SearchPatternData getPatternData() {
		String pattern= getPattern();
		SearchPatternData match= null;
		int i= 0;
		int size= fgPreviousSearchPatterns.size();
		while (match == null && i < size) {
			match= (SearchPatternData) fgPreviousSearchPatterns.get(i);
			i++;
			if (!pattern.equals(match.pattern))
				match= null;
		};
		if (match == null) {
			match= new SearchPatternData(
							getSearchFor(),
							getLimitTo(),
							pattern,
							fCaseSensitive.getSelection(),
							fCElement,
							getContainer().getSelectedScope(),
							getContainer().getSelectedWorkingSets());
			fgPreviousSearchPatterns.add(match);
		}
		else {
			match.searchFor= getSearchFor();
			match.limitTo= getLimitTo();
			match.isCaseSensitive= fCaseSensitive.getSelection();
			match.cElement= fCElement;
			match.scope= getContainer().getSelectedScope();
			match.workingSets= getContainer().getSelectedWorkingSets();
		};
		return match;
	}
	
	private static class SearchPatternData {
		List 		searchFor;
		LimitTo		limitTo;
		String		pattern;
		boolean		isCaseSensitive;
		ICElement	cElement;
		int			scope;
		IWorkingSet[]	 	workingSets;
	
		public SearchPatternData(List s, LimitTo l, boolean i, String p, ICElement element) {
			this(s, l, p, i, element, ISearchPageContainer.WORKSPACE_SCOPE, null);
		}
	
		public SearchPatternData(List s, LimitTo l, String p, boolean i, ICElement element, int scope, IWorkingSet[] workingSets) {
			searchFor= s;
			limitTo= l;
			pattern= p;
			isCaseSensitive= i;
			cElement= element;
			this.scope = scope;
			this.workingSets = workingSets;
		}
	}
	
	//Dialog store id constants
	private final static String PAGE_NAME= "CSearchPage"; //$NON-NLS-1$
	private final static String STORE_CASE_SENSITIVE= PAGE_NAME + "CASE_SENSITIVE"; //$NON-NLS-1$

	private static List fgPreviousSearchPatterns = new ArrayList(20);

	private Button[] fSearchFor;
	private SearchFor[] fSearchForValues = { CLASS_STRUCT, FUNCTION, VAR, UNION, METHOD, FIELD, ENUM, NAMESPACE, UNKNOWN_SEARCH_FOR };
	
	private String[] fSearchForText= {
		CSearchMessages.getString("CSearchPage.searchFor.classStruct"), //$NON-NLS-1$
		CSearchMessages.getString("CSearchPage.searchFor.function"),	//$NON-NLS-1$
		CSearchMessages.getString("CSearchPage.searchFor.variable"), 	//$NON-NLS-1$
		CSearchMessages.getString("CSearchPage.searchFor.union"),		//$NON-NLS-1$
		CSearchMessages.getString("CSearchPage.searchFor.method"), 		//$NON-NLS-1$
		CSearchMessages.getString("CSearchPage.searchFor.field"),		//$NON-NLS-1$
		CSearchMessages.getString("CSearchPage.searchFor.enum"),		//$NON-NLS-1$
		CSearchMessages.getString("CSearchPage.searchFor.namespace"),	//$NON-NLS-1$
		CSearchMessages.getString("CSearchPage.searchFor.any") }; 		//$NON-NLS-1$
		
		
	private Button[] fLimitTo;
	private LimitTo[] fLimitToValues = { DECLARATIONS, DEFINITIONS, REFERENCES, ALL_OCCURRENCES };
	private String[] fLimitToText= {
		CSearchMessages.getString("CSearchPage.limitTo.declarations"), //$NON-NLS-1$
		CSearchMessages.getString("CSearchPage.limitTo.definitions"), //$NON-NLS-1$
		CSearchMessages.getString("CSearchPage.limitTo.references"), //$NON-NLS-1$
		CSearchMessages.getString("CSearchPage.limitTo.allOccurrences") }; //$NON-NLS-1$
		//CSearchMessages.getString("CSearchPage.limitTo.readReferences"), //$NON-NLS-1$		
		//CSearchMessages.getString("CSearchPage.limitTo.writeReferences")}; //$NON-NLS-1$

	private SearchPatternData fInitialData;
	private IStructuredSelection fStructuredSelection;
	private ICElement fCElement;
	private boolean fFirstTime= true;
	private IDialogSettings fDialogSettings;
	private boolean fIsCaseSensitive;

	private Combo fPattern;
	private ISearchPageContainer fContainer;
	private Button fCaseSensitive;
}

Back to the top