129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2008 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 * Cagatay Calli <ccalli@gmail.com> - [find/replace] retain caps when replacing - https://bugs.eclipse.org/bugs/show_bug.cgi?id=28949
|
|
11 * Port to the D programming language:
|
|
12 * Frank Benoit <benoit@tionex.de>
|
|
13 *******************************************************************************/
|
|
14 module dwtx.jface.text.FindReplaceDocumentAdapterContentProposalProvider;
|
|
15
|
|
16 import dwt.dwthelper.utils;
|
|
17
|
|
18 import java.util.ArrayList;
|
|
19
|
|
20 import dwtx.jface.fieldassist.IContentProposal;
|
|
21 import dwtx.jface.fieldassist.IContentProposalProvider;
|
|
22
|
|
23
|
|
24 /**
|
|
25 * Content assist proposal provider for the {@link FindReplaceDocumentAdapter}.
|
|
26 * <p>
|
|
27 * Clients can subclass to provide additional proposals in case they are supported
|
|
28 * by their own find/replace mechanism.
|
|
29 * </p>
|
|
30 * <p>
|
|
31 * <strong>Note:</strong> Clients must not make any assumptions about the returned
|
|
32 * proposals. This can change from release to release to adapt to
|
|
33 * changes made in {@link FindReplaceDocumentAdapter}.
|
|
34 * </p>
|
|
35 *
|
|
36 * @since 3.4
|
|
37 */
|
|
38 public class FindReplaceDocumentAdapterContentProposalProvider : IContentProposalProvider {
|
|
39
|
|
40
|
|
41 /**
|
|
42 * Proposal computer.
|
|
43 */
|
|
44 private static class ProposalComputer {
|
|
45
|
|
46 private static class Proposal : IContentProposal {
|
|
47
|
|
48 private String fContent;
|
|
49 private String fLabel;
|
|
50 private String fDescription;
|
|
51 private int fCursorPosition;
|
|
52
|
|
53 Proposal(String content, String label, String description, int cursorPosition) {
|
|
54 fContent= content;
|
|
55 fLabel= label;
|
|
56 fDescription= description;
|
|
57 fCursorPosition= cursorPosition;
|
|
58 }
|
|
59
|
|
60 public String getContent() {
|
|
61 return fContent;
|
|
62 }
|
|
63
|
|
64 public String getLabel() {
|
|
65 return fLabel;
|
|
66 }
|
|
67
|
|
68 public String getDescription() {
|
|
69 return fDescription;
|
|
70 }
|
|
71
|
|
72 public int getCursorPosition() {
|
|
73 return fCursorPosition;
|
|
74 }
|
|
75 }
|
|
76
|
|
77
|
|
78 /**
|
|
79 * The whole regular expression.
|
|
80 */
|
|
81 private final String fExpression;
|
|
82 /**
|
|
83 * The document offset.
|
|
84 */
|
|
85 private final int fDocumentOffset;
|
|
86 /**
|
|
87 * The high-priority proposals.
|
|
88 */
|
|
89 private final ArrayList fPriorityProposals;
|
|
90 /**
|
|
91 * The low-priority proposals.
|
|
92 */
|
|
93 private final ArrayList fProposals;
|
|
94 /**
|
|
95 * <code>true</code> iff <code>fExpression</code> ends with an open escape.
|
|
96 */
|
|
97 private final bool fIsEscape;
|
|
98
|
|
99 /**
|
|
100 * Creates a new Proposal Computer.
|
|
101 * @param contents the contents of the subject control
|
|
102 * @param position the cursor position
|
|
103 */
|
|
104 public ProposalComputer(String contents, int position) {
|
|
105 fExpression= contents;
|
|
106 fDocumentOffset= position;
|
|
107 fPriorityProposals= new ArrayList();
|
|
108 fProposals= new ArrayList();
|
|
109
|
|
110 bool isEscape= false;
|
|
111 esc: for (int i= position - 1; i >= 0; i--) {
|
|
112 if (fExpression.charAt(i) is '\\')
|
|
113 isEscape= !isEscape;
|
|
114 else
|
|
115 break esc;
|
|
116 }
|
|
117 fIsEscape= isEscape;
|
|
118 }
|
|
119
|
|
120 /**
|
|
121 * Computes applicable proposals for the find field.
|
|
122 * @return the proposals
|
|
123 */
|
|
124 public IContentProposal[] computeFindProposals() {
|
|
125 //characters
|
|
126 addBsProposal("\\\\", RegExMessages.getString("displayString_bs_bs"), RegExMessages.getString("additionalInfo_bs_bs")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
127 addBracketProposal("\\0", 2, RegExMessages.getString("displayString_bs_0"), RegExMessages.getString("additionalInfo_bs_0")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
128 addBracketProposal("\\x", 2, RegExMessages.getString("displayString_bs_x"), RegExMessages.getString("additionalInfo_bs_x")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
129 addBracketProposal("\\u", 2, RegExMessages.getString("displayString_bs_u"), RegExMessages.getString("additionalInfo_bs_u")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
130 addBsProposal("\\t", RegExMessages.getString("displayString_bs_t"), RegExMessages.getString("additionalInfo_bs_t")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
131 addBsProposal("\\R", RegExMessages.getString("displayString_bs_R"), RegExMessages.getString("additionalInfo_bs_R")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
132 addBsProposal("\\n", RegExMessages.getString("displayString_bs_n"), RegExMessages.getString("additionalInfo_bs_n")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
133 addBsProposal("\\r", RegExMessages.getString("displayString_bs_r"), RegExMessages.getString("additionalInfo_bs_r")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
134 addBsProposal("\\f", RegExMessages.getString("displayString_bs_f"), RegExMessages.getString("additionalInfo_bs_f")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
135 addBsProposal("\\a", RegExMessages.getString("displayString_bs_a"), RegExMessages.getString("additionalInfo_bs_a")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
136 addBsProposal("\\e", RegExMessages.getString("displayString_bs_e"), RegExMessages.getString("additionalInfo_bs_e")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
137 addBracketProposal("\\c", 2, RegExMessages.getString("displayString_bs_c"), RegExMessages.getString("additionalInfo_bs_c")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
138
|
|
139 if (! fIsEscape)
|
|
140 addBracketProposal(".", 1, RegExMessages.getString("displayString_dot"), RegExMessages.getString("additionalInfo_dot")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
141 addBsProposal("\\d", RegExMessages.getString("displayString_bs_d"), RegExMessages.getString("additionalInfo_bs_d")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
142 addBsProposal("\\D", RegExMessages.getString("displayString_bs_D"), RegExMessages.getString("additionalInfo_bs_D")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
143 addBsProposal("\\s", RegExMessages.getString("displayString_bs_s"), RegExMessages.getString("additionalInfo_bs_s")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
144 addBsProposal("\\S", RegExMessages.getString("displayString_bs_S"), RegExMessages.getString("additionalInfo_bs_S")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
145 addBsProposal("\\w", RegExMessages.getString("displayString_bs_w"), RegExMessages.getString("additionalInfo_bs_w")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
146 addBsProposal("\\W", RegExMessages.getString("displayString_bs_W"), RegExMessages.getString("additionalInfo_bs_W")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
147
|
|
148 // back reference
|
|
149 addBsProposal("\\", RegExMessages.getString("displayString_bs_i"), RegExMessages.getString("additionalInfo_bs_i")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
150
|
|
151 //quoting
|
|
152 addBsProposal("\\", RegExMessages.getString("displayString_bs"), RegExMessages.getString("additionalInfo_bs")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
153 addBsProposal("\\Q", RegExMessages.getString("displayString_bs_Q"), RegExMessages.getString("additionalInfo_bs_Q")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
154 addBsProposal("\\E", RegExMessages.getString("displayString_bs_E"), RegExMessages.getString("additionalInfo_bs_E")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
155
|
|
156 //character sets
|
|
157 if (! fIsEscape) {
|
|
158 addBracketProposal("[]", 1, RegExMessages.getString("displayString_set"), RegExMessages.getString("additionalInfo_set")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
159 addBracketProposal("[^]", 2, RegExMessages.getString("displayString_setExcl"), RegExMessages.getString("additionalInfo_setExcl")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
160 addBracketProposal("[-]", 1, RegExMessages.getString("displayString_setRange"), RegExMessages.getString("additionalInfo_setRange")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
161 addProposal("&&", RegExMessages.getString("displayString_setInter"), RegExMessages.getString("additionalInfo_setInter")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
162 }
|
|
163 if (! fIsEscape && fDocumentOffset > 0 && fExpression.charAt(fDocumentOffset - 1) is '\\') {
|
|
164 addProposal("\\p{}", 3, RegExMessages.getString("displayString_posix"), RegExMessages.getString("additionalInfo_posix")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
165 addProposal("\\P{}", 3, RegExMessages.getString("displayString_posixNot"), RegExMessages.getString("additionalInfo_posixNot")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
166 } else {
|
|
167 addBracketProposal("\\p{}", 3, RegExMessages.getString("displayString_posix"), RegExMessages.getString("additionalInfo_posix")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
168 addBracketProposal("\\P{}", 3, RegExMessages.getString("displayString_posixNot"), RegExMessages.getString("additionalInfo_posixNot")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
169 }
|
|
170
|
|
171 //boundary matchers
|
|
172 if (fDocumentOffset is 0) {
|
|
173 addPriorityProposal("^", RegExMessages.getString("displayString_start"), RegExMessages.getString("additionalInfo_start")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
174 } else if (fDocumentOffset is 1 && fExpression.charAt(0) is '^') {
|
|
175 addBracketProposal("^", 1, RegExMessages.getString("displayString_start"), RegExMessages.getString("additionalInfo_start")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
176 }
|
|
177 if (fDocumentOffset is fExpression.length()) {
|
|
178 addProposal("$", RegExMessages.getString("displayString_end"), RegExMessages.getString("additionalInfo_end")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
179 }
|
|
180 addBsProposal("\\b", RegExMessages.getString("displayString_bs_b"), RegExMessages.getString("additionalInfo_bs_b")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
181 addBsProposal("\\B", RegExMessages.getString("displayString_bs_B"), RegExMessages.getString("additionalInfo_bs_B")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
182 addBsProposal("\\A", RegExMessages.getString("displayString_bs_A"), RegExMessages.getString("additionalInfo_bs_A")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
183 addBsProposal("\\G", RegExMessages.getString("displayString_bs_G"), RegExMessages.getString("additionalInfo_bs_G")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
184 addBsProposal("\\Z", RegExMessages.getString("displayString_bs_Z"), RegExMessages.getString("additionalInfo_bs_Z")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
185 addBsProposal("\\z", RegExMessages.getString("displayString_bs_z"), RegExMessages.getString("additionalInfo_bs_z")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
186
|
|
187 if (! fIsEscape) {
|
|
188 //capturing groups
|
|
189 addBracketProposal("()", 1, RegExMessages.getString("displayString_group"), RegExMessages.getString("additionalInfo_group")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
190
|
|
191 //flags
|
|
192 addBracketProposal("(?)", 2, RegExMessages.getString("displayString_flag"), RegExMessages.getString("additionalInfo_flag")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
193 addBracketProposal("(?:)", 3, RegExMessages.getString("displayString_flagExpr"), RegExMessages.getString("additionalInfo_flagExpr")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
194
|
|
195 //non-capturing group
|
|
196 addBracketProposal("(?:)", 3, RegExMessages.getString("displayString_nonCap"), RegExMessages.getString("additionalInfo_nonCap")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
197 addBracketProposal("(?>)", 3, RegExMessages.getString("displayString_atomicCap"), RegExMessages.getString("additionalInfo_atomicCap")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
198
|
|
199 //look around
|
|
200 addBracketProposal("(?=)", 3, RegExMessages.getString("displayString_posLookahead"), RegExMessages.getString("additionalInfo_posLookahead")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
201 addBracketProposal("(?!)", 3, RegExMessages.getString("displayString_negLookahead"), RegExMessages.getString("additionalInfo_negLookahead")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
202 addBracketProposal("(?<=)", 4, RegExMessages.getString("displayString_posLookbehind"), RegExMessages.getString("additionalInfo_posLookbehind")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
203 addBracketProposal("(?<!)", 4, RegExMessages.getString("displayString_negLookbehind"), RegExMessages.getString("additionalInfo_negLookbehind")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
204
|
|
205 //greedy quantifiers
|
|
206 addBracketProposal("?", 1, RegExMessages.getString("displayString_quest"), RegExMessages.getString("additionalInfo_quest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
207 addBracketProposal("*", 1, RegExMessages.getString("displayString_star"), RegExMessages.getString("additionalInfo_star")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
208 addBracketProposal("+", 1, RegExMessages.getString("displayString_plus"), RegExMessages.getString("additionalInfo_plus")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
209 addBracketProposal("{}", 1, RegExMessages.getString("displayString_exact"), RegExMessages.getString("additionalInfo_exact")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
210 addBracketProposal("{,}", 1, RegExMessages.getString("displayString_least"), RegExMessages.getString("additionalInfo_least")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
211 addBracketProposal("{,}", 1, RegExMessages.getString("displayString_count"), RegExMessages.getString("additionalInfo_count")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
212
|
|
213 //lazy quantifiers
|
|
214 addBracketProposal("??", 1, RegExMessages.getString("displayString_questLazy"), RegExMessages.getString("additionalInfo_questLazy")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
215 addBracketProposal("*?", 1, RegExMessages.getString("displayString_starLazy"), RegExMessages.getString("additionalInfo_starLazy")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
216 addBracketProposal("+?", 1, RegExMessages.getString("displayString_plusLazy"), RegExMessages.getString("additionalInfo_plusLazy")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
217 addBracketProposal("{}?", 1, RegExMessages.getString("displayString_exactLazy"), RegExMessages.getString("additionalInfo_exactLazy")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
218 addBracketProposal("{,}?", 1, RegExMessages.getString("displayString_leastLazy"), RegExMessages.getString("additionalInfo_leastLazy")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
219 addBracketProposal("{,}?", 1, RegExMessages.getString("displayString_countLazy"), RegExMessages.getString("additionalInfo_countLazy")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
220
|
|
221 //possessive quantifiers
|
|
222 addBracketProposal("?+", 1, RegExMessages.getString("displayString_questPoss"), RegExMessages.getString("additionalInfo_questPoss")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
223 addBracketProposal("*+", 1, RegExMessages.getString("displayString_starPoss"), RegExMessages.getString("additionalInfo_starPoss")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
224 addBracketProposal("++", 1, RegExMessages.getString("displayString_plusPoss"), RegExMessages.getString("additionalInfo_plusPoss")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
225 addBracketProposal("{}+", 1, RegExMessages.getString("displayString_exactPoss"), RegExMessages.getString("additionalInfo_exactPoss")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
226 addBracketProposal("{,}+", 1, RegExMessages.getString("displayString_leastPoss"), RegExMessages.getString("additionalInfo_leastPoss")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
227 addBracketProposal("{,}+", 1, RegExMessages.getString("displayString_countPoss"), RegExMessages.getString("additionalInfo_countPoss")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
228
|
|
229 //alternative
|
|
230 addBracketProposal("|", 1, RegExMessages.getString("displayString_alt"), RegExMessages.getString("additionalInfo_alt")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
231 }
|
|
232
|
|
233 fPriorityProposals.addAll(fProposals);
|
|
234 return (IContentProposal[]) fPriorityProposals.toArray(new IContentProposal[fProposals.size()]);
|
|
235 }
|
|
236
|
|
237 /**
|
|
238 * Computes applicable proposals for the replace field.
|
|
239 * @return the proposals
|
|
240 */
|
|
241 public IContentProposal[] computeReplaceProposals() {
|
|
242 if (fDocumentOffset > 0 && '$' is fExpression.charAt(fDocumentOffset - 1)) {
|
|
243 addProposal("", RegExMessages.getString("displayString_dollar"), RegExMessages.getString("additionalInfo_dollar")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
244 } else {
|
|
245 if (! fIsEscape)
|
|
246 addProposal("$", RegExMessages.getString("displayString_dollar"), RegExMessages.getString("additionalInfo_dollar")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
247 addBsProposal("\\", RegExMessages.getString("displayString_replace_cap"), RegExMessages.getString("additionalInfo_replace_cap")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
248 addBsProposal("\\", RegExMessages.getString("displayString_replace_bs"), RegExMessages.getString("additionalInfo_replace_bs")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
249 addBsProposal("\\R", RegExMessages.getString("displayString_replace_bs_R"), RegExMessages.getString("additionalInfo_replace_bs_R")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
250 addBracketProposal("\\x", 2, RegExMessages.getString("displayString_bs_x"), RegExMessages.getString("additionalInfo_bs_x")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
251 addBracketProposal("\\u", 2, RegExMessages.getString("displayString_bs_u"), RegExMessages.getString("additionalInfo_bs_u")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
252 addBsProposal("\\t", RegExMessages.getString("displayString_bs_t"), RegExMessages.getString("additionalInfo_bs_t")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
253 addBsProposal("\\n", RegExMessages.getString("displayString_replace_bs_n"), RegExMessages.getString("additionalInfo_replace_bs_n")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
254 addBsProposal("\\r", RegExMessages.getString("displayString_replace_bs_r"), RegExMessages.getString("additionalInfo_replace_bs_r")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
255 addBsProposal("\\f", RegExMessages.getString("displayString_bs_f"), RegExMessages.getString("additionalInfo_bs_f")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
256 addBsProposal("\\a", RegExMessages.getString("displayString_bs_a"), RegExMessages.getString("additionalInfo_bs_a")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
257 addBsProposal("\\e", RegExMessages.getString("displayString_bs_e"), RegExMessages.getString("additionalInfo_bs_e")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
258 addBracketProposal("\\c", 2, RegExMessages.getString("displayString_bs_c"), RegExMessages.getString("additionalInfo_bs_c")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
259 addBsProposal("\\C", RegExMessages.getString("displayString_replace_bs_C"), RegExMessages.getString("additionalInfo_replace_bs_C")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
260 }
|
|
261 fPriorityProposals.addAll(fProposals);
|
|
262 return (IContentProposal[]) fPriorityProposals.toArray(new IContentProposal[fPriorityProposals.size()]);
|
|
263 }
|
|
264
|
|
265 /**
|
|
266 * Adds a proposal.
|
|
267 *
|
|
268 * @param proposal the string to be inserted
|
|
269 * @param displayString the proposal's label
|
|
270 * @param additionalInfo the additional information
|
|
271 */
|
|
272 private void addProposal(String proposal, String displayString, String additionalInfo) {
|
|
273 fProposals.add(new Proposal(proposal, displayString, additionalInfo, proposal.length()));
|
|
274 }
|
|
275
|
|
276 /**
|
|
277 * Adds a proposal.
|
|
278 *
|
|
279 * @param proposal the string to be inserted
|
|
280 * @param cursorPosition the cursor position after insertion,
|
|
281 * relative to the start of the proposal
|
|
282 * @param displayString the proposal's label
|
|
283 * @param additionalInfo the additional information
|
|
284 */
|
|
285 private void addProposal(String proposal, int cursorPosition, String displayString, String additionalInfo) {
|
|
286 fProposals.add(new Proposal(proposal, displayString, additionalInfo, cursorPosition));
|
|
287 }
|
|
288
|
|
289 /**
|
|
290 * Adds a proposal to the priority proposals list.
|
|
291 *
|
|
292 * @param proposal the string to be inserted
|
|
293 * @param displayString the proposal's label
|
|
294 * @param additionalInfo the additional information
|
|
295 */
|
|
296 private void addPriorityProposal(String proposal, String displayString, String additionalInfo) {
|
|
297 fPriorityProposals.add(new Proposal(proposal, displayString, additionalInfo, proposal.length()));
|
|
298 }
|
|
299
|
|
300 /**
|
|
301 * Adds a proposal. Ensures that existing pre- and postfixes are not duplicated.
|
|
302 *
|
|
303 * @param proposal the string to be inserted
|
|
304 * @param cursorPosition the cursor position after insertion,
|
|
305 * relative to the start of the proposal
|
|
306 * @param displayString the proposal's label
|
|
307 * @param additionalInfo the additional information
|
|
308 */
|
|
309 private void addBracketProposal(String proposal, int cursorPosition, String displayString, String additionalInfo) {
|
|
310 String prolog= fExpression.substring(0, fDocumentOffset);
|
|
311 if (! fIsEscape && prolog.endsWith("\\") && proposal.startsWith("\\")) { //$NON-NLS-1$//$NON-NLS-2$
|
|
312 fProposals.add(new Proposal(proposal, displayString, additionalInfo, cursorPosition));
|
|
313 return;
|
|
314 }
|
|
315 for (int i= 1; i <= cursorPosition; i++) {
|
|
316 String prefix= proposal.substring(0, i);
|
|
317 if (prolog.endsWith(prefix)) {
|
|
318 String postfix= proposal.substring(cursorPosition);
|
|
319 String epilog= fExpression.substring(fDocumentOffset);
|
|
320 if (epilog.startsWith(postfix)) {
|
|
321 fPriorityProposals.add(new Proposal(proposal.substring(i, cursorPosition), displayString, additionalInfo, cursorPosition-i));
|
|
322 } else {
|
|
323 fPriorityProposals.add(new Proposal(proposal.substring(i), displayString, additionalInfo, cursorPosition-i));
|
|
324 }
|
|
325 return;
|
|
326 }
|
|
327 }
|
|
328 fProposals.add(new Proposal(proposal, displayString, additionalInfo, cursorPosition));
|
|
329 }
|
|
330
|
|
331 /**
|
|
332 * Adds a proposal that starts with a backslash.
|
|
333 * Ensures that the backslash is not repeated if already typed.
|
|
334 *
|
|
335 * @param proposal the string to be inserted
|
|
336 * @param displayString the proposal's label
|
|
337 * @param additionalInfo the additional information
|
|
338 */
|
|
339 private void addBsProposal(String proposal, String displayString, String additionalInfo) {
|
|
340 String prolog= fExpression.substring(0, fDocumentOffset);
|
|
341 int position= proposal.length();
|
|
342 // If the string already contains the backslash, do not include in the proposal
|
|
343 if (prolog.endsWith("\\")) { //$NON-NLS-1$
|
|
344 position--;
|
|
345 proposal= proposal.substring(1);
|
|
346 }
|
|
347
|
|
348 if (fIsEscape) {
|
|
349 fPriorityProposals.add(new Proposal(proposal, displayString, additionalInfo, position));
|
|
350 } else {
|
|
351 addProposal(proposal, position, displayString, additionalInfo);
|
|
352 }
|
|
353 }
|
|
354 }
|
|
355
|
|
356 /**
|
|
357 * <code>true</code> iff the processor is for the find field.
|
|
358 * <code>false</code> iff the processor is for the replace field.
|
|
359 */
|
|
360 private final bool fIsFind;
|
|
361
|
|
362
|
|
363 /**
|
|
364 * Creates a new completion proposal provider.
|
|
365 *
|
|
366 * @param isFind <code>true</code> if the provider is used for the 'find' field
|
|
367 * <code>false</code> if the provider is used for the 'replace' field
|
|
368 */
|
|
369 public FindReplaceDocumentAdapterContentProposalProvider(bool isFind) {
|
|
370 fIsFind= isFind;
|
|
371 }
|
|
372
|
|
373 /*
|
|
374 * @see dwtx.jface.fieldassist.IContentProposalProvider#getProposals(java.lang.String, int)
|
|
375 */
|
|
376 public IContentProposal [] getProposals(String contents, int position) {
|
|
377 if (fIsFind)
|
|
378 return new ProposalComputer(contents, position).computeFindProposals();
|
|
379 return new ProposalComputer(contents, position).computeReplaceProposals();
|
|
380 }
|
|
381 }
|