Mercurial > projects > dwt-addons
annotate dwtx/jface/text/DefaultDocumentAdapter.d @ 172:d994a8b2cdf7
again compile fixes
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 10 Sep 2008 23:14:02 +0200 |
parents | 1a5b8f8129df |
children | c6d7b1ea700b |
rev | line source |
---|---|
129 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2007 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 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.jface.text.DefaultDocumentAdapter; | |
14 | |
131 | 15 import dwtx.jface.text.IDocumentPartitioningListener; // packageimport |
16 import dwtx.jface.text.DefaultTextHover; // packageimport | |
17 import dwtx.jface.text.AbstractInformationControl; // packageimport | |
18 import dwtx.jface.text.TextUtilities; // packageimport | |
19 import dwtx.jface.text.IInformationControlCreatorExtension; // packageimport | |
20 import dwtx.jface.text.AbstractInformationControlManager; // packageimport | |
21 import dwtx.jface.text.ITextViewerExtension2; // packageimport | |
22 import dwtx.jface.text.IDocumentPartitioner; // packageimport | |
23 import dwtx.jface.text.DefaultIndentLineAutoEditStrategy; // packageimport | |
24 import dwtx.jface.text.ITextSelection; // packageimport | |
25 import dwtx.jface.text.Document; // packageimport | |
26 import dwtx.jface.text.FindReplaceDocumentAdapterContentProposalProvider; // 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.ITextViewerExtension3; // packageimport | |
53 import dwtx.jface.text.IInformationControlCreator; // packageimport | |
54 import dwtx.jface.text.TypedRegion; // packageimport | |
55 import dwtx.jface.text.ISynchronizable; // packageimport | |
56 import dwtx.jface.text.IMarkRegionTarget; // packageimport | |
57 import dwtx.jface.text.TextViewerUndoManager; // packageimport | |
58 import dwtx.jface.text.IRegion; // packageimport | |
59 import dwtx.jface.text.IInformationControlExtension2; // packageimport | |
60 import dwtx.jface.text.IDocumentExtension4; // packageimport | |
61 import dwtx.jface.text.IDocumentExtension2; // packageimport | |
62 import dwtx.jface.text.IDocumentPartitionerExtension2; // packageimport | |
63 import dwtx.jface.text.DefaultInformationControl; // packageimport | |
64 import dwtx.jface.text.IWidgetTokenOwnerExtension; // packageimport | |
65 import dwtx.jface.text.DocumentClone; // packageimport | |
66 import dwtx.jface.text.DefaultUndoManager; // packageimport | |
67 import dwtx.jface.text.IFindReplaceTarget; // packageimport | |
68 import dwtx.jface.text.IAutoEditStrategy; // packageimport | |
69 import dwtx.jface.text.ILineTrackerExtension; // packageimport | |
70 import dwtx.jface.text.IUndoManagerExtension; // packageimport | |
71 import dwtx.jface.text.TextSelection; // packageimport | |
72 import dwtx.jface.text.DefaultAutoIndentStrategy; // packageimport | |
73 import dwtx.jface.text.IAutoIndentStrategy; // packageimport | |
74 import dwtx.jface.text.IPainter; // packageimport | |
75 import dwtx.jface.text.IInformationControl; // packageimport | |
76 import dwtx.jface.text.IInformationControlExtension3; // packageimport | |
77 import dwtx.jface.text.ITextViewerExtension6; // packageimport | |
78 import dwtx.jface.text.IInformationControlExtension4; // packageimport | |
79 import dwtx.jface.text.DefaultLineTracker; // packageimport | |
80 import dwtx.jface.text.IDocumentInformationMappingExtension; // packageimport | |
81 import dwtx.jface.text.IRepairableDocumentExtension; // packageimport | |
82 import dwtx.jface.text.ITextHover; // packageimport | |
83 import dwtx.jface.text.FindReplaceDocumentAdapter; // packageimport | |
84 import dwtx.jface.text.ILineTracker; // packageimport | |
85 import dwtx.jface.text.Line; // packageimport | |
86 import dwtx.jface.text.ITextViewerExtension; // packageimport | |
87 import dwtx.jface.text.IDocumentAdapter; // packageimport | |
88 import dwtx.jface.text.TextEvent; // packageimport | |
89 import dwtx.jface.text.BadLocationException; // packageimport | |
90 import dwtx.jface.text.AbstractDocument; // packageimport | |
91 import dwtx.jface.text.AbstractLineTracker; // packageimport | |
92 import dwtx.jface.text.TreeLineTracker; // packageimport | |
93 import dwtx.jface.text.ITextPresentationListener; // packageimport | |
94 import dwtx.jface.text.Region; // packageimport | |
95 import dwtx.jface.text.ITextViewer; // packageimport | |
96 import dwtx.jface.text.IDocumentInformationMapping; // packageimport | |
97 import dwtx.jface.text.MarginPainter; // packageimport | |
98 import dwtx.jface.text.IPaintPositionManager; // packageimport | |
99 import dwtx.jface.text.TextPresentation; // packageimport | |
100 import dwtx.jface.text.IFindReplaceTargetExtension; // packageimport | |
101 import dwtx.jface.text.ISlaveDocumentManagerExtension; // packageimport | |
102 import dwtx.jface.text.ISelectionValidator; // packageimport | |
103 import dwtx.jface.text.IDocumentExtension; // packageimport | |
104 import dwtx.jface.text.PropagatingFontFieldEditor; // packageimport | |
105 import dwtx.jface.text.ConfigurableLineTracker; // packageimport | |
106 import dwtx.jface.text.SlaveDocumentEvent; // packageimport | |
107 import dwtx.jface.text.IDocumentListener; // packageimport | |
108 import dwtx.jface.text.PaintManager; // packageimport | |
109 import dwtx.jface.text.IFindReplaceTargetExtension3; // packageimport | |
110 import dwtx.jface.text.ITextDoubleClickStrategy; // packageimport | |
111 import dwtx.jface.text.IDocumentExtension3; // packageimport | |
112 import dwtx.jface.text.Position; // packageimport | |
113 import dwtx.jface.text.TextMessages; // packageimport | |
114 import dwtx.jface.text.CopyOnWriteTextStore; // packageimport | |
115 import dwtx.jface.text.WhitespaceCharacterPainter; // packageimport | |
116 import dwtx.jface.text.IPositionUpdater; // packageimport | |
117 import dwtx.jface.text.DefaultTextDoubleClickStrategy; // packageimport | |
118 import dwtx.jface.text.ListLineTracker; // packageimport | |
119 import dwtx.jface.text.ITextInputListener; // packageimport | |
120 import dwtx.jface.text.BadPositionCategoryException; // packageimport | |
121 import dwtx.jface.text.IWidgetTokenKeeperExtension; // packageimport | |
122 import dwtx.jface.text.IInputChangedListener; // packageimport | |
123 import dwtx.jface.text.ITextOperationTarget; // packageimport | |
124 import dwtx.jface.text.IDocumentInformationMappingExtension2; // packageimport | |
125 import dwtx.jface.text.ITextViewerExtension7; // packageimport | |
126 import dwtx.jface.text.IInformationControlExtension5; // packageimport | |
127 import dwtx.jface.text.IDocumentRewriteSessionListener; // packageimport | |
128 import dwtx.jface.text.JFaceTextUtil; // packageimport | |
129 import dwtx.jface.text.AbstractReusableInformationControlCreator; // packageimport | |
130 import dwtx.jface.text.TabsToSpacesConverter; // packageimport | |
131 import dwtx.jface.text.CursorLinePainter; // packageimport | |
132 import dwtx.jface.text.ITextHoverExtension; // packageimport | |
133 import dwtx.jface.text.IEventConsumer; // packageimport | |
134 import dwtx.jface.text.IDocument; // packageimport | |
135 import dwtx.jface.text.IWidgetTokenKeeper; // packageimport | |
136 import dwtx.jface.text.DocumentCommand; // packageimport | |
137 import dwtx.jface.text.TypedPosition; // packageimport | |
138 import dwtx.jface.text.IEditingSupportRegistry; // packageimport | |
139 import dwtx.jface.text.IDocumentPartitionerExtension; // packageimport | |
140 import dwtx.jface.text.AbstractHoverInformationControlManager; // packageimport | |
141 import dwtx.jface.text.IEditingSupport; // packageimport | |
142 import dwtx.jface.text.IMarkSelection; // packageimport | |
143 import dwtx.jface.text.ISlaveDocumentManager; // packageimport | |
144 import dwtx.jface.text.DocumentEvent; // packageimport | |
145 import dwtx.jface.text.DocumentPartitioningChangedEvent; // packageimport | |
146 import dwtx.jface.text.ITextStore; // packageimport | |
147 import dwtx.jface.text.JFaceTextMessages; // packageimport | |
148 import dwtx.jface.text.DocumentRewriteSessionEvent; // packageimport | |
149 import dwtx.jface.text.SequentialRewriteTextStore; // packageimport | |
150 import dwtx.jface.text.DocumentRewriteSessionType; // packageimport | |
151 import dwtx.jface.text.TextAttribute; // packageimport | |
152 import dwtx.jface.text.ITextViewerExtension4; // packageimport | |
153 import dwtx.jface.text.ITypedRegion; // packageimport | |
154 | |
155 | |
129 | 156 import dwt.dwthelper.utils; |
157 | |
158 | |
153
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
140
diff
changeset
|
159 import dwtx.dwtxhelper.Collection; |
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
140
diff
changeset
|
160 |
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
140
diff
changeset
|
161 |
129 | 162 |
163 import dwt.DWT; | |
164 import dwt.custom.TextChangeListener; | |
165 import dwt.custom.TextChangedEvent; | |
166 import dwt.custom.TextChangingEvent; | |
167 import dwtx.core.runtime.Assert; | |
168 | |
169 | |
170 /** | |
171 * Default implementation of {@link dwtx.jface.text.IDocumentAdapter}. | |
172 * <p> | |
173 * <strong>Note:</strong> This adapter does not work if the widget auto-wraps the text. | |
174 * </p> | |
175 */ | |
176 class DefaultDocumentAdapter : IDocumentAdapter, IDocumentListener, IDocumentAdapterExtension { | |
177 | |
178 /** The adapted document. */ | |
179 private IDocument fDocument; | |
180 /** The document clone for the non-forwarding case. */ | |
181 private IDocument fDocumentClone; | |
182 /** The original content */ | |
183 private String fOriginalContent; | |
184 /** The original line delimiters */ | |
185 private String[] fOriginalLineDelimiters; | |
186 /** The registered text change listeners */ | |
162 | 187 private List fTextChangeListeners; |
129 | 188 /** |
189 * The remembered document event | |
190 * @since 2.0 | |
191 */ | |
192 private DocumentEvent fEvent; | |
193 /** The line delimiter */ | |
194 private String fLineDelimiter= null; | |
195 /** | |
196 * Indicates whether this adapter is forwarding document changes | |
197 * @since 2.0 | |
198 */ | |
199 private bool fIsForwarding= true; | |
200 /** | |
201 * Length of document at receipt of <code>documentAboutToBeChanged</code> | |
202 * @since 2.1 | |
203 */ | |
204 private int fRememberedLengthOfDocument; | |
205 /** | |
206 * Length of first document line at receipt of <code>documentAboutToBeChanged</code> | |
207 * @since 2.1 | |
208 */ | |
209 private int fRememberedLengthOfFirstLine; | |
210 /** | |
211 * The data of the event at receipt of <code>documentAboutToBeChanged</code> | |
212 * @since 2.1 | |
213 */ | |
162 | 214 private DocumentEvent fOriginalEvent; |
129 | 215 |
216 | |
217 /** | |
218 * Creates a new document adapter which is initially not connected to | |
219 * any document. | |
220 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
221 public this() { |
162 | 222 fTextChangeListeners= new ArrayList(1); |
223 fOriginalEvent= new DocumentEvent(); | |
129 | 224 } |
225 | |
226 /** | |
227 * Sets the given document as the document to be adapted. | |
228 * | |
229 * @param document the document to be adapted or <code>null</code> if there is no document | |
230 */ | |
231 public void setDocument(IDocument document) { | |
232 | |
233 if (fDocument !is null) | |
234 fDocument.removePrenotifiedDocumentListener(this); | |
235 | |
236 fDocument= document; | |
237 fLineDelimiter= null; | |
238 | |
239 if (!fIsForwarding) { | |
240 fDocumentClone= null; | |
241 if (fDocument !is null) { | |
242 fOriginalContent= fDocument.get(); | |
243 fOriginalLineDelimiters= fDocument.getLegalLineDelimiters(); | |
244 } else { | |
245 fOriginalContent= null; | |
246 fOriginalLineDelimiters= null; | |
247 } | |
248 } | |
249 | |
250 if (fDocument !is null) | |
251 fDocument.addPrenotifiedDocumentListener(this); | |
252 } | |
253 | |
254 /* | |
255 * @see StyledTextContent#addTextChangeListener(TextChangeListener) | |
256 */ | |
257 public void addTextChangeListener(TextChangeListener listener) { | |
162 | 258 Assert.isNotNull(cast(Object)listener); |
259 if (!fTextChangeListeners.contains(cast(Object)listener)) | |
260 fTextChangeListeners.add(cast(Object)listener); | |
129 | 261 } |
262 | |
263 /* | |
264 * @see StyledTextContent#removeTextChangeListener(TextChangeListener) | |
265 */ | |
266 public void removeTextChangeListener(TextChangeListener listener) { | |
162 | 267 Assert.isNotNull(cast(Object)listener); |
268 fTextChangeListeners.remove(cast(Object)listener); | |
129 | 269 } |
270 | |
271 /** | |
272 * Tries to repair the line information. | |
273 * | |
274 * @param document the document | |
275 * @see IRepairableDocument#repairLineInformation() | |
276 * @since 3.0 | |
277 */ | |
278 private void repairLineInformation(IDocument document) { | |
138 | 279 if ( cast(IRepairableDocument)document ) { |
134 | 280 IRepairableDocument repairable= cast(IRepairableDocument) document; |
129 | 281 repairable.repairLineInformation(); |
282 } | |
283 } | |
284 | |
285 /** | |
286 * Returns the line for the given line number. | |
287 * | |
288 * @param document the document | |
289 * @param line the line number | |
290 * @return the content of the line of the given number in the given document | |
291 * @throws BadLocationException if the line number is invalid for the adapted document | |
292 * @since 3.0 | |
293 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
294 private String doGetLine(IDocument document, int line) { |
129 | 295 IRegion r= document.getLineInformation(line); |
296 return document.get(r.getOffset(), r.getLength()); | |
297 } | |
298 | |
299 private IDocument getDocumentForRead() { | |
300 if (!fIsForwarding) { | |
301 if (fDocumentClone is null) { | |
302 String content= fOriginalContent is null ? "" : fOriginalContent; //$NON-NLS-1$ | |
303 String[] delims= fOriginalLineDelimiters is null ? DefaultLineTracker.DELIMITERS : fOriginalLineDelimiters; | |
304 fDocumentClone= new DocumentClone(content, delims); | |
305 } | |
306 return fDocumentClone; | |
307 } | |
308 | |
309 return fDocument; | |
310 } | |
311 | |
312 /* | |
313 * @see StyledTextContent#getLine(int) | |
314 */ | |
315 public String getLine(int line) { | |
316 | |
317 IDocument document= getDocumentForRead(); | |
318 try { | |
319 return doGetLine(document, line); | |
320 } catch (BadLocationException x) { | |
321 repairLineInformation(document); | |
322 try { | |
323 return doGetLine(document, line); | |
324 } catch (BadLocationException x2) { | |
325 } | |
326 } | |
327 | |
328 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
329 return null; | |
330 } | |
331 | |
332 /* | |
333 * @see StyledTextContent#getLineAtOffset(int) | |
334 */ | |
335 public int getLineAtOffset(int offset) { | |
336 IDocument document= getDocumentForRead(); | |
337 try { | |
338 return document.getLineOfOffset(offset); | |
339 } catch (BadLocationException x) { | |
340 repairLineInformation(document); | |
341 try { | |
342 return document.getLineOfOffset(offset); | |
343 } catch (BadLocationException x2) { | |
344 } | |
345 } | |
346 | |
347 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
348 return -1; | |
349 } | |
350 | |
351 /* | |
352 * @see StyledTextContent#getLineCount() | |
353 */ | |
354 public int getLineCount() { | |
355 return getDocumentForRead().getNumberOfLines(); | |
356 } | |
357 | |
358 /* | |
359 * @see StyledTextContent#getOffsetAtLine(int) | |
360 */ | |
361 public int getOffsetAtLine(int line) { | |
362 IDocument document= getDocumentForRead(); | |
363 try { | |
364 return document.getLineOffset(line); | |
365 } catch (BadLocationException x) { | |
366 repairLineInformation(document); | |
367 try { | |
368 return document.getLineOffset(line); | |
369 } catch (BadLocationException x2) { | |
370 } | |
371 } | |
372 | |
373 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
374 return -1; | |
375 } | |
376 | |
377 /* | |
378 * @see StyledTextContent#getTextRange(int, int) | |
379 */ | |
380 public String getTextRange(int offset, int length) { | |
381 try { | |
382 return getDocumentForRead().get(offset, length); | |
383 } catch (BadLocationException x) { | |
384 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
385 return null; | |
386 } | |
387 } | |
388 | |
389 /* | |
390 * @see StyledTextContent#replaceTextRange(int, int, String) | |
391 */ | |
392 public void replaceTextRange(int pos, int length, String text) { | |
393 try { | |
394 fDocument.replace(pos, length, text); | |
395 } catch (BadLocationException x) { | |
396 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
397 } | |
398 } | |
399 | |
400 /* | |
401 * @see StyledTextContent#setText(String) | |
402 */ | |
403 public void setText(String text) { | |
404 fDocument.set(text); | |
405 } | |
406 | |
407 /* | |
408 * @see StyledTextContent#getCharCount() | |
409 */ | |
410 public int getCharCount() { | |
411 return getDocumentForRead().getLength(); | |
412 } | |
413 | |
414 /* | |
415 * @see StyledTextContent#getLineDelimiter() | |
416 */ | |
417 public String getLineDelimiter() { | |
418 if (fLineDelimiter is null) | |
419 fLineDelimiter= TextUtilities.getDefaultLineDelimiter(fDocument); | |
420 return fLineDelimiter; | |
421 } | |
422 | |
423 /* | |
424 * @see IDocumentListener#documentChanged(DocumentEvent) | |
425 */ | |
426 public void documentChanged(DocumentEvent event) { | |
427 // check whether the given event is the one which was remembered | |
428 if (fEvent is null || event !is fEvent) | |
429 return; | |
430 | |
431 if (isPatchedEvent(event) || (event.getOffset() is 0 && event.getLength() is fRememberedLengthOfDocument)) { | |
432 fLineDelimiter= null; | |
433 fireTextSet(); | |
434 } else { | |
435 if (event.getOffset() < fRememberedLengthOfFirstLine) | |
436 fLineDelimiter= null; | |
437 fireTextChanged(); | |
438 } | |
439 } | |
440 | |
441 /* | |
442 * @see IDocumentListener#documentAboutToBeChanged(DocumentEvent) | |
443 */ | |
444 public void documentAboutToBeChanged(DocumentEvent event) { | |
445 | |
446 fRememberedLengthOfDocument= fDocument.getLength(); | |
447 try { | |
448 fRememberedLengthOfFirstLine= fDocument.getLineLength(0); | |
449 } catch (BadLocationException e) { | |
450 fRememberedLengthOfFirstLine= -1; | |
451 } | |
452 | |
453 fEvent= event; | |
454 rememberEventData(fEvent); | |
455 fireTextChanging(); | |
456 } | |
457 | |
458 /** | |
459 * Checks whether this event has been changed between <code>documentAboutToBeChanged</code> and | |
460 * <code>documentChanged</code>. | |
461 * | |
462 * @param event the event to be checked | |
463 * @return <code>true</code> if the event has been changed, <code>false</code> otherwise | |
464 */ | |
465 private bool isPatchedEvent(DocumentEvent event) { | |
466 return fOriginalEvent.fOffset !is event.fOffset || fOriginalEvent.fLength !is event.fLength || fOriginalEvent.fText !is event.fText; | |
467 } | |
468 | |
469 /** | |
470 * Makes a copy of the given event and remembers it. | |
471 * | |
472 * @param event the event to be copied | |
473 */ | |
474 private void rememberEventData(DocumentEvent event) { | |
475 fOriginalEvent.fOffset= event.fOffset; | |
476 fOriginalEvent.fLength= event.fLength; | |
477 fOriginalEvent.fText= event.fText; | |
478 } | |
479 | |
480 /** | |
481 * Sends a text changed event to all registered listeners. | |
482 */ | |
483 private void fireTextChanged() { | |
484 | |
485 if (!fIsForwarding) | |
486 return; | |
487 | |
488 TextChangedEvent event= new TextChangedEvent(this); | |
489 | |
490 if (fTextChangeListeners !is null && fTextChangeListeners.size() > 0) { | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
491 Iterator e= (new ArrayList(fTextChangeListeners)).iterator(); |
129 | 492 while (e.hasNext()) |
134 | 493 (cast(TextChangeListener) e.next()).textChanged(event); |
129 | 494 } |
495 } | |
496 | |
497 /** | |
498 * Sends a text set event to all registered listeners. | |
499 */ | |
500 private void fireTextSet() { | |
501 | |
502 if (!fIsForwarding) | |
503 return; | |
504 | |
505 TextChangedEvent event = new TextChangedEvent(this); | |
506 | |
507 if (fTextChangeListeners !is null && fTextChangeListeners.size() > 0) { | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
508 Iterator e= (new ArrayList(fTextChangeListeners)).iterator(); |
129 | 509 while (e.hasNext()) |
134 | 510 (cast(TextChangeListener) e.next()).textSet(event); |
129 | 511 } |
512 } | |
513 | |
514 /** | |
515 * Sends the text changing event to all registered listeners. | |
516 */ | |
517 private void fireTextChanging() { | |
518 | |
519 if (!fIsForwarding) | |
520 return; | |
521 | |
522 try { | |
523 IDocument document= fEvent.getDocument(); | |
524 if (document is null) | |
525 return; | |
526 | |
527 TextChangingEvent event= new TextChangingEvent(this); | |
528 event.start= fEvent.fOffset; | |
529 event.replaceCharCount= fEvent.fLength; | |
530 event.replaceLineCount= document.getNumberOfLines(fEvent.fOffset, fEvent.fLength) - 1; | |
531 event.newText= fEvent.fText; | |
532 event.newCharCount= (fEvent.fText is null ? 0 : fEvent.fText.length()); | |
533 event.newLineCount= (fEvent.fText is null ? 0 : document.computeNumberOfLines(fEvent.fText)); | |
534 | |
535 if (fTextChangeListeners !is null && fTextChangeListeners.size() > 0) { | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
536 Iterator e= (new ArrayList(fTextChangeListeners)).iterator(); |
129 | 537 while (e.hasNext()) |
134 | 538 (cast(TextChangeListener) e.next()).textChanging(event); |
129 | 539 } |
540 | |
541 } catch (BadLocationException e) { | |
542 } | |
543 } | |
544 | |
545 /* | |
546 * @see IDocumentAdapterExtension#resumeForwardingDocumentChanges() | |
547 * @since 2.0 | |
548 */ | |
549 public void resumeForwardingDocumentChanges() { | |
550 fIsForwarding= true; | |
551 fDocumentClone= null; | |
552 fOriginalContent= null; | |
553 fOriginalLineDelimiters= null; | |
554 fireTextSet(); | |
555 } | |
556 | |
557 /* | |
558 * @see IDocumentAdapterExtension#stopForwardingDocumentChanges() | |
559 * @since 2.0 | |
560 */ | |
561 public void stopForwardingDocumentChanges() { | |
562 fDocumentClone= null; | |
563 fOriginalContent= fDocument.get(); | |
564 fOriginalLineDelimiters= fDocument.getLegalLineDelimiters(); | |
565 fIsForwarding= false; | |
566 } | |
162 | 567 |
568 /++ | |
569 + DWT extension | |
570 +/ | |
571 public int utf8AdjustOffset( int offset ){ | |
572 implMissing(__FILE__,__LINE__); | |
573 return offset; | |
574 } | |
129 | 575 } |