View | Details | Raw Unified | Return to bug 132833 | Differences between
and this patch

Collapse All | Expand All

(-)search/org/eclipse/search/internal/ui/text/ReplaceDialog2.java (-41 / +27 lines)
Lines 50-59 Link Here
50
import org.eclipse.swt.widgets.Shell;
50
import org.eclipse.swt.widgets.Shell;
51
import org.eclipse.swt.widgets.Text;
51
import org.eclipse.swt.widgets.Text;
52
52
53
import org.eclipse.jface.contentassist.SubjectControlContentAssistant;
54
import org.eclipse.jface.dialogs.IDialogConstants;
53
import org.eclipse.jface.dialogs.IDialogConstants;
55
import org.eclipse.jface.dialogs.IDialogSettings;
54
import org.eclipse.jface.dialogs.IDialogSettings;
56
import org.eclipse.jface.dialogs.MessageDialog;
55
import org.eclipse.jface.dialogs.MessageDialog;
56
import org.eclipse.jface.fieldassist.ComboContentAdapter;
57
import org.eclipse.jface.fieldassist.IControlCreator;
57
import org.eclipse.jface.operation.IRunnableWithProgress;
58
import org.eclipse.jface.operation.IRunnableWithProgress;
58
import org.eclipse.jface.resource.JFaceColors;
59
import org.eclipse.jface.resource.JFaceColors;
59
import org.eclipse.jface.util.Assert;
60
import org.eclipse.jface.util.Assert;
Lines 62-74 Link Here
62
import org.eclipse.jface.viewers.StructuredSelection;
63
import org.eclipse.jface.viewers.StructuredSelection;
63
64
64
import org.eclipse.jface.text.BadLocationException;
65
import org.eclipse.jface.text.BadLocationException;
65
import org.eclipse.jface.text.DefaultInformationControl;
66
import org.eclipse.jface.text.IDocument;
66
import org.eclipse.jface.text.IDocument;
67
import org.eclipse.jface.text.IInformationControl;
68
import org.eclipse.jface.text.IInformationControlCreator;
69
import org.eclipse.jface.text.Position;
67
import org.eclipse.jface.text.Position;
70
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
71
import org.eclipse.jface.text.contentassist.IContentAssistant;
72
68
73
import org.eclipse.ui.IEditorDescriptor;
69
import org.eclipse.ui.IEditorDescriptor;
74
import org.eclipse.ui.IEditorPart;
70
import org.eclipse.ui.IEditorPart;
Lines 78-87 Link Here
78
import org.eclipse.ui.PartInitException;
74
import org.eclipse.ui.PartInitException;
79
import org.eclipse.ui.PlatformUI;
75
import org.eclipse.ui.PlatformUI;
80
import org.eclipse.ui.actions.GlobalBuildAction;
76
import org.eclipse.ui.actions.GlobalBuildAction;
81
import org.eclipse.ui.contentassist.ContentAssistHandler;
77
import org.eclipse.ui.fieldassist.ContentAssistField;
82
import org.eclipse.ui.ide.IDE;
78
import org.eclipse.ui.ide.IDE;
83
import org.eclipse.ui.part.FileEditorInput;
79
import org.eclipse.ui.part.FileEditorInput;
84
import org.eclipse.ui.texteditor.ITextEditor;
80
import org.eclipse.ui.texteditor.ITextEditor;
81
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
85
82
86
import org.eclipse.search.ui.NewSearchUI;
83
import org.eclipse.search.ui.NewSearchUI;
87
import org.eclipse.search.ui.text.Match;
84
import org.eclipse.search.ui.text.Match;
Lines 143-150 Link Here
143
	// reuse editors stuff
140
	// reuse editors stuff
144
	private IReusableEditor fEditor;
141
	private IReusableEditor fEditor;
145
	private FileSearchPage fPage;
142
	private FileSearchPage fPage;
146
	private ContentAssistHandler fReplaceContentAssistHandler;
147
	private Label fStatusLabel;
143
	private Label fStatusLabel;
144
	
145
	/**
146
	 * Decorated find and replace fields.
147
	 * @since 3.2
148
	 */
149
	private ContentAssistField fContentAssistReplaceField;
148
150
149
	private boolean fSaved= false;
151
	private boolean fSaved= false;
150
152
Lines 213-219 Link Here
213
	}	
215
	}	
214
216
215
	private void restoreAutobuild() throws CoreException {
217
	private void restoreAutobuild() throws CoreException {
216
		// this is only called if autobuild was on before.
218
		// this is only called if auto-build was on before.
217
		IWorkspace workspace= ResourcesPlugin.getWorkspace();
219
		IWorkspace workspace= ResourcesPlugin.getWorkspace();
218
		IWorkspaceDescription description = workspace.getDescription();
220
		IWorkspaceDescription description = workspace.getDescription();
219
		description.setAutoBuilding(true);
221
		description.setAutoBuilding(true);
Lines 261-270 Link Here
261
		
263
		
262
		label= new Label(result, SWT.NONE);
264
		label= new Label(result, SWT.NONE);
263
		label.setText(SearchMessages.ReplaceDialog_with_label); 
265
		label.setText(SearchMessages.ReplaceDialog_with_label); 
264
		fTextField= new Combo(result, SWT.DROP_DOWN);
266
267
		ComboContentAdapter contentAdapter= new ComboContentAdapter();
268
		RegExContentProposalProvider findProposer= new RegExContentProposalProvider(false);
269
		fContentAssistReplaceField= new ContentAssistField(result, SWT.DROP_DOWN | SWT.BORDER, 
270
				new IControlCreator() {
271
					public Control createControl(Composite controlParent, int style) {
272
						return new Combo(controlParent, SWT.DROP_DOWN);
273
					}
274
				}, 
275
				contentAdapter, findProposer, 
276
				ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS,
277
				new char[] {'\\', '[', '('});
278
		
279
		fTextField= (Combo)fContentAssistReplaceField.getControl(); 
265
		gd= new GridData(GridData.FILL_HORIZONTAL);
280
		gd= new GridData(GridData.FILL_HORIZONTAL);
266
		gd.widthHint= convertWidthInCharsToPixels(50);
281
		gd.widthHint= convertWidthInCharsToPixels(50);
267
		fTextField.setLayoutData(gd);
282
		fContentAssistReplaceField.getLayoutControl().setLayoutData(gd);
268
		fTextField.setFocus();
283
		fTextField.setFocus();
269
		
284
		
270
		IDialogSettings settings= SearchPlugin.getDefault().getDialogSettings().getSection(SETTINGS_GROUP);
285
		IDialogSettings settings= SearchPlugin.getDefault().getDialogSettings().getSection(SETTINGS_GROUP);
Lines 754-791 Link Here
754
		return fMarkers.size() > 0;
769
		return fMarkers.size() > 0;
755
	}
770
	}
756
	
771
	
757
	public static SubjectControlContentAssistant createContentAssistant(boolean isFind) {
758
		final SubjectControlContentAssistant contentAssistant= new SubjectControlContentAssistant();
759
		
760
		contentAssistant.setRestoreCompletionProposalSize(SearchPlugin.getDefault().getDialogSettings());
761
		
762
		IContentAssistProcessor processor= new RegExContentAssistProcessor(isFind);
763
		contentAssistant.setContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE);
764
		
765
		contentAssistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
766
		contentAssistant.setInformationControlCreator(new IInformationControlCreator() {
767
			/*
768
			 * @see org.eclipse.jface.text.IInformationControlCreator#createInformationControl(org.eclipse.swt.widgets.Shell)
769
			 */
770
			public IInformationControl createInformationControl(Shell parent) {
771
				return new DefaultInformationControl(parent);
772
			}});
773
		
774
		return contentAssistant;
775
	}
776
	
772
	
