Mercurial > projects > dwt-addons
annotate dwtx/jface/text/FindReplaceDocumentAdapterContentProposalProvider.d @ 146:75302ef3f92f
final
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 24 Aug 2008 22:34:04 +0200 |
parents | 93a6ec48fd28 |
children | f70d9508c95c |
rev | line source |
---|---|
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 | |
131 | 16 import dwtx.jface.text.IDocumentPartitioningListener; // packageimport |
17 import dwtx.jface.text.DefaultTextHover; // packageimport | |
18 import dwtx.jface.text.AbstractInformationControl; // packageimport | |
19 import dwtx.jface.text.TextUtilities; // packageimport | |
20 import dwtx.jface.text.IInformationControlCreatorExtension; // packageimport | |
21 import dwtx.jface.text.AbstractInformationControlManager; // packageimport | |
22 import dwtx.jface.text.ITextViewerExtension2; // packageimport | |
23 import dwtx.jface.text.IDocumentPartitioner; // packageimport | |
24 import dwtx.jface.text.DefaultIndentLineAutoEditStrategy; // packageimport | |
25 import dwtx.jface.text.ITextSelection; // packageimport | |
26 import dwtx.jface.text.Document; // packageimport | |
27 import dwtx.jface.text.ITextListener; // packageimport | |
28 import dwtx.jface.text.BadPartitioningException; // packageimport | |
29 import dwtx.jface.text.ITextViewerExtension5; // packageimport | |
30 import dwtx.jface.text.IDocumentPartitionerExtension3; // packageimport | |
31 import dwtx.jface.text.IUndoManager; // packageimport | |
32 import dwtx.jface.text.ITextHoverExtension2; // packageimport | |
33 import dwtx.jface.text.IRepairableDocument; // packageimport | |
34 import dwtx.jface.text.IRewriteTarget; // packageimport | |
35 import dwtx.jface.text.DefaultPositionUpdater; // packageimport | |
36 import dwtx.jface.text.RewriteSessionEditProcessor; // packageimport | |
37 import dwtx.jface.text.TextViewerHoverManager; // packageimport | |
38 import dwtx.jface.text.DocumentRewriteSession; // packageimport | |
39 import dwtx.jface.text.TextViewer; // packageimport | |
40 import dwtx.jface.text.ITextViewerExtension8; // packageimport | |
41 import dwtx.jface.text.RegExMessages; // packageimport | |
42 import dwtx.jface.text.IDelayedInputChangeProvider; // packageimport | |
43 import dwtx.jface.text.ITextOperationTargetExtension; // packageimport | |
44 import dwtx.jface.text.IWidgetTokenOwner; // packageimport | |
45 import dwtx.jface.text.IViewportListener; // packageimport | |
46 import dwtx.jface.text.GapTextStore; // packageimport | |
47 import dwtx.jface.text.MarkSelection; // packageimport | |
48 import dwtx.jface.text.IDocumentPartitioningListenerExtension; // packageimport | |
49 import dwtx.jface.text.IDocumentAdapterExtension; // packageimport | |
50 import dwtx.jface.text.IInformationControlExtension; // packageimport | |
51 import dwtx.jface.text.IDocumentPartitioningListenerExtension2; // packageimport | |
52 import dwtx.jface.text.DefaultDocumentAdapter; // packageimport | |
53 import dwtx.jface.text.ITextViewerExtension3; // packageimport | |
54 import dwtx.jface.text.IInformationControlCreator; // packageimport | |
55 import dwtx.jface.text.TypedRegion; // packageimport | |
56 import dwtx.jface.text.ISynchronizable; // packageimport | |
57 import dwtx.jface.text.IMarkRegionTarget; // packageimport | |
58 import dwtx.jface.text.TextViewerUndoManager; // packageimport | |
59 import dwtx.jface.text.IRegion; // packageimport | |
60 import dwtx.jface.text.IInformationControlExtension2; // packageimport | |
61 import dwtx.jface.text.IDocumentExtension4; // packageimport | |
62 import dwtx.jface.text.IDocumentExtension2; // packageimport | |
63 import dwtx.jface.text.IDocumentPartitionerExtension2; // packageimport | |
64 import dwtx.jface.text.Assert; // packageimport | |
65 import dwtx.jface.text.DefaultInformationControl; // packageimport | |
66 import dwtx.jface.text.IWidgetTokenOwnerExtension; // packageimport | |
67 import dwtx.jface.text.DocumentClone; // packageimport | |
68 import dwtx.jface.text.DefaultUndoManager; // packageimport | |
69 import dwtx.jface.text.IFindReplaceTarget; // packageimport | |
70 import dwtx.jface.text.IAutoEditStrategy; // packageimport | |
71 import dwtx.jface.text.ILineTrackerExtension; // packageimport | |
72 import dwtx.jface.text.IUndoManagerExtension; // packageimport | |
73 import dwtx.jface.text.TextSelection; // packageimport | |
74 import dwtx.jface.text.DefaultAutoIndentStrategy; // packageimport | |
75 import dwtx.jface.text.IAutoIndentStrategy; // packageimport | |
76 import dwtx.jface.text.IPainter; // packageimport | |
77 import dwtx.jface.text.IInformationControl; // packageimport | |
78 import dwtx.jface.text.IInformationControlExtension3; // packageimport | |
79 import dwtx.jface.text.ITextViewerExtension6; // packageimport | |
80 import dwtx.jface.text.IInformationControlExtension4; // packageimport | |
81 import dwtx.jface.text.DefaultLineTracker; // packageimport | |
82 import dwtx.jface.text.IDocumentInformationMappingExtension; // packageimport | |
83 import dwtx.jface.text.IRepairableDocumentExtension; // packageimport | |
84 import dwtx.jface.text.ITextHover; // packageimport | |
85 import dwtx.jface.text.FindReplaceDocumentAdapter; // packageimport | |
86 import dwtx.jface.text.ILineTracker; // packageimport | |
87 import dwtx.jface.text.Line; // packageimport | |
88 import dwtx.jface.text.ITextViewerExtension; // packageimport | |
89 import dwtx.jface.text.IDocumentAdapter; // packageimport | |
90 import dwtx.jface.text.TextEvent; // packageimport | |
91 import dwtx.jface.text.BadLocationException; // packageimport | |
92 import dwtx.jface.text.AbstractDocument; // packageimport | |
93 import dwtx.jface.text.AbstractLineTracker; // packageimport | |
94 import dwtx.jface.text.TreeLineTracker; // packageimport | |
95 import dwtx.jface.text.ITextPresentationListener; // packageimport | |
96 import dwtx.jface.text.Region; // packageimport | |
97 import dwtx.jface.text.ITextViewer; // packageimport | |
98 import dwtx.jface.text.IDocumentInformationMapping; // packageimport | |
99 import dwtx.jface.text.MarginPainter; // packageimport | |
100 import dwtx.jface.text.IPaintPositionManager; // packageimport | |
101 import dwtx.jface.text.TextPresentation; // packageimport | |
102 import dwtx.jface.text.IFindReplaceTargetExtension; // packageimport | |
103 import dwtx.jface.text.ISlaveDocumentManagerExtension; // packageimport | |
104 import dwtx.jface.text.ISelectionValidator; // packageimport | |
105 import dwtx.jface.text.IDocumentExtension; // packageimport | |
106 import dwtx.jface.text.PropagatingFontFieldEditor; // packageimport | |
107 import dwtx.jface.text.ConfigurableLineTracker; // packageimport | |
108 import dwtx.jface.text.SlaveDocumentEvent; // packageimport | |
109 import dwtx.jface.text.IDocumentListener; // packageimport | |
110 import dwtx.jface.text.PaintManager; // packageimport | |
111 import dwtx.jface.text.IFindReplaceTargetExtension3; // packageimport | |
112 import dwtx.jface.text.ITextDoubleClickStrategy; // packageimport | |
113 import dwtx.jface.text.IDocumentExtension3; // packageimport | |
114 import dwtx.jface.text.Position; // packageimport | |
115 import dwtx.jface.text.TextMessages; // packageimport | |
116 import dwtx.jface.text.CopyOnWriteTextStore; // packageimport | |
117 import dwtx.jface.text.WhitespaceCharacterPainter; // packageimport | |
118 import dwtx.jface.text.IPositionUpdater; // packageimport | |
119 import dwtx.jface.text.DefaultTextDoubleClickStrategy; // packageimport | |
120 import dwtx.jface.text.ListLineTracker; // packageimport | |
121 import dwtx.jface.text.ITextInputListener; // packageimport | |
122 import dwtx.jface.text.BadPositionCategoryException; // packageimport | |
123 import dwtx.jface.text.IWidgetTokenKeeperExtension; // packageimport | |
124 import dwtx.jface.text.IInputChangedListener; // packageimport | |
125 import dwtx.jface.text.ITextOperationTarget; // packageimport | |
126 import dwtx.jface.text.IDocumentInformationMappingExtension2; // packageimport | |
127 import dwtx.jface.text.ITextViewerExtension7; // packageimport | |
128 import dwtx.jface.text.IInformationControlExtension5; // packageimport | |
129 import dwtx.jface.text.IDocumentRewriteSessionListener; // packageimport | |
130 import dwtx.jface.text.JFaceTextUtil; // packageimport | |
131 import dwtx.jface.text.AbstractReusableInformationControlCreator; // packageimport | |
132 import dwtx.jface.text.TabsToSpacesConverter; // packageimport | |
133 import dwtx.jface.text.CursorLinePainter; // packageimport | |
134 import dwtx.jface.text.ITextHoverExtension; // packageimport | |
135 import dwtx.jface.text.IEventConsumer; // packageimport | |
136 import dwtx.jface.text.IDocument; // packageimport | |
137 import dwtx.jface.text.IWidgetTokenKeeper; // packageimport | |
138 import dwtx.jface.text.DocumentCommand; // packageimport | |
139 import dwtx.jface.text.TypedPosition; // packageimport | |
140 import dwtx.jface.text.IEditingSupportRegistry; // packageimport | |
141 import dwtx.jface.text.IDocumentPartitionerExtension; // packageimport | |
142 import dwtx.jface.text.AbstractHoverInformationControlManager; // packageimport | |
143 import dwtx.jface.text.IEditingSupport; // packageimport | |
144 import dwtx.jface.text.IMarkSelection; // packageimport | |
145 import dwtx.jface.text.ISlaveDocumentManager; // packageimport | |
146 import dwtx.jface.text.DocumentEvent; // packageimport | |
147 import dwtx.jface.text.DocumentPartitioningChangedEvent; // packageimport | |
148 import dwtx.jface.text.ITextStore; // packageimport | |
149 import dwtx.jface.text.JFaceTextMessages; // packageimport | |
150 import dwtx.jface.text.DocumentRewriteSessionEvent; // packageimport | |
151 import dwtx.jface.text.SequentialRewriteTextStore; // packageimport | |
152 import dwtx.jface.text.DocumentRewriteSessionType; // packageimport | |
153 import dwtx.jface.text.TextAttribute; // packageimport | |
154 import dwtx.jface.text.ITextViewerExtension4; // packageimport | |
155 import dwtx.jface.text.ITypedRegion; // packageimport | |
156 | |
157 | |
129 | 158 import dwt.dwthelper.utils; |
159 | |
160 import java.util.ArrayList; | |
161 | |
162 import dwtx.jface.fieldassist.IContentProposal; | |
163 import dwtx.jface.fieldassist.IContentProposalProvider; | |
164 | |
165 | |
166 /** | |
167 * Content assist proposal provider for the {@link FindReplaceDocumentAdapter}. | |
168 * <p> | |
169 * Clients can subclass to provide additional proposals in case they are supported | |
170 * by their own find/replace mechanism. | |
171 * </p> | |
172 * <p> | |
173 * <strong>Note:</strong> Clients must not make any assumptions about the returned | |
174 * proposals. This can change from release to release to adapt to | |
175 * changes made in {@link FindReplaceDocumentAdapter}. | |
176 * </p> | |
177 * | |
178 * @since 3.4 | |
179 */ | |
180 public class FindReplaceDocumentAdapterContentProposalProvider : IContentProposalProvider { | |
181 | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
182 |
129 | 183 /** |
184 * Proposal computer. | |
185 */ | |
186 private static class ProposalComputer { | |
187 | |
188 private static class Proposal : IContentProposal { | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
189 |
129 | 190 private String fContent; |
191 private String fLabel; | |
192 private String fDescription; | |
193 private int fCursorPosition; | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
194 |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
195 this(String content, String label, String description, int cursorPosition) { |
129 | 196 fContent= content; |
197 fLabel= label; | |
198 fDescription= description; | |
199 fCursorPosition= cursorPosition; | |
200 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
201 |
129 | 202 public String getContent() { |
203 return fContent; | |
204 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
205 |
129 | 206 public String getLabel() { |
207 return fLabel; | |
208 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
209 |
129 | 210 public String getDescription() { |
211 return fDescription; | |
212 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
213 |
129 | 214 public int getCursorPosition() { |
215 return fCursorPosition; | |
216 } | |
217 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
218 |
129 | 219 |
220 /** | |
221 * The whole regular expression. | |
222 */ | |
146 | 223 private const String fExpression; |
129 | 224 /** |
225 * The document offset. | |
226 */ | |
146 | 227 private const int fDocumentOffset; |
129 | 228 /** |
229 * The high-priority proposals. | |
230 */ | |
146 | 231 private const ArrayList fPriorityProposals; |
129 | 232 /** |
233 * The low-priority proposals. | |
234 */ | |
146 | 235 private const ArrayList fProposals; |
129 | 236 /** |
237 * <code>true</code> iff <code>fExpression</code> ends with an open escape. | |
238 */ | |
146 | 239 private const bool fIsEscape; |
129 | 240 |
241 /** | |
242 * Creates a new Proposal Computer. | |
243 * @param contents the contents of the subject control | |
244 * @param position the cursor position | |
245 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
246 public this(String contents, int position) { |
129 | 247 fExpression= contents; |
248 fDocumentOffset= position; | |
249 fPriorityProposals= new ArrayList(); | |
250 fProposals= new ArrayList(); | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
251 |
129 | 252 bool isEscape= false; |
253 esc: for (int i= position - 1; i >= 0; i--) { | |
254 if (fExpression.charAt(i) is '\\') | |
255 isEscape= !isEscape; | |
256 else | |
257 break esc; | |
258 } | |
259 fIsEscape= isEscape; | |
260 } | |
261 | |
262 /** | |
263 * Computes applicable proposals for the find field. | |
264 * @return the proposals | |
265 */ | |
266 public IContentProposal[] computeFindProposals() { | |
267 //characters | |
268 addBsProposal("\\\\", RegExMessages.getString("displayString_bs_bs"), RegExMessages.getString("additionalInfo_bs_bs")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
269 addBracketProposal("\\0", 2, RegExMessages.getString("displayString_bs_0"), RegExMessages.getString("additionalInfo_bs_0")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
270 addBracketProposal("\\x", 2, RegExMessages.getString("displayString_bs_x"), RegExMessages.getString("additionalInfo_bs_x")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
271 addBracketProposal("\\u", 2, RegExMessages.getString("displayString_bs_u"), RegExMessages.getString("additionalInfo_bs_u")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
272 addBsProposal("\\t", RegExMessages.getString("displayString_bs_t"), RegExMessages.getString("additionalInfo_bs_t")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
273 addBsProposal("\\R", RegExMessages.getString("displayString_bs_R"), RegExMessages.getString("additionalInfo_bs_R")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
274 addBsProposal("\\n", RegExMessages.getString("displayString_bs_n"), RegExMessages.getString("additionalInfo_bs_n")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
275 addBsProposal("\\r", RegExMessages.getString("displayString_bs_r"), RegExMessages.getString("additionalInfo_bs_r")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
276 addBsProposal("\\f", RegExMessages.getString("displayString_bs_f"), RegExMessages.getString("additionalInfo_bs_f")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
277 addBsProposal("\\a", RegExMessages.getString("displayString_bs_a"), RegExMessages.getString("additionalInfo_bs_a")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
278 addBsProposal("\\e", RegExMessages.getString("displayString_bs_e"), RegExMessages.getString("additionalInfo_bs_e")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
279 addBracketProposal("\\c", 2, RegExMessages.getString("displayString_bs_c"), RegExMessages.getString("additionalInfo_bs_c")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
280 |
129 | 281 if (! fIsEscape) |
282 addBracketProposal(".", 1, RegExMessages.getString("displayString_dot"), RegExMessages.getString("additionalInfo_dot")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
283 addBsProposal("\\d", RegExMessages.getString("displayString_bs_d"), RegExMessages.getString("additionalInfo_bs_d")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
284 addBsProposal("\\D", RegExMessages.getString("displayString_bs_D"), RegExMessages.getString("additionalInfo_bs_D")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
285 addBsProposal("\\s", RegExMessages.getString("displayString_bs_s"), RegExMessages.getString("additionalInfo_bs_s")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
286 addBsProposal("\\S", RegExMessages.getString("displayString_bs_S"), RegExMessages.getString("additionalInfo_bs_S")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
287 addBsProposal("\\w", RegExMessages.getString("displayString_bs_w"), RegExMessages.getString("additionalInfo_bs_w")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
288 addBsProposal("\\W", RegExMessages.getString("displayString_bs_W"), RegExMessages.getString("additionalInfo_bs_W")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
289 |
129 | 290 // back reference |
291 addBsProposal("\\", RegExMessages.getString("displayString_bs_i"), RegExMessages.getString("additionalInfo_bs_i")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
292 |
129 | 293 //quoting |
294 addBsProposal("\\", RegExMessages.getString("displayString_bs"), RegExMessages.getString("additionalInfo_bs")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
295 addBsProposal("\\Q", RegExMessages.getString("displayString_bs_Q"), RegExMessages.getString("additionalInfo_bs_Q")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
296 addBsProposal("\\E", RegExMessages.getString("displayString_bs_E"), RegExMessages.getString("additionalInfo_bs_E")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
297 |
129 | 298 //character sets |
299 if (! fIsEscape) { | |
300 addBracketProposal("[]", 1, RegExMessages.getString("displayString_set"), RegExMessages.getString("additionalInfo_set")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
301 addBracketProposal("[^]", 2, RegExMessages.getString("displayString_setExcl"), RegExMessages.getString("additionalInfo_setExcl")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
302 addBracketProposal("[-]", 1, RegExMessages.getString("displayString_setRange"), RegExMessages.getString("additionalInfo_setRange")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
303 addProposal("&&", RegExMessages.getString("displayString_setInter"), RegExMessages.getString("additionalInfo_setInter")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
304 } | |
305 if (! fIsEscape && fDocumentOffset > 0 && fExpression.charAt(fDocumentOffset - 1) is '\\') { | |
306 addProposal("\\p{}", 3, RegExMessages.getString("displayString_posix"), RegExMessages.getString("additionalInfo_posix")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
307 addProposal("\\P{}", 3, RegExMessages.getString("displayString_posixNot"), RegExMessages.getString("additionalInfo_posixNot")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
308 } else { | |
309 addBracketProposal("\\p{}", 3, RegExMessages.getString("displayString_posix"), RegExMessages.getString("additionalInfo_posix")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
310 addBracketProposal("\\P{}", 3, RegExMessages.getString("displayString_posixNot"), RegExMessages.getString("additionalInfo_posixNot")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
311 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
312 |
129 | 313 //boundary matchers |
314 if (fDocumentOffset is 0) { | |
315 addPriorityProposal("^", RegExMessages.getString("displayString_start"), RegExMessages.getString("additionalInfo_start")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
316 } else if (fDocumentOffset is 1 && fExpression.charAt(0) is '^') { | |
317 addBracketProposal("^", 1, RegExMessages.getString("displayString_start"), RegExMessages.getString("additionalInfo_start")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
318 } | |
319 if (fDocumentOffset is fExpression.length()) { | |
320 addProposal("$", RegExMessages.getString("displayString_end"), RegExMessages.getString("additionalInfo_end")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
321 } | |
322 addBsProposal("\\b", RegExMessages.getString("displayString_bs_b"), RegExMessages.getString("additionalInfo_bs_b")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
323 addBsProposal("\\B", RegExMessages.getString("displayString_bs_B"), RegExMessages.getString("additionalInfo_bs_B")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
324 addBsProposal("\\A", RegExMessages.getString("displayString_bs_A"), RegExMessages.getString("additionalInfo_bs_A")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
325 addBsProposal("\\G", RegExMessages.getString("displayString_bs_G"), RegExMessages.getString("additionalInfo_bs_G")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
326 addBsProposal("\\Z", RegExMessages.getString("displayString_bs_Z"), RegExMessages.getString("additionalInfo_bs_Z")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
327 addBsProposal("\\z", RegExMessages.getString("displayString_bs_z"), RegExMessages.getString("additionalInfo_bs_z")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
328 |
129 | 329 if (! fIsEscape) { |
330 //capturing groups | |
331 addBracketProposal("()", 1, RegExMessages.getString("displayString_group"), RegExMessages.getString("additionalInfo_group")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
332 |
129 | 333 //flags |
334 addBracketProposal("(?)", 2, RegExMessages.getString("displayString_flag"), RegExMessages.getString("additionalInfo_flag")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
335 addBracketProposal("(?:)", 3, RegExMessages.getString("displayString_flagExpr"), RegExMessages.getString("additionalInfo_flagExpr")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
336 |
129 | 337 //non-capturing group |
338 addBracketProposal("(?:)", 3, RegExMessages.getString("displayString_nonCap"), RegExMessages.getString("additionalInfo_nonCap")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
339 addBracketProposal("(?>)", 3, RegExMessages.getString("displayString_atomicCap"), RegExMessages.getString("additionalInfo_atomicCap")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
340 |
129 | 341 //look around |
342 addBracketProposal("(?=)", 3, RegExMessages.getString("displayString_posLookahead"), RegExMessages.getString("additionalInfo_posLookahead")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
343 addBracketProposal("(?!)", 3, RegExMessages.getString("displayString_negLookahead"), RegExMessages.getString("additionalInfo_negLookahead")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
344 addBracketProposal("(?<=)", 4, RegExMessages.getString("displayString_posLookbehind"), RegExMessages.getString("additionalInfo_posLookbehind")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
345 addBracketProposal("(?<!)", 4, RegExMessages.getString("displayString_negLookbehind"), RegExMessages.getString("additionalInfo_negLookbehind")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
346 |
129 | 347 //greedy quantifiers |
348 addBracketProposal("?", 1, RegExMessages.getString("displayString_quest"), RegExMessages.getString("additionalInfo_quest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
349 addBracketProposal("*", 1, RegExMessages.getString("displayString_star"), RegExMessages.getString("additionalInfo_star")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
350 addBracketProposal("+", 1, RegExMessages.getString("displayString_plus"), RegExMessages.getString("additionalInfo_plus")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
351 addBracketProposal("{}", 1, RegExMessages.getString("displayString_exact"), RegExMessages.getString("additionalInfo_exact")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
352 addBracketProposal("{,}", 1, RegExMessages.getString("displayString_least"), RegExMessages.getString("additionalInfo_least")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
353 addBracketProposal("{,}", 1, RegExMessages.getString("displayString_count"), RegExMessages.getString("additionalInfo_count")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
354 |
129 | 355 //lazy quantifiers |
356 addBracketProposal("??", 1, RegExMessages.getString("displayString_questLazy"), RegExMessages.getString("additionalInfo_questLazy")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
357 addBracketProposal("*?", 1, RegExMessages.getString("displayString_starLazy"), RegExMessages.getString("additionalInfo_starLazy")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
358 addBracketProposal("+?", 1, RegExMessages.getString("displayString_plusLazy"), RegExMessages.getString("additionalInfo_plusLazy")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
359 addBracketProposal("{}?", 1, RegExMessages.getString("displayString_exactLazy"), RegExMessages.getString("additionalInfo_exactLazy")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
360 addBracketProposal("{,}?", 1, RegExMessages.getString("displayString_leastLazy"), RegExMessages.getString("additionalInfo_leastLazy")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
361 addBracketProposal("{,}?", 1, RegExMessages.getString("displayString_countLazy"), RegExMessages.getString("additionalInfo_countLazy")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
362 |
129 | 363 //possessive quantifiers |
364 addBracketProposal("?+", 1, RegExMessages.getString("displayString_questPoss"), RegExMessages.getString("additionalInfo_questPoss")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
365 addBracketProposal("*+", 1, RegExMessages.getString("displayString_starPoss"), RegExMessages.getString("additionalInfo_starPoss")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
366 addBracketProposal("++", 1, RegExMessages.getString("displayString_plusPoss"), RegExMessages.getString("additionalInfo_plusPoss")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
367 addBracketProposal("{}+", 1, RegExMessages.getString("displayString_exactPoss"), RegExMessages.getString("additionalInfo_exactPoss")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
368 addBracketProposal("{,}+", 1, RegExMessages.getString("displayString_leastPoss"), RegExMessages.getString("additionalInfo_leastPoss")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
369 addBracketProposal("{,}+", 1, RegExMessages.getString("displayString_countPoss"), RegExMessages.getString("additionalInfo_countPoss")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
370 |
129 | 371 //alternative |
372 addBracketProposal("|", 1, RegExMessages.getString("displayString_alt"), RegExMessages.getString("additionalInfo_alt")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
373 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
374 |
129 | 375 fPriorityProposals.addAll(fProposals); |
376 return (IContentProposal[]) fPriorityProposals.toArray(new IContentProposal[fProposals.size()]); | |
377 } | |
378 | |
379 /** | |
380 * Computes applicable proposals for the replace field. | |
381 * @return the proposals | |
382 */ | |
383 public IContentProposal[] computeReplaceProposals() { | |
384 if (fDocumentOffset > 0 && '$' is fExpression.charAt(fDocumentOffset - 1)) { | |
385 addProposal("", RegExMessages.getString("displayString_dollar"), RegExMessages.getString("additionalInfo_dollar")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
386 } else { | |
387 if (! fIsEscape) | |
388 addProposal("$", RegExMessages.getString("displayString_dollar"), RegExMessages.getString("additionalInfo_dollar")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
389 addBsProposal("\\", RegExMessages.getString("displayString_replace_cap"), RegExMessages.getString("additionalInfo_replace_cap")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
390 addBsProposal("\\", RegExMessages.getString("displayString_replace_bs"), RegExMessages.getString("additionalInfo_replace_bs")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
391 addBsProposal("\\R", RegExMessages.getString("displayString_replace_bs_R"), RegExMessages.getString("additionalInfo_replace_bs_R")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
392 addBracketProposal("\\x", 2, RegExMessages.getString("displayString_bs_x"), RegExMessages.getString("additionalInfo_bs_x")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
393 addBracketProposal("\\u", 2, RegExMessages.getString("displayString_bs_u"), RegExMessages.getString("additionalInfo_bs_u")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
394 addBsProposal("\\t", RegExMessages.getString("displayString_bs_t"), RegExMessages.getString("additionalInfo_bs_t")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
395 addBsProposal("\\n", RegExMessages.getString("displayString_replace_bs_n"), RegExMessages.getString("additionalInfo_replace_bs_n")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
396 addBsProposal("\\r", RegExMessages.getString("displayString_replace_bs_r"), RegExMessages.getString("additionalInfo_replace_bs_r")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
397 addBsProposal("\\f", RegExMessages.getString("displayString_bs_f"), RegExMessages.getString("additionalInfo_bs_f")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
398 addBsProposal("\\a", RegExMessages.getString("displayString_bs_a"), RegExMessages.getString("additionalInfo_bs_a")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
399 addBsProposal("\\e", RegExMessages.getString("displayString_bs_e"), RegExMessages.getString("additionalInfo_bs_e")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
400 addBracketProposal("\\c", 2, RegExMessages.getString("displayString_bs_c"), RegExMessages.getString("additionalInfo_bs_c")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
401 addBsProposal("\\C", RegExMessages.getString("displayString_replace_bs_C"), RegExMessages.getString("additionalInfo_replace_bs_C")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
402 } | |
403 fPriorityProposals.addAll(fProposals); | |
404 return (IContentProposal[]) fPriorityProposals.toArray(new IContentProposal[fPriorityProposals.size()]); | |
405 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
406 |
129 | 407 /** |
408 * Adds a proposal. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
409 * |
129 | 410 * @param proposal the string to be inserted |
411 * @param displayString the proposal's label | |
412 * @param additionalInfo the additional information | |
413 */ | |
414 private void addProposal(String proposal, String displayString, String additionalInfo) { | |
415 fProposals.add(new Proposal(proposal, displayString, additionalInfo, proposal.length())); | |
416 } | |
417 | |
418 /** | |
419 * Adds a proposal. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
420 * |
129 | 421 * @param proposal the string to be inserted |
422 * @param cursorPosition the cursor position after insertion, | |
423 * relative to the start of the proposal | |
424 * @param displayString the proposal's label | |
425 * @param additionalInfo the additional information | |
426 */ | |
427 private void addProposal(String proposal, int cursorPosition, String displayString, String additionalInfo) { | |
428 fProposals.add(new Proposal(proposal, displayString, additionalInfo, cursorPosition)); | |
429 } | |
430 | |
431 /** | |
432 * Adds a proposal to the priority proposals list. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
433 * |
129 | 434 * @param proposal the string to be inserted |
435 * @param displayString the proposal's label | |
436 * @param additionalInfo the additional information | |
437 */ | |
438 private void addPriorityProposal(String proposal, String displayString, String additionalInfo) { | |
439 fPriorityProposals.add(new Proposal(proposal, displayString, additionalInfo, proposal.length())); | |
440 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
441 |
129 | 442 /** |
443 * Adds a proposal. Ensures that existing pre- and postfixes are not duplicated. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
444 * |
129 | 445 * @param proposal the string to be inserted |
446 * @param cursorPosition the cursor position after insertion, | |
447 * relative to the start of the proposal | |
448 * @param displayString the proposal's label | |
449 * @param additionalInfo the additional information | |
450 */ | |
451 private void addBracketProposal(String proposal, int cursorPosition, String displayString, String additionalInfo) { | |
452 String prolog= fExpression.substring(0, fDocumentOffset); | |
453 if (! fIsEscape && prolog.endsWith("\\") && proposal.startsWith("\\")) { //$NON-NLS-1$//$NON-NLS-2$ | |
454 fProposals.add(new Proposal(proposal, displayString, additionalInfo, cursorPosition)); | |
455 return; | |
456 } | |
457 for (int i= 1; i <= cursorPosition; i++) { | |
458 String prefix= proposal.substring(0, i); | |
459 if (prolog.endsWith(prefix)) { | |
460 String postfix= proposal.substring(cursorPosition); | |
461 String epilog= fExpression.substring(fDocumentOffset); | |
462 if (epilog.startsWith(postfix)) { | |
463 fPriorityProposals.add(new Proposal(proposal.substring(i, cursorPosition), displayString, additionalInfo, cursorPosition-i)); | |
464 } else { | |
465 fPriorityProposals.add(new Proposal(proposal.substring(i), displayString, additionalInfo, cursorPosition-i)); | |
466 } | |
467 return; | |
468 } | |
469 } | |
470 fProposals.add(new Proposal(proposal, displayString, additionalInfo, cursorPosition)); | |
471 } | |
472 | |
473 /** | |
474 * Adds a proposal that starts with a backslash. | |
475 * Ensures that the backslash is not repeated if already typed. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
476 * |
129 | 477 * @param proposal the string to be inserted |
478 * @param displayString the proposal's label | |
479 * @param additionalInfo the additional information | |
480 */ | |
481 private void addBsProposal(String proposal, String displayString, String additionalInfo) { | |
482 String prolog= fExpression.substring(0, fDocumentOffset); | |
483 int position= proposal.length(); | |
484 // If the string already contains the backslash, do not include in the proposal | |
485 if (prolog.endsWith("\\")) { //$NON-NLS-1$ | |
486 position--; | |
487 proposal= proposal.substring(1); | |
488 } | |
489 | |
490 if (fIsEscape) { | |
491 fPriorityProposals.add(new Proposal(proposal, displayString, additionalInfo, position)); | |
492 } else { | |
493 addProposal(proposal, position, displayString, additionalInfo); | |
494 } | |
495 } | |
496 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
497 |
129 | 498 /** |
499 * <code>true</code> iff the processor is for the find field. | |
500 * <code>false</code> iff the processor is for the replace field. | |
501 */ | |
146 | 502 private const bool fIsFind; |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
503 |
129 | 504 |
505 /** | |
506 * Creates a new completion proposal provider. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
507 * |
129 | 508 * @param isFind <code>true</code> if the provider is used for the 'find' field |
509 * <code>false</code> if the provider is used for the 'replace' field | |
510 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
511 public this(bool isFind) { |
129 | 512 fIsFind= isFind; |
513 } | |
514 | |
515 /* | |
516 * @see dwtx.jface.fieldassist.IContentProposalProvider#getProposals(java.lang.String, int) | |
517 */ | |
518 public IContentProposal [] getProposals(String contents, int position) { | |
519 if (fIsFind) | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
520 return (new ProposalComputer(contents, position)).computeFindProposals(); |
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
521 return (new ProposalComputer(contents, position)).computeReplaceProposals(); |
129 | 522 } |
523 } |