777
	private void setContentAssistsEnablement(boolean enable) {
773
	private void setContentAssistsEnablement(boolean enable) {
778
		if (enable) {
774
		fContentAssistReplaceField.setEnabled(enable);
779
			if (fReplaceContentAssistHandler == null) {
780
				fReplaceContentAssistHandler= ContentAssistHandler.createHandlerForCombo(fTextField, createContentAssistant(false));
781
			}
782
			fReplaceContentAssistHandler.setEnabled(true);
783
			
784
		} else {
785
			if (fReplaceContentAssistHandler == null)
786
				return;
787
			fReplaceContentAssistHandler.setEnabled(false);
788
		}
789
	}
775
	}
790
776
791
	private void statusMessage(boolean error, String message) {
777
	private void statusMessage(boolean error, String message) {
(-)search/org/eclipse/search/internal/ui/text/RegExContentAssistProcessor.java (-388 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 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
12
package org.eclipse.search.internal.ui.text;
13
14
import java.util.ArrayList;
15
16
import org.eclipse.jface.contentassist.IContentAssistSubjectControl;
17
import org.eclipse.jface.contentassist.ISubjectControlContentAssistProcessor;
18
import org.eclipse.jface.contentassist.SubjectControlContextInformationValidator;
19
import org.eclipse.jface.text.ITextViewer;
20
import org.eclipse.jface.text.contentassist.CompletionProposal;
21
import org.eclipse.jface.text.contentassist.ICompletionProposal;
22
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
23
import org.eclipse.jface.text.contentassist.IContextInformation;
24
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
25
26
/**
27
 * Content assist processor for regular expressions.
28
 *
29
 * @since 3.0
30
 */
31
final class RegExContentAssistProcessor implements IContentAssistProcessor, ISubjectControlContentAssistProcessor {
32
33
	/**
34
	 * Proposal computer.
35
	 */
36
	private static class ProposalComputer {
37
38
		/**
39
		 * The whole regular expression.
40
		 */
41
		private final String fExpression;
42
		/**
43
		 * The document offset.
44
		 */
45
		private final int fDocumentOffset;
46
		/**
47
		 * The high-priority proposals.
48
		 */
49
		private final ArrayList fPriorityProposals;
50
		/**
51
		 * The low-priority proposals.
52
		 */
53
		private final ArrayList fProposals;
54
		/**
55
		 * <code>true</code> iff <code>fExpression</code> ends with an open escape.
56
		 */
57
		private final boolean fIsEscape;
58
59
		/**
60
		 * Creates a new Proposal Computer.
61
		 * @param contentAssistSubjectControl the subject control
62
		 * @param documentOffset the offset
63
		 */
64
		public ProposalComputer(IContentAssistSubjectControl contentAssistSubjectControl, int documentOffset) {
65
			fExpression= contentAssistSubjectControl.getDocument().get();
66
			fDocumentOffset= documentOffset;
67
			fPriorityProposals= new ArrayList();
68
			fProposals= new ArrayList();
69
			
70
			boolean isEscape= false;
71
			esc: for (int i= documentOffset - 1; i >= 0; i--) {
72
				if (fExpression.charAt(i) == '\\')
73
					isEscape= !isEscape;
74
				else
75
					break esc;
76
			}
77
			fIsEscape= isEscape;
78
		}
79
80
		/**
81
		 * Computes applicable proposals for the find field.
82
		 * @return the proposals
83
		 */
84
		public ICompletionProposal[] computeFindProposals() {
85
			//characters
86
			addBsProposal("\\\\", RegExMessages.displayString_bs_bs, RegExMessages.additionalInfo_bs_bs); //$NON-NLS-1$
87
			addBracketProposal("\\0", 2, RegExMessages.displayString_bs_0, RegExMessages.additionalInfo_bs_0); //$NON-NLS-1$
88
			addBracketProposal("\\x", 2, RegExMessages.displayString_bs_x, RegExMessages.additionalInfo_bs_x); //$NON-NLS-1$
89
			addBracketProposal("\\u", 2, RegExMessages.displayString_bs_u, RegExMessages.additionalInfo_bs_u); //$NON-NLS-1$
90
			addBsProposal("\\t", RegExMessages.displayString_bs_t, RegExMessages.additionalInfo_bs_t); //$NON-NLS-1$
91
			addBsProposal("\\n", RegExMessages.displayString_bs_n, RegExMessages.additionalInfo_bs_n); //$NON-NLS-1$
92
			addBsProposal("\\r", RegExMessages.displayString_bs_r, RegExMessages.additionalInfo_bs_r); //$NON-NLS-1$
93
			addBsProposal("\\f", RegExMessages.displayString_bs_f, RegExMessages.additionalInfo_bs_f); //$NON-NLS-1$
94
			addBsProposal("\\a", RegExMessages.displayString_bs_a, RegExMessages.additionalInfo_bs_a); //$NON-NLS-1$
95
			addBsProposal("\\e", RegExMessages.displayString_bs_e, RegExMessages.additionalInfo_bs_e); //$NON-NLS-1$
96
			addBsProposal("\\c", RegExMessages.displayString_bs_c, RegExMessages.additionalInfo_bs_c); //$NON-NLS-1$
97
			
98
			if (! fIsEscape)
99
				addBracketProposal(".", 1, RegExMessages.displayString_dot, RegExMessages.additionalInfo_dot); //$NON-NLS-1$
100
			addBsProposal("\\d", RegExMessages.displayString_bs_d, RegExMessages.additionalInfo_bs_d); //$NON-NLS-1$
101
			addBsProposal("\\D", RegExMessages.displayString_bs_D, RegExMessages.additionalInfo_bs_D); //$NON-NLS-1$
102
			addBsProposal("\\s", RegExMessages.displayString_bs_s, RegExMessages.additionalInfo_bs_s); //$NON-NLS-1$
103
			addBsProposal("\\S", RegExMessages.displayString_bs_S, RegExMessages.additionalInfo_bs_S); //$NON-NLS-1$
104
			addBsProposal("\\w", RegExMessages.displayString_bs_w, RegExMessages.additionalInfo_bs_w); //$NON-NLS-1$
105
			addBsProposal("\\W", RegExMessages.displayString_bs_W, RegExMessages.additionalInfo_bs_W); //$NON-NLS-1$
106
			
107
			// backreference
108
			addBsProposal("\\", RegExMessages.displayString_bs_i, RegExMessages.additionalInfo_bs_i); //$NON-NLS-1$
109
			
110
			//quoting
111
			addBsProposal("\\", RegExMessages.displayString_bs, RegExMessages.additionalInfo_bs); //$NON-NLS-1$
112
			addBsProposal("\\Q", RegExMessages.displayString_bs_Q, RegExMessages.additionalInfo_bs_Q); //$NON-NLS-1$
113
			addBsProposal("\\E", RegExMessages.displayString_bs_E, RegExMessages.additionalInfo_bs_E); //$NON-NLS-1$
114
			
115
			//character sets
116
			if (! fIsEscape) {
117
				addBracketProposal("[]", 1, RegExMessages.displayString_set, RegExMessages.additionalInfo_set); //$NON-NLS-1$
118
				addBracketProposal("[^]", 2, RegExMessages.displayString_setExcl, RegExMessages.additionalInfo_setExcl); //$NON-NLS-1$
119
				addBracketProposal("[-]", 1, RegExMessages.displayString_setRange, RegExMessages.additionalInfo_setRange); //$NON-NLS-1$
120
				addProposal("&&", RegExMessages.displayString_setInter, RegExMessages.additionalInfo_setInter); //$NON-NLS-1$
121
			}
122
			if (! fIsEscape && fDocumentOffset > 0 && fExpression.charAt(fDocumentOffset - 1) == '\\') {
123
				addProposal("\\p{}", 3, RegExMessages.displayString_posix, RegExMessages.additionalInfo_posix); //$NON-NLS-1$
124
				addProposal("\\P{}", 3, RegExMessages.displayString_posixNot, RegExMessages.additionalInfo_posixNot); //$NON-NLS-1$
125
			} else {
126
				addBracketProposal("\\p{}", 3, RegExMessages.displayString_posix, RegExMessages.additionalInfo_posix); //$NON-NLS-1$
127
				addBracketProposal("\\P{}", 3, RegExMessages.displayString_posixNot, RegExMessages.additionalInfo_posixNot); //$NON-NLS-1$
128
			}
129
			
130
//			addBsProposal("\\p{Lower}", RegExMessages.displayString_bs_p{Lower}, RegExMessages.additionalInfo_bs_p{Lower}); //$NON-NLS-1$
131
//			addBsProposal("\\p{Upper}", RegExMessages.displayString_bs_p{Upper}, RegExMessages.additionalInfo_bs_p{Upper}); //$NON-NLS-1$
132
//			addBsProposal("\\p{ASCII}", RegExMessages.displayString_bs_p{ASCII}, RegExMessages.additionalInfo_bs_p{ASCII}); //$NON-NLS-1$
133
//			addBsProposal("\\p{Alpha}", RegExMessages.displayString_bs_p{Alpha}, RegExMessages.additionalInfo_bs_p{Alpha}); //$NON-NLS-1$
134
//			addBsProposal("\\p{Digit}", RegExMessages.displayString_bs_p{Digit}, RegExMessages.additionalInfo_bs_p{Digit}); //$NON-NLS-1$
135
//			addBsProposal("\\p{Alnum}", RegExMessages.displayString_bs_p{Alnum}, RegExMessages.additionalInfo_bs_p{Alnum}); //$NON-NLS-1$
136
//			addBsProposal("\\p{Punct}", RegExMessages.displayString_bs_p{Punct}, RegExMessages.additionalInfo_bs_p{Punct}); //$NON-NLS-1$
137
//			addBsProposal("\\p{Graph}", RegExMessages.displayString_bs_p{Graph}, RegExMessages.additionalInfo_bs_p{Graph}); //$NON-NLS-1$
138
//			addBsProposal("\\p{Print}", RegExMessages.displayString_bs_p{Print}, RegExMessages.additionalInfo_bs_p{Print}); //$NON-NLS-1$
139
//			addBsProposal("\\p{Blank}", RegExMessages.displayString_bs_p{Blank}, RegExMessages.additionalInfo_bs_p{Blank}); //$NON-NLS-1$
140
//			addBsProposal("\\p{Cntrl}", RegExMessages.displayString_bs_p{Cntrl}, RegExMessages.additionalInfo_bs_p{Cntrl}); //$NON-NLS-1$
141
//			addBsProposal("\\p{XDigit}", RegExMessages.displayString_bs_p{XDigit}, RegExMessages.additionalInfo_bs_p{XDigit}); //$NON-NLS-1$
142
//			addBsProposal("\\p{Space}", RegExMessages.displayString_bs_p{Space}, RegExMessages.additionalInfo_bs_p{Space}); //$NON-NLS-1$
143
//
144
//			addBsProposal("\\p{InGreek}", RegExMessages.displayString_bs_p{InGreek}, RegExMessages.additionalInfo_bs_p{InGreek}); //$NON-NLS-1$
145
//			addBsProposal("\\p{Lu}", RegExMessages.displayString_bs_p{Lu}, RegExMessages.additionalInfo_bs_p{Lu}); //$NON-NLS-1$
146
//			addBsProposal("\\p{Sc}", RegExMessages.displayString_bs_p{Sc}, RegExMessages.additionalInfo_bs_p{Sc}); //$NON-NLS-1$
147
//			addBsProposal("\\P{InGreek}", RegExMessages.displayString_bs_P{InGreek}, RegExMessages.additionalInfo_bs_P{InGreek}); //$NON-NLS-1$
148
			
149
			//boundary matchers
150
			if (fDocumentOffset == 0) {
151
				addPriorityProposal("^", RegExMessages.displayString_start, RegExMessages.additionalInfo_start); //$NON-NLS-1$
152
			} else if (fDocumentOffset == 1 && fExpression.charAt(0) == '^') {
153
				addBracketProposal("^", 1, RegExMessages.displayString_start, RegExMessages.additionalInfo_start); //$NON-NLS-1$
154
			}
155
			if (fDocumentOffset == fExpression.length()) {
156
				addProposal("$", RegExMessages.displayString_end, RegExMessages.additionalInfo_end); //$NON-NLS-1$
157
			}
158
			addBsProposal("\\b", RegExMessages.displayString_bs_b, RegExMessages.additionalInfo_bs_b); //$NON-NLS-1$
159
			addBsProposal("\\B", RegExMessages.displayString_bs_B, RegExMessages.additionalInfo_bs_B); //$NON-NLS-1$
160
			addBsProposal("\\A", RegExMessages.displayString_bs_A, RegExMessages.additionalInfo_bs_A); //$NON-NLS-1$
161
			addBsProposal("\\G", RegExMessages.displayString_bs_G, RegExMessages.additionalInfo_bs_G); //$NON-NLS-1$
162
			addBsProposal("\\Z", RegExMessages.displayString_bs_Z, RegExMessages.additionalInfo_bs_Z); //$NON-NLS-1$
163
			addBsProposal("\\z", RegExMessages.displayString_bs_z, RegExMessages.additionalInfo_bs_z); //$NON-NLS-1$
164
			
165
			if (! fIsEscape) {
166
				//capturing groups
167
				addBracketProposal("()", 1, RegExMessages.displayString_group, RegExMessages.additionalInfo_group); //$NON-NLS-1$
168
				
169
				//flags
170
				addBracketProposal("(?)", 2, RegExMessages.displayString_flag, RegExMessages.additionalInfo_flag); //$NON-NLS-1$
171
				addBracketProposal("(?:)", 3, RegExMessages.displayString_flagExpr, RegExMessages.additionalInfo_flagExpr); //$NON-NLS-1$
172
			
173
				//noncapturing group
174
				addBracketProposal("(?:)", 3, RegExMessages.displayString_nonCap, RegExMessages.additionalInfo_nonCap); //$NON-NLS-1$
175
				addBracketProposal("(?>)", 3, RegExMessages.displayString_atomicCap, RegExMessages.additionalInfo_atomicCap); //$NON-NLS-1$
176
				
177
				//lookaraound
178
				addBracketProposal("(?=)", 3, RegExMessages.displayString_posLookahead, RegExMessages.additionalInfo_posLookahead); //$NON-NLS-1$
179
				addBracketProposal("(?!)", 3, RegExMessages.displayString_negLookahead, RegExMessages.additionalInfo_negLookahead); //$NON-NLS-1$
180
				addBracketProposal("(?<=)", 4, RegExMessages.displayString_posLookbehind, RegExMessages.additionalInfo_posLookbehind); //$NON-NLS-1$
181
				addBracketProposal("(?<!)", 4, RegExMessages.displayString_negLookbehind, RegExMessages.additionalInfo_negLookbehind); //$NON-NLS-1$
182
				
183
				//greedy quantifiers
184
				addBracketProposal("?", 1, RegExMessages.displayString_quest, RegExMessages.additionalInfo_quest); //$NON-NLS-1$
185
				addBracketProposal("*", 1, RegExMessages.displayString_star, RegExMessages.additionalInfo_star); //$NON-NLS-1$
186
				addBracketProposal("+", 1, RegExMessages.displayString_plus, RegExMessages.additionalInfo_plus); //$NON-NLS-1$
187
				addBracketProposal("{}", 1, RegExMessages.displayString_exact, RegExMessages.additionalInfo_exact); //$NON-NLS-1$
188
				addBracketProposal("{,}", 1, RegExMessages.displayString_least, RegExMessages.additionalInfo_least); //$NON-NLS-1$
189
				addBracketProposal("{,}", 1, RegExMessages.displayString_count, RegExMessages.additionalInfo_count); //$NON-NLS-1$
190
				
191
				//lazy quantifiers
192
				addBracketProposal("??", 1, RegExMessages.displayString_questLazy, RegExMessages.additionalInfo_questLazy); //$NON-NLS-1$
193
				addBracketProposal("*?", 1, RegExMessages.displayString_starLazy, RegExMessages.additionalInfo_starLazy); //$NON-NLS-1$
194
				addBracketProposal("+?", 1, RegExMessages.displayString_plusLazy, RegExMessages.additionalInfo_plusLazy); //$NON-NLS-1$
195
				addBracketProposal("{}?", 1, RegExMessages.displayString_exactLazy, RegExMessages.additionalInfo_exactLazy); //$NON-NLS-1$
196
				addBracketProposal("{,}?", 1, RegExMessages.displayString_leastLazy, RegExMessages.additionalInfo_leastLazy); //$NON-NLS-1$
197
				addBracketProposal("{,}?", 1, RegExMessages.displayString_countLazy, RegExMessages.additionalInfo_countLazy); //$NON-NLS-1$
198
				
199
				//possessive quantifiers
200
				addBracketProposal("?+", 1, RegExMessages.displayString_questPoss, RegExMessages.additionalInfo_questPoss); //$NON-NLS-1$
201
				addBracketProposal("*+", 1, RegExMessages.displayString_starPoss, RegExMessages.additionalInfo_starPoss); //$NON-NLS-1$
202
				addBracketProposal("++", 1, RegExMessages.displayString_plusPoss, RegExMessages.additionalInfo_plusPoss); //$NON-NLS-1$
203
				addBracketProposal("{}+", 1, RegExMessages.displayString_exactPoss, RegExMessages.additionalInfo_exactPoss); //$NON-NLS-1$
204
				addBracketProposal("{,}+", 1, RegExMessages.displayString_leastPoss, RegExMessages.additionalInfo_leastPoss); //$NON-NLS-1$
205
				addBracketProposal("{,}+", 1, RegExMessages.displayString_countPoss, RegExMessages.additionalInfo_countPoss); //$NON-NLS-1$
206
				
207
				//alternative
208
				addBracketProposal("|", 1, RegExMessages.displayString_alt, RegExMessages.additionalInfo_alt); //$NON-NLS-1$
209
			}
210
			
211
			fPriorityProposals.addAll(fProposals);
212
			return (ICompletionProposal[]) fPriorityProposals.toArray(new ICompletionProposal[fProposals.size()]);
213
		}
214
215
		/**
216
		 * Computes applicable proposals for the replace field.
217
		 * @return the proposals
218
		 */
219
		public ICompletionProposal[] computeReplaceProposals() {
220
			if (fDocumentOffset > 0 && '$' == fExpression.charAt(fDocumentOffset - 1)) {
221
				addProposal("", RegExMessages.displayString_dollar, RegExMessages.additionalInfo_dollar); //$NON-NLS-1$
222
			} else {
223
				addProposal("$", RegExMessages.displayString_dollar, RegExMessages.additionalInfo_dollar); //$NON-NLS-1$
224
				addBsProposal("\\", RegExMessages.displayString_replace_bs, RegExMessages.additionalInfo_replace_bs); //$NON-NLS-1$
225
				addProposal("\t", RegExMessages.displayString_tab, RegExMessages.additionalInfo_tab); //$NON-NLS-1$
226
			}
227
			return (ICompletionProposal[]) fProposals.toArray(new ICompletionProposal[fProposals.size()]);
228
		}
229
		
230
		/**
231
		 * Adds a proposal.
232
		 * 
233
		 * @param proposal the string to be inserted
234
		 * @param displayString the proposal's label
235
		 * @param additionalInfo the additional information
236
		 */
237
		private void addProposal(String proposal, String displayString, String additionalInfo) {
238
			fProposals.add(new CompletionProposal(proposal, fDocumentOffset, 0, proposal.length(), null, displayString, null, additionalInfo));
239
		}
240
241
		/**
242
		 * Adds a proposal.
243
		 * 
244
		 * @param proposal the string to be inserted
245
		 * @param cursorPosition the cursor position after insertion,
246
		 * 		relative to the start of the proposal
247
		 * @param displayString the proposal's label
248
		 * @param additionalInfo the additional information
249
		 */
250
		private void addProposal(String proposal, int cursorPosition, String displayString, String additionalInfo) {
251
			fProposals.add(new CompletionProposal(proposal, fDocumentOffset, 0, cursorPosition, null, displayString, null, additionalInfo));
252
		}
253
254
		/**
255
		 * Adds a proposal to the priority proposals list.
256
		 * 
257
		 * @param proposal the string to be inserted
258
		 * @param displayString the proposal's label
259
		 * @param additionalInfo the additional information
260
		 */
261
		private void addPriorityProposal(String proposal, String displayString, String additionalInfo) {
262
			fPriorityProposals.add(new CompletionProposal(proposal, fDocumentOffset, 0, proposal.length(), null, displayString, null, additionalInfo));
263
		}
264
		
265
		/**
266
		 * Adds a proposal. Ensures that existing pre- and postfixes are not duplicated.
267
		 * 
268
		 * @param proposal the string to be inserted
269
		 * @param cursorPosition the cursor position after insertion,
270
		 * 		relative to the start of the proposal
271
		 * @param displayString the proposal's label
272
		 * @param additionalInfo the additional information
273
		 */
274
		private void addBracketProposal(String proposal, int cursorPosition, String displayString, String additionalInfo) {
275
			String prolog= fExpression.substring(0, fDocumentOffset);
276
			if (! fIsEscape && prolog.endsWith("\\") && proposal.startsWith("\\")) { //$NON-NLS-1$//$NON-NLS-2$
277
				fProposals.add(new CompletionProposal(proposal, fDocumentOffset, 0, cursorPosition, null, displayString, null, additionalInfo));
278
				return;
279
			}
280
			for (int i= 1; i <= cursorPosition; i++) {
281
				String prefix= proposal.substring(0, i);
282
				if (prolog.endsWith(prefix)) {
283
					String postfix= proposal.substring(cursorPosition);
284
					String epilog= fExpression.substring(fDocumentOffset);
285
					if (epilog.startsWith(postfix)) {
286
						fPriorityProposals.add(new CompletionProposal(proposal.substring(i, cursorPosition), fDocumentOffset, 0, cursorPosition - i, null, displayString, null, additionalInfo));
287
					} else {
288
						fPriorityProposals.add(new CompletionProposal(proposal.substring(i), fDocumentOffset, 0, cursorPosition - i, null, displayString, null, additionalInfo));
289
					}
290
					return;
291
				}
292
			}
293
			fProposals.add(new CompletionProposal(proposal, fDocumentOffset, 0, cursorPosition, null, displayString, null, additionalInfo));
294
		}
295
296
		/**
297
		 * Adds a proposal that starts with a backslash.
298
		 * 
299
		 * @param proposal the string to be inserted
300
		 * @param displayString the proposal's label
301
		 * @param additionalInfo the additional information
302
		 */
303
		private void addBsProposal(String proposal, String displayString, String additionalInfo) {
304
			if (fIsEscape) {
305
				fPriorityProposals.add(new CompletionProposal(proposal.substring(1), fDocumentOffset, 0, proposal.length() - 1, null, displayString, null, additionalInfo));
306
			} else {
307
				addProposal(proposal, displayString, additionalInfo);
308
			}
309
		}
310
	}
311
312
	/**
313
	 * The context information validator.
314
	 */
315
	private IContextInformationValidator fValidator= new SubjectControlContextInformationValidator(this);
316
317
	/**
318
	 * <code>true</code> iff the processor is for the find field.
319
	 * <code>false</code> iff the processor is for the replace field.
320
	 */
321
	private final boolean fIsFind;
322
	
323
	public RegExContentAssistProcessor(boolean isFind) {
324
		fIsFind= isFind;
325
	}
326
	
327
	/*
328
	 * @see IContentAssistProcessor#computeCompletionProposals(ITextViewer, int)
329
	 */
330
	public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
331
		throw new UnsupportedOperationException("ITextViewer not supported"); //$NON-NLS-1$
332
	}
333
334
	/*
335
	 * @see IContentAssistProcessor#computeContextInformation(ITextViewer, int)
336
	 */
337
	public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {
338
		throw new UnsupportedOperationException("ITextViewer not supported"); //$NON-NLS-1$
339
	}
340
341
	/*
342
	 * @see IContentAssistProcessor#getCompletionProposalAutoActivationCharacters()
343
	 */
344
	public char[] getCompletionProposalAutoActivationCharacters() {
345
		if (fIsFind)
346
			return new char[] {'\\', '[', '('};
347
		
348
		return new char[] {'$'};
349
	}
350
351
	/*
352
	 * @see IContentAssistProcessor#getContextInformationAutoActivationCharacters()
353
	 */
354
	public char[] getContextInformationAutoActivationCharacters() {
355
		return new char[] { };
356
	}
357
358
	/*
359
	 * @see IContentAssistProcessor#getContextInformationValidator()
360
	 */
361
	public IContextInformationValidator getContextInformationValidator() {
362
		return fValidator;
363
	}
364
365
	/*
366
	 * @see IContentAssistProcessor#getErrorMessage()
367
	 */
368
	public String getErrorMessage() {
369
		return null;
370
	}
371
372
	/*
373
	 * @see ISubjectControlContentAssistProcessor#computeCompletionProposals(IContentAssistSubjectControl, int)
374
	 */
375
	public ICompletionProposal[] computeCompletionProposals(IContentAssistSubjectControl contentAssistSubjectControl, int documentOffset) {
376
		if (fIsFind)
377
			return new ProposalComputer(contentAssistSubjectControl, documentOffset).computeFindProposals();
378
		
379
		return new ProposalComputer(contentAssistSubjectControl, documentOffset).computeReplaceProposals();
380
	}
381
382
	/*
383
	 * @see ISubjectControlContentAssistProcessor#computeContextInformation(IContentAssistSubjectControl, int)
384
	 */
385
	public IContextInformation[] computeContextInformation(IContentAssistSubjectControl contentAssistSubjectControl, int documentOffset) {
386
		return null;
387
	}
388
}
(-)search/org/eclipse/search/internal/ui/text/TextSearchPage.java (-14 / +26 lines)
Lines 40-45 Link Here
40
import org.eclipse.swt.widgets.Button;
40
import org.eclipse.swt.widgets.Button;
41
import org.eclipse.swt.widgets.Combo;
41
import org.eclipse.swt.widgets.Combo;
42
import org.eclipse.swt.widgets.Composite;
42
import org.eclipse.swt.widgets.Composite;
43
import org.eclipse.swt.widgets.Control;
43
import org.eclipse.swt.widgets.Display;
44
import org.eclipse.swt.widgets.Display;
44
import org.eclipse.swt.widgets.Label;
45
import org.eclipse.swt.widgets.Label;
45
46
Lines 47-52 Link Here
47
import org.eclipse.jface.dialogs.DialogPage;
48
import org.eclipse.jface.dialogs.DialogPage;
48
import org.eclipse.jface.dialogs.ErrorDialog;
49
import org.eclipse.jface.dialogs.ErrorDialog;
49
import org.eclipse.jface.dialogs.IDialogSettings;
50
import org.eclipse.jface.dialogs.IDialogSettings;
51
import org.eclipse.jface.fieldassist.ComboContentAdapter;
52
import org.eclipse.jface.fieldassist.IControlCreator;
50
import org.eclipse.jface.resource.JFaceColors;
53
import org.eclipse.jface.resource.JFaceColors;
51
import org.eclipse.jface.viewers.ISelection;
54
import org.eclipse.jface.viewers.ISelection;
52
import org.eclipse.jface.viewers.IStructuredSelection;
55
import org.eclipse.jface.viewers.IStructuredSelection;
Lines 60-66 Link Here
60
import org.eclipse.ui.IWorkingSet;
63
import org.eclipse.ui.IWorkingSet;
61
import org.eclipse.ui.IWorkingSetManager;
64
import org.eclipse.ui.IWorkingSetManager;
62
import org.eclipse.ui.PlatformUI;
65
import org.eclipse.ui.PlatformUI;
63
import org.eclipse.ui.contentassist.ContentAssistHandler;
66
import org.eclipse.ui.fieldassist.ContentAssistField;
67
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
64
68
65
import org.eclipse.search.ui.IReplacePage;
69
import org.eclipse.search.ui.IReplacePage;
66
import org.eclipse.search.ui.ISearchPage;
70
import org.eclipse.search.ui.ISearchPage;
Lines 110-116 Link Here
110
	private ISearchPageContainer fContainer;
114
	private ISearchPageContainer fContainer;
111
	private FileTypeEditor fFileTypeEditor;
115
	private FileTypeEditor fFileTypeEditor;
112
116
113
	private ContentAssistHandler fReplaceContentAssistHandler;
117
	/**
118
	 * Decorated find and replace fields.
119
	 * @since 3.2
120
	 */
121
	private ContentAssistField fContentAssistFindField;
122
	
114
    
123
    
115
	private static class SearchPatternData {
124
	private static class SearchPatternData {
116
		public final boolean isCaseSensitive;
125
		public final boolean isCaseSensitive;
Lines 494-500 Link Here
494
		label.setFont(group.getFont());
503
		label.setFont(group.getFont());
495
504
496
		// Pattern combo
505
		// Pattern combo
497
		fPattern= new Combo(group, SWT.SINGLE | SWT.BORDER);
506
		ComboContentAdapter contentAdapter= new ComboContentAdapter();
507
		RegExContentProposalProvider findProposer= new RegExContentProposalProvider(true);
508
		fContentAssistFindField= new ContentAssistField(group, SWT.DROP_DOWN | SWT.BORDER, 
509
				new IControlCreator() {
510
					public Control createControl(Composite controlParent, int style) {
511
						return new Combo(controlParent, SWT.SINGLE | SWT.BORDER);
512
					}
513
				}, 
514
				contentAdapter, findProposer, 
515
				ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS,
516
				new char[] {'\\', '[', '('});
517
		fPattern= (Combo)fContentAssistFindField.getControl();
518
		
498
		// Not done here to prevent page from resizing
519
		// Not done here to prevent page from resizing
499
		// fPattern.setItems(getPreviousSearchPatterns());
520
		// fPattern.setItems(getPreviousSearchPatterns());
500
		fPattern.addSelectionListener(new SelectionAdapter() {
521
		fPattern.addSelectionListener(new SelectionAdapter() {
Lines 512-518 Link Here
512
		fPattern.setFont(group.getFont());
533
		fPattern.setFont(group.getFont());
513
		GridData data= new GridData(GridData.FILL, GridData.FILL, true, false, 1, 1);
534
		GridData data= new GridData(GridData.FILL, GridData.FILL, true, false, 1, 1);
514
		data.widthHint= convertWidthInCharsToPixels(50);
535
		data.widthHint= convertWidthInCharsToPixels(50);
515
		fPattern.setLayoutData(data);
536
		fContentAssistFindField.getLayoutControl().setLayoutData(data);
516
		
537
		
517
		fIsCaseSensitiveCheckbox= new Button(group, SWT.CHECK);
538
		fIsCaseSensitiveCheckbox= new Button(group, SWT.CHECK);
518
		fIsCaseSensitiveCheckbox.setText(SearchMessages.SearchPage_caseSensitive); 
539
		fIsCaseSensitiveCheckbox.setText(SearchMessages.SearchPage_caseSensitive); 
Lines 765-780 Link Here
765
	}
786
	}
766
	
787
	
767
	private void setContentAssistsEnablement(boolean enable) {
788
	private void setContentAssistsEnablement(boolean enable) {
768
		if (enable) {
789
		fContentAssistFindField.setEnabled(enable);
769
			if (fReplaceContentAssistHandler == null) {
770
				fReplaceContentAssistHandler= ContentAssistHandler.createHandlerForCombo(fPattern, ReplaceDialog2.createContentAssistant(true));
771
			}
772
			fReplaceContentAssistHandler.setEnabled(true);
773
		} else {
774
			if (fReplaceContentAssistHandler == null)
775
				return;
776
			fReplaceContentAssistHandler.setEnabled(false);
777
		}
778
	}
790
	}
779
791
780
	private void statusMessage(boolean error, String message) {
792
	private void statusMessage(boolean error, String message) {
(-)search/org/eclipse/search/internal/ui/text/RegExContentProposalProvider.java (+375 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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
12
package org.eclipse.search.internal.ui.text;
13
14
import java.util.ArrayList;
15
16
import org.eclipse.jface.fieldassist.IContentProposal;
17
import org.eclipse.jface.fieldassist.IContentProposalProvider;
18
19
/**
20
 * Content assist proposal provider for regular expressions.
21
 * <p>
22
 * Note: Replaces <code>RegExContentAssistProcessor</code> which was introduced in 3.0.
23
 * </p>
24
 *
25
 * @since 3.2
26
 */
27
final class RegExContentProposalProvider implements IContentProposalProvider {
28
29
	
30
	/**
31
	 * Proposal computer.
32
	 */
33
	private static class ProposalComputer {
34
35
		private static class Proposal implements IContentProposal {
36
			
37
			private String fContent;
38
			private String fLabel;
39
			private String fDescription;
40
			private int fCursorPosition;
41
			
42
			Proposal(String content, String label, String description, int cursorPosition) {
43
				fContent= content;
44
				fLabel= label;
45
				fDescription= description;
46
				fCursorPosition= cursorPosition;
47
			}
48
			
49
			public String getContent() {
50
				return fContent;
51
			}
52
			
53
			public String getLabel() {
54
				return fLabel;
55
			}
56
			
57
			public String getDescription() {
58
				return fDescription;
59
			}
60
			
61
			public int getCursorPosition() {
62
				return fCursorPosition;
63
			}
64
		}
65
		
66
67
		/**
68
		 * The whole regular expression.
69
		 */
70
		private final String fExpression;
71
		/**
72
		 * The document offset.
73
		 */
74
		private final int fDocumentOffset;
75
		/**
76
		 * The high-priority proposals.
77
		 */
78
		private final ArrayList fPriorityProposals;
79
		/**
80
		 * The low-priority proposals.
81
		 */
82
		private final ArrayList fProposals;
83
		/**
84
		 * <code>true</code> iff <code>fExpression</code> ends with an open escape.
85
		 */
86
		private final boolean fIsEscape;
87
88
		/**
89
		 * Creates a new Proposal Computer.
90
		 * @param contents the contents of the the subject control
91
		 * @param position the cursor position
92
		 */
93
		public ProposalComputer(String contents, int position) {
94
			fExpression= contents;
95
			fDocumentOffset= position;
96
			fPriorityProposals= new ArrayList();
97
			fProposals= new ArrayList();
98
			
99
			boolean isEscape= false;
100
			esc: for (int i= position - 1; i >= 0; i--) {
101
				if (fExpression.charAt(i) == '\\')
102
					isEscape= !isEscape;
103
				else
104
					break esc;
105
			}
106
			fIsEscape= isEscape;
107
		}
108
109
		/**
110
		 * Computes applicable proposals for the find field.
111
		 * @return the proposals
112
		 */
113
		public IContentProposal[] computeFindProposals() {
114
			//characters
115
			addBsProposal("\\\\", RegExMessages.displayString_bs_bs, RegExMessages.additionalInfo_bs_bs); //$NON-NLS-1$
116
			addBracketProposal("\\0", 2, RegExMessages.displayString_bs_0, RegExMessages.additionalInfo_bs_0); //$NON-NLS-1$
117
			addBracketProposal("\\x", 2, RegExMessages.displayString_bs_x, RegExMessages.additionalInfo_bs_x); //$NON-NLS-1$
118
			addBracketProposal("\\u", 2, RegExMessages.displayString_bs_u, RegExMessages.additionalInfo_bs_u); //$NON-NLS-1$
119
			addBsProposal("\\t", RegExMessages.displayString_bs_t, RegExMessages.additionalInfo_bs_t); //$NON-NLS-1$
120
			addBsProposal("\\n", RegExMessages.displayString_bs_n, RegExMessages.additionalInfo_bs_n); //$NON-NLS-1$
121
			addBsProposal("\\r", RegExMessages.displayString_bs_r, RegExMessages.additionalInfo_bs_r); //$NON-NLS-1$
122
			addBsProposal("\\f", RegExMessages.displayString_bs_f, RegExMessages.additionalInfo_bs_f); //$NON-NLS-1$
123
			addBsProposal("\\a", RegExMessages.displayString_bs_a, RegExMessages.additionalInfo_bs_a); //$NON-NLS-1$
124
			addBsProposal("\\e", RegExMessages.displayString_bs_e, RegExMessages.additionalInfo_bs_e); //$NON-NLS-1$
125
			addBsProposal("\\c", RegExMessages.displayString_bs_c, RegExMessages.additionalInfo_bs_c); //$NON-NLS-1$
126
			
127
			if (! fIsEscape)
128
				addBracketProposal(".", 1, RegExMessages.displayString_dot, RegExMessages.additionalInfo_dot); //$NON-NLS-1$
129
			addBsProposal("\\d", RegExMessages.displayString_bs_d, RegExMessages.additionalInfo_bs_d); //$NON-NLS-1$
130
			addBsProposal("\\D", RegExMessages.displayString_bs_D, RegExMessages.additionalInfo_bs_D); //$NON-NLS-1$
131
			addBsProposal("\\s", RegExMessages.displayString_bs_s, RegExMessages.additionalInfo_bs_s); //$NON-NLS-1$
132
			addBsProposal("\\S", RegExMessages.displayString_bs_S, RegExMessages.additionalInfo_bs_S); //$NON-NLS-1$
133
			addBsProposal("\\w", RegExMessages.displayString_bs_w, RegExMessages.additionalInfo_bs_w); //$NON-NLS-1$
134
			addBsProposal("\\W", RegExMessages.displayString_bs_W, RegExMessages.additionalInfo_bs_W); //$NON-NLS-1$
135
			
136
			// back reference
137
			addBsProposal("\\", RegExMessages.displayString_bs_i, RegExMessages.additionalInfo_bs_i); //$NON-NLS-1$
138
			
139
			//quoting
140
			addBsProposal("\\", RegExMessages.displayString_bs, RegExMessages.additionalInfo_bs); //$NON-NLS-1$
141
			addBsProposal("\\Q", RegExMessages.displayString_bs_Q, RegExMessages.additionalInfo_bs_Q); //$NON-NLS-1$
142
			addBsProposal("\\E", RegExMessages.displayString_bs_E, RegExMessages.additionalInfo_bs_E); //$NON-NLS-1$
143
			
144
			//character sets
145
			if (! fIsEscape) {
146
				addBracketProposal("[]", 1, RegExMessages.displayString_set, RegExMessages.additionalInfo_set); //$NON-NLS-1$
147
				addBracketProposal("[^]", 2, RegExMessages.displayString_setExcl, RegExMessages.additionalInfo_setExcl); //$NON-NLS-1$
148
				addBracketProposal("[-]", 1, RegExMessages.displayString_setRange, RegExMessages.additionalInfo_setRange); //$NON-NLS-1$
149
				addProposal("&&", RegExMessages.displayString_setInter, RegExMessages.additionalInfo_setInter); //$NON-NLS-1$
150
			}
151
			if (! fIsEscape && fDocumentOffset > 0 && fExpression.charAt(fDocumentOffset - 1) == '\\') {
152
				addProposal("\\p{}", 3, RegExMessages.displayString_posix, RegExMessages.additionalInfo_posix); //$NON-NLS-1$
153
				addProposal("\\P{}", 3, RegExMessages.displayString_posixNot, RegExMessages.additionalInfo_posixNot); //$NON-NLS-1$
154
			} else {
155
				addBracketProposal("\\p{}", 3, RegExMessages.displayString_posix, RegExMessages.additionalInfo_posix); //$NON-NLS-1$
156
				addBracketProposal("\\P{}", 3, RegExMessages.displayString_posixNot, RegExMessages.additionalInfo_posixNot); //$NON-NLS-1$
157
			}
158
			
159
//			addBsProposal("\\p{Lower}", RegExMessages.displayString_bs_p{Lower}, RegExMessages.additionalInfo_bs_p{Lower}); //$NON-NLS-1$
160
//			addBsProposal("\\p{Upper}", RegExMessages.displayString_bs_p{Upper}, RegExMessages.additionalInfo_bs_p{Upper}); //$NON-NLS-1$
161
//			addBsProposal("\\p{ASCII}", RegExMessages.displayString_bs_p{ASCII}, RegExMessages.additionalInfo_bs_p{ASCII}); //$NON-NLS-1$
162
//			addBsProposal("\\p{Alpha}", RegExMessages.displayString_bs_p{Alpha}, RegExMessages.additionalInfo_bs_p{Alpha}); //$NON-NLS-1$
163
//			addBsProposal("\\p{Digit}", RegExMessages.displayString_bs_p{Digit}, RegExMessages.additionalInfo_bs_p{Digit}); //$NON-NLS-1$
164
//			addBsProposal("\\p{Alnum}", RegExMessages.displayString_bs_p{Alnum}, RegExMessages.additionalInfo_bs_p{Alnum}); //$NON-NLS-1$
165
//			addBsProposal("\\p{Punct}", RegExMessages.displayString_bs_p{Punct}, RegExMessages.additionalInfo_bs_p{Punct}); //$NON-NLS-1$
166
//			addBsProposal("\\p{Graph}", RegExMessages.displayString_bs_p{Graph}, RegExMessages.additionalInfo_bs_p{Graph}); //$NON-NLS-1$
167
//			addBsProposal("\\p{Print}", RegExMessages.displayString_bs_p{Print}, RegExMessages.additionalInfo_bs_p{Print}); //$NON-NLS-1$
168
//			addBsProposal("\\p{Blank}", RegExMessages.displayString_bs_p{Blank}, RegExMessages.additionalInfo_bs_p{Blank}); //$NON-NLS-1$
169
//			addBsProposal("\\p{Cntrl}", RegExMessages.displayString_bs_p{Cntrl}, RegExMessages.additionalInfo_bs_p{Cntrl}); //$NON-NLS-1$
170
//			addBsProposal("\\p{XDigit}", RegExMessages.displayString_bs_p{XDigit}, RegExMessages.additionalInfo_bs_p{XDigit}); //$NON-NLS-1$
171
//			addBsProposal("\\p{Space}", RegExMessages.displayString_bs_p{Space}, RegExMessages.additionalInfo_bs_p{Space}); //$NON-NLS-1$
172
//
173
//			addBsProposal("\\p{InGreek}", RegExMessages.displayString_bs_p{InGreek}, RegExMessages.additionalInfo_bs_p{InGreek}); //$NON-NLS-1$
174
//			addBsProposal("\\p{Lu}", RegExMessages.displayString_bs_p{Lu}, RegExMessages.additionalInfo_bs_p{Lu}); //$NON-NLS-1$
175
//			addBsProposal("\\p{Sc}", RegExMessages.displayString_bs_p{Sc}, RegExMessages.additionalInfo_bs_p{Sc}); //$NON-NLS-1$
176
//			addBsProposal("\\P{InGreek}", RegExMessages.displayString_bs_P{InGreek}, RegExMessages.additionalInfo_bs_P{InGreek}); //$NON-NLS-1$
177
			
178
			//boundary matchers
179
			if (fDocumentOffset == 0) {
180
				addPriorityProposal("^", RegExMessages.displayString_start, RegExMessages.additionalInfo_start); //$NON-NLS-1$
181
			} else if (fDocumentOffset == 1 && fExpression.charAt(0) == '^') {
182
				addBracketProposal("^", 1, RegExMessages.displayString_start, RegExMessages.additionalInfo_start); //$NON-NLS-1$
183
			}
184
			if (fDocumentOffset == fExpression.length()) {
185
				addProposal("$", RegExMessages.displayString_end, RegExMessages.additionalInfo_end); //$NON-NLS-1$
186
			}
187
			addBsProposal("\\b", RegExMessages.displayString_bs_b, RegExMessages.additionalInfo_bs_b); //$NON-NLS-1$
188
			addBsProposal("\\B", RegExMessages.displayString_bs_B, RegExMessages.additionalInfo_bs_B); //$NON-NLS-1$
189
			addBsProposal("\\A", RegExMessages.displayString_bs_A, RegExMessages.additionalInfo_bs_A); //$NON-NLS-1$
190
			addBsProposal("\\G", RegExMessages.displayString_bs_G, RegExMessages.additionalInfo_bs_G); //$NON-NLS-1$
191
			addBsProposal("\\Z", RegExMessages.displayString_bs_Z, RegExMessages.additionalInfo_bs_Z); //$NON-NLS-1$
192
			addBsProposal("\\z", RegExMessages.displayString_bs_z, RegExMessages.additionalInfo_bs_z); //$NON-NLS-1$
193
			
194
			if (! fIsEscape) {
195
				//capturing groups
196
				addBracketProposal("()", 1, RegExMessages.displayString_group, RegExMessages.additionalInfo_group); //$NON-NLS-1$
197
				
198
				//flags
199
				addBracketProposal("(?)", 2, RegExMessages.displayString_flag, RegExMessages.additionalInfo_flag); //$NON-NLS-1$
200
				addBracketProposal("(?:)", 3, RegExMessages.displayString_flagExpr, RegExMessages.additionalInfo_flagExpr); //$NON-NLS-1$
201
			
202
				//non-capturing group
203
				addBracketProposal("(?:)", 3, RegExMessages.displayString_nonCap, RegExMessages.additionalInfo_nonCap); //$NON-NLS-1$
204
				addBracketProposal("(?>)", 3, RegExMessages.displayString_atomicCap, RegExMessages.additionalInfo_atomicCap); //$NON-NLS-1$
205
				
206
				//lookaraound
207
				addBracketProposal("(?=)", 3, RegExMessages.displayString_posLookahead, RegExMessages.additionalInfo_posLookahead); //$NON-NLS-1$
208
				addBracketProposal("(?!)", 3, RegExMessages.displayString_negLookahead, RegExMessages.additionalInfo_negLookahead); //$NON-NLS-1$
209
				addBracketProposal("(?<=)", 4, RegExMessages.displayString_posLookbehind, RegExMessages.additionalInfo_posLookbehind); //$NON-NLS-1$
210
				addBracketProposal("(?<!)", 4, RegExMessages.displayString_negLookbehind, RegExMessages.additionalInfo_negLookbehind); //$NON-NLS-1$
211
				
212
				//greedy quantifiers
213
				addBracketProposal("?", 1, RegExMessages.displayString_quest, RegExMessages.additionalInfo_quest); //$NON-NLS-1$
214
				addBracketProposal("*", 1, RegExMessages.displayString_star, RegExMessages.additionalInfo_star); //$NON-NLS-1$
215
				addBracketProposal("+", 1, RegExMessages.displayString_plus, RegExMessages.additionalInfo_plus); //$NON-NLS-1$
216
				addBracketProposal("{}", 1, RegExMessages.displayString_exact, RegExMessages.additionalInfo_exact); //$NON-NLS-1$
217
				addBracketProposal("{,}", 1, RegExMessages.displayString_least, RegExMessages.additionalInfo_least); //$NON-NLS-1$
218
				addBracketProposal("{,}", 1, RegExMessages.displayString_count, RegExMessages.additionalInfo_count); //$NON-NLS-1$
219
				
220
				//lazy quantifiers
221
				addBracketProposal("??", 1, RegExMessages.displayString_questLazy, RegExMessages.additionalInfo_questLazy); //$NON-NLS-1$
222
				addBracketProposal("*?", 1, RegExMessages.displayString_starLazy, RegExMessages.additionalInfo_starLazy); //$NON-NLS-1$
223
				addBracketProposal("+?", 1, RegExMessages.displayString_plusLazy, RegExMessages.additionalInfo_plusLazy); //$NON-NLS-1$
224
				addBracketProposal("{}?", 1, RegExMessages.displayString_exactLazy, RegExMessages.additionalInfo_exactLazy); //$NON-NLS-1$
225
				addBracketProposal("{,}?", 1, RegExMessages.displayString_leastLazy, RegExMessages.additionalInfo_leastLazy); //$NON-NLS-1$
226
				addBracketProposal("{,}?", 1, RegExMessages.displayString_countLazy, RegExMessages.additionalInfo_countLazy); //$NON-NLS-1$
227
				
228
				//possessive quantifiers
229
				addBracketProposal("?+", 1, RegExMessages.displayString_questPoss, RegExMessages.additionalInfo_questPoss); //$NON-NLS-1$
230
				addBracketProposal("*+", 1, RegExMessages.displayString_starPoss, RegExMessages.additionalInfo_starPoss); //$NON-NLS-1$
231
				addBracketProposal("++", 1, RegExMessages.displayString_plusPoss, RegExMessages.additionalInfo_plusPoss); //$NON-NLS-1$
232
				addBracketProposal("{}+", 1, RegExMessages.displayString_exactPoss, RegExMessages.additionalInfo_exactPoss); //$NON-NLS-1$
233
				addBracketProposal("{,}+", 1, RegExMessages.displayString_leastPoss, RegExMessages.additionalInfo_leastPoss); //$NON-NLS-1$
234
				addBracketProposal("{,}+", 1, RegExMessages.displayString_countPoss, RegExMessages.additionalInfo_countPoss); //$NON-NLS-1$
235
				
236
				//alternative
237
				addBracketProposal("|", 1, RegExMessages.displayString_alt, RegExMessages.additionalInfo_alt); //$NON-NLS-1$
238
			}
239
			
240
			fPriorityProposals.addAll(fProposals);
241
			return (IContentProposal[]) fPriorityProposals.toArray(new IContentProposal[fProposals.size()]);
242
		}
243
244
		/**
245
		 * Computes applicable proposals for the replace field.
246
		 * @return the proposals
247
		 */
248
		public IContentProposal[] computeReplaceProposals() {
249
			if (fDocumentOffset > 0 && '$' == fExpression.charAt(fDocumentOffset - 1)) {
250
				addProposal("", RegExMessages.displayString_dollar, RegExMessages.additionalInfo_dollar); //$NON-NLS-1$
251
			} else {
252
				addProposal("$", RegExMessages.displayString_dollar, RegExMessages.additionalInfo_dollar); //$NON-NLS-1$
253
				addBsProposal("\\", RegExMessages.displayString_replace_bs, RegExMessages.additionalInfo_replace_bs); //$NON-NLS-1$
254
				addProposal("\t", RegExMessages.displayString_tab, RegExMessages.additionalInfo_tab); //$NON-NLS-1$
255
			}
256
			return (IContentProposal[]) fProposals.toArray(new IContentProposal[fProposals.size()]);
257
		}
258
		
259
		/**
260
		 * Adds a proposal.
261
		 * 
262
		 * @param proposal the string to be inserted
263
		 * @param displayString the proposal's label
264
		 * @param additionalInfo the additional information
265
		 */
266
		private void addProposal(String proposal, String displayString, String additionalInfo) {
267
			fProposals.add(new Proposal(proposal, displayString, additionalInfo, proposal.length()));
268
		}
269
270
		/**
271
		 * Adds a proposal.
272
		 * 
273
		 * @param proposal the string to be inserted
274
		 * @param cursorPosition the cursor position after insertion,
275
		 * 		relative to the start of the proposal
276
		 * @param displayString the proposal's label
277
		 * @param additionalInfo the additional information
278
		 */
279
		private void addProposal(String proposal, int cursorPosition, String displayString, String additionalInfo) {
280
			fProposals.add(new Proposal(proposal, displayString, additionalInfo, cursorPosition));
281
		}
282
283
		/**
284
		 * Adds a proposal to the priority proposals list.
285
		 * 
286
		 * @param proposal the string to be inserted
287
		 * @param displayString the proposal's label
288
		 * @param additionalInfo the additional information
289
		 */
290
		private void addPriorityProposal(String proposal, String displayString, String additionalInfo) {
291
			fPriorityProposals.add(new Proposal(proposal, displayString, additionalInfo, proposal.length()));
292
		}
293
		
294
		/**
295
		 * Adds a proposal. Ensures that existing pre- and postfixes are not duplicated.
296
		 * 
297
		 * @param proposal the string to be inserted
298
		 * @param cursorPosition the cursor position after insertion,
299
		 * 		relative to the start of the proposal
300
		 * @param displayString the proposal's label
301
		 * @param additionalInfo the additional information
302
		 */
303
		private void addBracketProposal(String proposal, int cursorPosition, String displayString, String additionalInfo) {
304
			String prolog= fExpression.substring(0, fDocumentOffset);
305
			if (! fIsEscape && prolog.endsWith("\\") && proposal.startsWith("\\")) { //$NON-NLS-1$//$NON-NLS-2$
306
				fProposals.add(new Proposal(proposal, displayString, additionalInfo, cursorPosition));
307
				return;
308
			}
309
			for (int i= 1; i <= cursorPosition; i++) {
310
				String prefix= proposal.substring(0, i);
311
				if (prolog.endsWith(prefix)) {
312
					String postfix= proposal.substring(cursorPosition);
313
					String epilog= fExpression.substring(fDocumentOffset);
314
					if (epilog.startsWith(postfix)) {
315
						fPriorityProposals.add(new Proposal(proposal.substring(i, cursorPosition), displayString, additionalInfo, cursorPosition-i));
316
					} else {
317
						fPriorityProposals.add(new Proposal(proposal.substring(i), displayString, additionalInfo, cursorPosition-i));
318
					}
319
					return;
320
				}
321
			}
322
			fProposals.add(new Proposal(proposal, displayString, additionalInfo, cursorPosition));
323
		}
324
325
		/**
326
		 * Adds a proposal that starts with a backslash.
327
		 * Ensures that the backslash is not repeated if already typed.
328
		 * 
329
		 * @param proposal the string to be inserted
330
		 * @param displayString the proposal's label
331
		 * @param additionalInfo the additional information
332
		 */
333
		private void addBsProposal(String proposal, String displayString, String additionalInfo) {
334
			String prolog= fExpression.substring(0, fDocumentOffset);
335
			int position= proposal.length();
336
			// If the string already contains the backslash, do not include in the proposal
337
			if (prolog.endsWith("\\")) { //$NON-NLS-1$
338
				position--;
339
				proposal= proposal.substring(1);
340
			}
341
342
			if (fIsEscape) {
343
				fPriorityProposals.add(new Proposal(proposal, displayString, additionalInfo, position));
344
			} else {
345
				addProposal(proposal, position, displayString, additionalInfo);
346
			}
347
		}
348
	}
349
	
350
	/**
351
	 * <code>true</code> iff the processor is for the find field.
352
	 * <code>false</code> iff the processor is for the replace field.
353
	 */
354
	private final boolean fIsFind;
355
	
356
357
	/**
358
	 * Creates a new completion proposal provider.
359
	 * 
360
	 * @param isFind <code>true</code> if the provider is used for the 'find' field
361
	 * 					<code>false</code> if the provider is used for the 'reaplce' field
362
	 */
363
	public RegExContentProposalProvider(boolean isFind) {
364
		fIsFind= isFind;
365
	}
366
	
367
	/*
368
	 * @see org.eclipse.jface.fieldassist.IContentProposalProvider#getProposals(java.lang.String, int)
369
	 */
370
	public IContentProposal [] getProposals(String contents, int position) {
371
		if (fIsFind)
372
			return new ProposalComputer(contents, position).computeFindProposals();
373
		return new ProposalComputer(contents, position).computeReplaceProposals();
374
	}
375
}

Return to bug 132833